当前位置: 首页>>代码示例>>Java>>正文


Java NetworkOnMainThreadException类代码示例

本文整理汇总了Java中android.os.NetworkOnMainThreadException的典型用法代码示例。如果您正苦于以下问题:Java NetworkOnMainThreadException类的具体用法?Java NetworkOnMainThreadException怎么用?Java NetworkOnMainThreadException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NetworkOnMainThreadException类属于android.os包,在下文中一共展示了NetworkOnMainThreadException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: exportFile

import android.os.NetworkOnMainThreadException; //导入依赖的package包/类
private void exportFile(Uri data) {
    MetaFile2 file = null;
    try {
        file = MetaFile2Factory.getMetaFileForUrl(data);
    } catch (Exception e) {
        if(e instanceof NetworkOnMainThreadException)
            throw new NetworkOnMainThreadException();
        else
            e.printStackTrace();
    }
    if (file != null && file.isDirectory()) {
        showNotification(data.toString());
        handleCursor(getInDirectoryCursor(data));
        hideNotification();
    }
    removeDirTask(data);
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:18,代码来源:NfoExportService.java

示例2: process

import android.os.NetworkOnMainThreadException; //导入依赖的package包/类
@NonNull
private Observable<Boolean> process(RequestType requestType) {
    return Observable.create(new Observable.OnSubscribe<Boolean>() {
        @Override
        public void call(Subscriber<? super Boolean> subscriber) {
            if (Looper.myLooper() == Looper.getMainLooper()) {
                throw new NetworkOnMainThreadException();
            }

            if (!mRequestsController.tryRequest(requestType)) {
                subscriber.onError(new Throwable());
            }

            SystemClock.sleep(requestType.getDelay());
            mRequestsController.onRequestFinished(requestType);

            subscriber.onCompleted();
        }
    });
}
 
开发者ID:ArturVasilov,项目名称:RxSamplesPractice,代码行数:21,代码来源:RequestProcessor.java

示例3: loadBitmap

import android.os.NetworkOnMainThreadException; //导入依赖的package包/类
/**
 * Fetches a Bitmap from a URL. Don't call this from the Main Thread.
 *
 * @param url The image url.
 * @throws IOException
 */
@SuppressWarnings("UnusedDeclaration")
public static Bitmap loadBitmap(String url) throws IOException {
    if (isMainThread()) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            Log.w(TAG, new RuntimeException("Network On Main Thread"));
        } else {
            Log.w(TAG, new NetworkOnMainThreadException());
        }
    }
    URL url1 = new URL(url.replace(" ", "%20"));
    InputStream inputStream = url1.openConnection().getInputStream();
    BitmapFactory.Options opts = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        opts = new BitmapFactory.Options();
        opts.inMutable = true;
    }
    Bitmap bitmap = BitmapFactory.decodeStream(inputStream, null, opts);
    inputStream.close();
    return bitmap;
}
 
开发者ID:carlosefonseca,项目名称:CEFCommon,代码行数:27,代码来源:NetworkingUtils.java

示例4: getErrorForNetworkOnMainThreadOrConnection

import android.os.NetworkOnMainThreadException; //导入依赖的package包/类
public static ANError getErrorForNetworkOnMainThreadOrConnection(Exception e) {
    ANError error = new ANError(e);
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
            && e instanceof NetworkOnMainThreadException) {
        error.setErrorDetail(ANConstants.NETWORK_ON_MAIN_THREAD_ERROR);
    } else {
        error.setErrorDetail(ANConstants.CONNECTION_ERROR);
    }
    error.setErrorCode(0);
    return error;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:Utils.java

示例5: connectBlocking

import android.os.NetworkOnMainThreadException; //导入依赖的package包/类
@WorkerThread
public Velocity.Response connectBlocking()
{
    if(Looper.myLooper() == Looper.getMainLooper())
        throw new NetworkOnMainThreadException();

    return new SynchronousWrapper().connect(this);
}
 
开发者ID:ravindu1024,项目名称:velocity,代码行数:9,代码来源:RequestBuilder.java

示例6: asParcelableException

import android.os.NetworkOnMainThreadException; //导入依赖的package包/类
private RuntimeException asParcelableException(final Throwable e) {
	if (e instanceof SecurityException
			|| e instanceof BadParcelableException
			|| e instanceof IllegalArgumentException
			|| e instanceof NullPointerException
			|| e instanceof IllegalStateException
			|| e instanceof NetworkOnMainThreadException
			|| e instanceof UnsupportedOperationException)
		return (RuntimeException) e;
	return new IllegalStateException(e);
}
 
开发者ID:markzhai,项目名称:nevo-direct-reply,代码行数:12,代码来源:NevoDecoratorService.java

示例7: clear

import android.os.NetworkOnMainThreadException; //导入依赖的package包/类
public void clear() {
    try {
        subscriptions.clear();
    } catch (NetworkOnMainThreadException exception) {
        // Ignore
    }
}
 
开发者ID:mattlogan,项目名称:RhymeCity,代码行数:8,代码来源:SafeCompositeSubscription.java

示例8: onDestroyView

import android.os.NetworkOnMainThreadException; //导入依赖的package包/类
@Override
    public void onDestroyView() {
        super.onDestroyView();
        Timber.d("onDestroyView()");

        String className = this.getClass().toString();
        Timber.d("onDestroyView() : className - "+ className);
        if(this instanceof VideosFragment){
            String query = ((VideosFragment)this).getQuery();
            Timber.d("onDestroyView() : query - "+ query);
        }

        Timber.d("onDestroyView() : calls.size() - " + calls.size());

        for(final Call call : calls){
            Timber.d("onDestroyView() : call.cancel() - "+call.toString());

            try {
                call.cancel();
            } catch (NetworkOnMainThreadException e){
                Timber.d("onDestroyView() : NetworkOnMainThreadException thrown");
                e.printStackTrace();
            }

//            new CancelTask().execute(call);

//            OkHttpClient client = new OkHttpClient();
//            client.getDispatcher().getExecutorService().execute(new Runnable() {
//                @Override
//                public void run() {
//                    call.cancel();
//                }
//            });
        }

        calls.clear();
    }
 
开发者ID:lawloretienne,项目名称:Loop,代码行数:38,代码来源:BaseFragment.java

示例9: onPublishTxAuth

import android.os.NetworkOnMainThreadException; //导入依赖的package包/类
public void onPublishTxAuth(final Context app, boolean authAsked) {
        if (ActivityUTILS.isMainThread()) throw new NetworkOnMainThreadException();

        final BRWalletManager walletManager = BRWalletManager.getInstance();
        byte[] rawSeed;
        try {
            rawSeed = BRKeyStore.getPhrase(app, BRConstants.PAY_REQUEST_CODE);
        } catch (UserNotAuthenticatedException e) {
            return;
        }
        if (rawSeed.length < 10) return;
        final byte[] seed = TypesConverter.getNullTerminatedPhrase(rawSeed);
        try {
            if (seed.length != 0) {
                if (paymentItem != null && paymentItem.serializedTx != null) {
                    byte[] txHash = walletManager.publishSerializedTransaction(paymentItem.serializedTx, seed);
                    Log.e(TAG, "onPublishTxAuth: txhash:" + Arrays.toString(txHash));
                    if (Utils.isNullOrEmpty(txHash)) {
                        Log.e(TAG, "onPublishTxAuth: publishSerializedTransaction returned FALSE");
                        //todo fix this
//                        BRWalletManager.getInstance().offerToChangeTheAmount(app, new PaymentItem(paymentRequest.addresses, paymentItem.serializedTx, paymentRequest.amount, null, paymentRequest.isPaymentRequest));
                    } else {
                        TxMetaData txMetaData = new TxMetaData();
                        txMetaData.comment = paymentItem.comment;
                        KVStoreManager.getInstance().putTxMetaData(app, txMetaData, txHash);
                    }
                    paymentItem = null;
                } else {
                    throw new NullPointerException("payment item is null");
                }
            } else {
                Log.e(TAG, "onPublishTxAuth: seed length is 0!");
                return;
            }
        } finally {
            Arrays.fill(seed, (byte) 0);
        }

    }
 
开发者ID:breadwallet,项目名称:breadwallet-android,代码行数:40,代码来源:PostAuth.java

示例10: openDatabase

import android.os.NetworkOnMainThreadException; //导入依赖的package包/类
@Override
    public  SQLiteDatabase openDatabase() {
        if(ActivityUTILS.isMainThread()) throw new NetworkOnMainThreadException();
//        if (mOpenCounter.incrementAndGet() == 1) {
        // Opening new database
        if (database == null || !database.isOpen())
            database = dbHelper.getWritableDatabase();
        dbHelper.setWriteAheadLoggingEnabled(BRConstants.WAL);
//        }
//        Log.d("Database open counter: ",  String.valueOf(mOpenCounter.get()));
        return database;
    }
 
开发者ID:breadwallet,项目名称:breadwallet-android,代码行数:13,代码来源:TransactionDataSource.java

示例11: openDatabase

import android.os.NetworkOnMainThreadException; //导入依赖的package包/类
@Override
    public  SQLiteDatabase openDatabase() {
//        if (mOpenCounter.incrementAndGet() == 1) {
        // Opening new database
        if(ActivityUTILS.isMainThread()) throw new NetworkOnMainThreadException();
        if (database == null || !database.isOpen())
            database = dbHelper.getWritableDatabase();
        dbHelper.setWriteAheadLoggingEnabled(BRConstants.WAL);
//        }
//        Log.d("Database open counter: ",  String.valueOf(mOpenCounter.get()));
        return database;
    }
 
开发者ID:breadwallet,项目名称:breadwallet-android,代码行数:13,代码来源:PeerDataSource.java

示例12: buyBitcoinMe

import android.os.NetworkOnMainThreadException; //导入依赖的package包/类
public Response buyBitcoinMe() {
    if (ActivityUTILS.isMainThread()) {
        throw new NetworkOnMainThreadException();
    }
    if (ctx == null) ctx = BreadApp.getBreadContext();
    if (ctx == null) return null;
    String strUtl = BASE_URL + ME;
    Request request = new Request.Builder()
            .url(strUtl)
            .get()
            .build();
    String response = null;
    Response res = null;
    try {
        res = sendRequest(request, true, 0);
        response = res.body().string();
        if (response.isEmpty()) {
            res.close();
            res = sendRequest(request, true, 0);
            response = res.body().string();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (response == null) throw new NullPointerException();

    return res;
}
 
开发者ID:breadwallet,项目名称:breadwallet-android,代码行数:30,代码来源:APIClient.java

示例13: syncKvStore

import android.os.NetworkOnMainThreadException; //导入依赖的package包/类
public void syncKvStore() {
    if (ActivityUTILS.isMainThread()) {
        throw new NetworkOnMainThreadException();
    }
    final APIClient client = this;
    //sync the kv stores
    RemoteKVStore remoteKVStore = RemoteKVStore.getInstance(client);
    ReplicatedKVStore kvStore = ReplicatedKVStore.getInstance(ctx, remoteKVStore);
    kvStore.syncAllKeys();
}
 
开发者ID:breadwallet,项目名称:breadwallet-android,代码行数:11,代码来源:APIClient.java

示例14: run

import android.os.NetworkOnMainThreadException; //导入依赖的package包/类
private void run()
{
    thread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                if(!isPortOpen(INFO.getUri().getHost(), INFO.getUri().getPort(), 10000)){
                    throw new Exception("Cannot connect to ROS. Please make sure ROS is running and that the Master URI is correct.");
                }

                final Intent intent = new Intent(activity, ControlApp.class);

                // !!!---- EVIL USE OF STATIC VARIABLE ----!! //
                // Should not be doing this but there is no other way that I can see -Michael
                ControlApp.ROBOT_INFO = INFO;

                dismiss();

                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        activity.startActivity(intent);
                    }
                });
            }
            catch (final NetworkOnMainThreadException e){
                dismiss();

                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(activity, "Invalid Master URI", Toast.LENGTH_LONG).show();
                    }
                });
            }
            catch (InterruptedException e)
            {
                // Ignore
                Log.d(TAG, "interrupted");
            }
            catch (final Exception e) {

                if (ConnectionProgressDialogFragment.this.getFragmentManager() != null)
                    dismiss();

                activity.runOnUiThread(new Runnable() {
                        @Override
    public void run() {
                    Toast.makeText(activity, e.getMessage(), Toast.LENGTH_LONG).show();
                        }
                });
            }
        }
    });

    thread.start();
}
 
开发者ID:mtbii,项目名称:RobotCA,代码行数:58,代码来源:RobotInfoAdapter.java

示例15: updateBundle

import android.os.NetworkOnMainThreadException; //导入依赖的package包/类
public void updateBundle() {
        if (ActivityUTILS.isMainThread()) {
            throw new NetworkOnMainThreadException();
        }
        File bundleFile = new File(getBundleResource(ctx, BREAD_FILE));
        Log.d(TAG, "updateBundle: " + bundleFile);
        if (bundleFile.exists()) {
            Log.d(TAG, bundleFile + ": updateBundle: exists");

            byte[] bFile = new byte[0];
            try {
                FileInputStream in = new FileInputStream(bundleFile);
                bFile = IOUtils.toByteArray(in);
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

            String latestVersion = getLatestVersion();
            String currentTarVersion = null;
            byte[] hash = CryptoHelper.sha256(bFile);

            currentTarVersion = Utils.bytesToHex(hash);
            Log.d(TAG, bundleFile + ": updateBundle: version of the current tar: " + currentTarVersion);
//            FileHelper.printDirectoryTree(new File(getExtractedPath(ctx, null)));
            if (latestVersion != null) {
                if (latestVersion.equals(currentTarVersion)) {
                    Log.d(TAG, bundleFile + ": updateBundle: have the latest version");
                    tryExtractTar();
                } else {
                    Log.d(TAG, bundleFile + ": updateBundle: don't have the most recent version, download diff");
                    downloadDiff(currentTarVersion);
                    tryExtractTar();
                }
            } else {
                Log.d(TAG, bundleFile + ": updateBundle: latestVersion is null");
            }
//            FileHelper.printDirectoryTree(new File(getExtractedPath(ctx, null)));

        } else {
            Log.d(TAG, bundleFile + ": updateBundle: bundle doesn't exist, downloading new copy");
            long startTime = System.currentTimeMillis();
            Request request = new Request.Builder()
                    .url(String.format("%s/assets/bundles/%s/download", BASE_URL, BREAD_POINT))
                    .get().build();
            Response response = null;
            byte[] body;
            try {
                response = sendRequest(request, false, 0);
                Log.d(TAG, bundleFile + ": updateBundle: Downloaded, took: " + (System.currentTimeMillis() - startTime));
                body = writeBundleToFile(response);
            } finally {
                if (response != null) response.close();
            }
            if (Utils.isNullOrEmpty(body)) {
                Log.e(TAG, "updateBundle: body is null, returning.");
                return;
            }

            boolean b = tryExtractTar();
            if (!b) {
                Log.e(TAG, "updateBundle: Failed to extract tar");
            }
        }

        logFiles("updateBundle after", ctx);
    }
 
开发者ID:breadwallet,项目名称:breadwallet-android,代码行数:68,代码来源:APIClient.java


注:本文中的android.os.NetworkOnMainThreadException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。