android.content.Context#unregisterReceiver ( )源码实例Demo

下面列出了android.content.Context#unregisterReceiver ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: DeviceConnect-Android   文件: USBMonitor.java
/**
	 * unregister BroadcastReceiver
	 * @throws IllegalStateException
	 */
	public synchronized void unregister() throws IllegalStateException {
		// 接続チェック用Runnableを削除
		mDeviceCounts = 0;
		if (!destroyed) {
			mAsyncHandler.removeCallbacks(mDeviceCheckRunnable);
		}
		if (mPermissionIntent != null) {
//			if (DEBUG) Log.i(TAG, "unregister:");
			final Context context = mWeakContext.get();
			try {
				if (context != null) {
					context.unregisterReceiver(mUsbReceiver);
				}
			} catch (final Exception e) {
				Log.w(TAG, e);
			}
			mPermissionIntent = null;
		}
	}
 
源代码2 项目: react-native-share   文件: TargetChosenReceiver.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
public static IntentSender getSharingSenderIntent(ReactContext reactContext) {
    synchronized (LOCK) {
        if (sTargetChosenReceiveAction == null) {
            sTargetChosenReceiveAction = reactContext.getPackageName() + "/" + TargetChosenReceiver.class.getName() + "_ACTION";
        }
        Context context = reactContext.getApplicationContext();
        if (sLastRegisteredReceiver != null) {
            context.unregisterReceiver(sLastRegisteredReceiver);
        }
        sLastRegisteredReceiver = new TargetChosenReceiver();
        context.registerReceiver(sLastRegisteredReceiver, new IntentFilter(sTargetChosenReceiveAction));
    }

    Intent intent = new Intent(sTargetChosenReceiveAction);
    intent.setPackage(reactContext.getPackageName());
    intent.putExtra(EXTRA_RECEIVER_TOKEN, sLastRegisteredReceiver.hashCode());
    final PendingIntent callback = PendingIntent.getBroadcast(reactContext, 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);

    return callback.getIntentSender();
}
 
源代码3 项目: AppVerUpdater   文件: AppVerUpdater.java
public void onStop(Context context) {
    if (networkReceiver != null) {
        try {
            context.unregisterReceiver(networkReceiver);
            networkReceiver = null;
        } catch (IllegalArgumentException e) {
            if (BuildConfig.DEBUG) {
                Log.e(TAG, "Exception: ", e);
            }
        }
    }
}
 
源代码4 项目: zapp   文件: NetworkConnectionHelper.java
public void endListenForNetworkChanges() {
	Context context = contextReference.get();
	if (context == null) {
		return;
	}

	this.listener = null;
	context.unregisterReceiver(networkReceiver);
}
 
源代码5 项目: Conquer   文件: AudioUtils.java
@Override
public void onReceive(Context context, Intent intent) {
    if (intent != null && Constants.ACTION_DESTORY_PLAYER.equals(intent.getAction())) {
        stopAnim();
        releasePlayer();
        L.d("停止音乐");
        context.unregisterReceiver(this);
        receiver = null;
    }
}
 
源代码6 项目: zone-sdk   文件: ScreenLockReceiver.java
public void unRegisterScreenReceiver(Context context) {
    try {
        context.unregisterReceiver(this);
        LogZSDK.INSTANCE.d("注销屏幕解锁、加锁广播接收者...");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
源代码7 项目: android-common   文件: PhoneReceiver.java
public void unRegisterReceiver(Context context) {
    try {
        context.unregisterReceiver(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
/**
 * Safe method to unregister the receiver in case of errors. Still unregisters the receiver for
 * all filters it has been registered for.
 * @param context the context that had registered the receiver
 * @param receiver the receiver that was registered.
 */
public static void safeUnregister(Context context, BluetoothStateReceiver receiver) {
    try {
        context.unregisterReceiver(receiver);
    } catch(IllegalStateException e) {
        e.printStackTrace();
    }
}
 
源代码9 项目: Noyze   文件: VolumePanel.java
@Override
public void onDestroy() {
       Context context = getContext();
       try {
           if (null != mVolumeMediaReceiver)
               context.unregisterReceiver(mVolumeMediaReceiver);
       } catch (IllegalArgumentException iae) {
           LOGE("VolumePanel", "Could not unregister volume/ media receiver.", iae);
       }
       if (null != mAppTypeMonitor)
           mAppTypeMonitor.unregister(context);
       if (null != mPriorityModeObserver)
           mPriorityModeObserver.setListening(false);
       mPriorityModeObserver = null;
	mAudioManager = null;
       mAppTypeMonitor = null;
	mVolumeMediaReceiver = null;
       AudioHelper.freeResources();
       if (null != mAudioHelper)
           mAudioHelper.setHandler(null);
       if (null != mMediaProviderDelegate)
           mMediaProviderDelegate.destroy();
       mMediaProviderDelegate = null;
       mAudioHelper = null;
       try {
           if (registeredOtto) MainThreadBus.get().unregister(this);
       } catch (IllegalArgumentException e) {
           LOGE("VolumePanel", "Failed to unregister our VolumePanel from Otto.");
       }
	super.onDestroy();
}
 
源代码10 项目: DebugDrawer   文件: NetworkController.java
/**
 * Unregister network state broadcast receiver
 */
void unregisterReceiver() {
    try {
        final Context context = contextRef.get();
        if (context != null) {
            context.unregisterReceiver(receiver);
        }
    } catch (IllegalArgumentException e) {
    }
}
 
源代码11 项目: android-u2f-bridge   文件: U2FTransportAndroid.java
@Override
public void onReceive(Context context, Intent intent) {
   String action = intent.getAction();
   UsbDevice usbDevice = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
   String deviceName = usbDevice.getDeviceName();

   if (ACTION_USB_PERMISSION.equals(action)) {
      boolean permission = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED,
            false);
      // sync with connect
      gotRights.clear();
      gotRights.add(permission);
      context.unregisterReceiver(mUsbReceiver);
   }
}
 
源代码12 项目: Easer   文件: WifiSkillViewFragment.java
@Override
public void onDetach() {
    //noinspection ConstantConditions
    @NonNull Context context = getContext();
    wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    context.unregisterReceiver(mReceiver);
    super.onDetach();
}
 
源代码13 项目: 365browser   文件: ShareHelper.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
static void sendChooserIntent(boolean saveLastUsed, Activity activity,
                              Intent sharingIntent,
                              @Nullable TargetChosenCallback callback) {
    synchronized (LOCK) {
        if (sTargetChosenReceiveAction == null) {
            sTargetChosenReceiveAction = activity.getPackageName() + "/"
                    + TargetChosenReceiver.class.getName() + "_ACTION";
        }
        Context context = activity.getApplicationContext();
        if (sLastRegisteredReceiver != null) {
            context.unregisterReceiver(sLastRegisteredReceiver);
            // Must cancel the callback (to satisfy guarantee that exactly one method of
            // TargetChosenCallback is called).
            // TODO(mgiuca): This should be called immediately upon cancelling the chooser,
            // not just when the next share takes place (https://crbug.com/636274).
            sLastRegisteredReceiver.cancel();
        }
        sLastRegisteredReceiver = new TargetChosenReceiver(saveLastUsed, callback);
        context.registerReceiver(
                sLastRegisteredReceiver, new IntentFilter(sTargetChosenReceiveAction));
    }

    Intent intent = new Intent(sTargetChosenReceiveAction);
    intent.setPackage(activity.getPackageName());
    intent.putExtra(EXTRA_RECEIVER_TOKEN, sLastRegisteredReceiver.hashCode());
    final PendingIntent pendingIntent = PendingIntent.getBroadcast(activity, 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
    Intent chooserIntent = Intent.createChooser(sharingIntent,
            activity.getString(R.string.share_link_chooser_title),
            pendingIntent.getIntentSender());
    if (sFakeIntentReceiverForTesting != null) {
        sFakeIntentReceiverForTesting.setIntentToSendBack(intent);
    }
    fireIntent(activity, chooserIntent);
}
 
源代码14 项目: cronet   文件: HttpNegotiateAuthenticator.java
@Override
public void run(AccountManagerFuture<Bundle> future) {
    Bundle result;
    try {
        result = future.getResult();
    } catch (OperationCanceledException | AuthenticatorException | IOException e) {
        Log.w(TAG, "ERR_UNEXPECTED: Error while attempting to obtain a token.", e);
        nativeSetResult(mRequestData.nativeResultObject, NetError.ERR_UNEXPECTED, null);
        return;
    }

    if (result.containsKey(AccountManager.KEY_INTENT)) {
        final Context appContext = ContextUtils.getApplicationContext();

        // We wait for a broadcast that should be sent once the user is done interacting
        // with the notification
        // TODO(dgn) We currently hang around if the notification is swiped away, until
        // a LOGIN_ACCOUNTS_CHANGED_ACTION filter is received. It might be for something
        // unrelated then we would wait again here. Maybe we should limit the number of
        // retries in some way?
        BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                appContext.unregisterReceiver(this);
                mRequestData.accountManager.getAuthToken(mRequestData.account,
                        mRequestData.authTokenType, mRequestData.options,
                        true /* notifyAuthFailure */, new GetTokenCallback(mRequestData),
                        null);
            }

        };
        appContext.registerReceiver(broadcastReceiver,
                new IntentFilter(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION));
    } else {
        processResult(result, mRequestData);
    }
}
 
源代码15 项目: AndroidChromium   文件: ShareHelper.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
static void sendChooserIntent(boolean saveLastUsed, Activity activity,
                              Intent sharingIntent,
                              @Nullable TargetChosenCallback callback) {
    synchronized (LOCK) {
        if (sTargetChosenReceiveAction == null) {
            sTargetChosenReceiveAction = activity.getPackageName() + "/"
                    + TargetChosenReceiver.class.getName() + "_ACTION";
        }
        Context context = activity.getApplicationContext();
        if (sLastRegisteredReceiver != null) {
            context.unregisterReceiver(sLastRegisteredReceiver);
            // Must cancel the callback (to satisfy guarantee that exactly one method of
            // TargetChosenCallback is called).
            // TODO(mgiuca): This should be called immediately upon cancelling the chooser,
            // not just when the next share takes place (https://crbug.com/636274).
            sLastRegisteredReceiver.cancel();
        }
        sLastRegisteredReceiver = new TargetChosenReceiver(saveLastUsed, callback);
        context.registerReceiver(
                sLastRegisteredReceiver, new IntentFilter(sTargetChosenReceiveAction));
    }

    Intent intent = new Intent(sTargetChosenReceiveAction);
    intent.setPackage(activity.getPackageName());
    intent.putExtra(EXTRA_RECEIVER_TOKEN, sLastRegisteredReceiver.hashCode());
    final PendingIntent pendingIntent = PendingIntent.getBroadcast(activity, 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
    Intent chooserIntent = Intent.createChooser(sharingIntent,
            activity.getString(R.string.share_link_chooser_title),
            pendingIntent.getIntentSender());
    if (sFakeIntentReceiverForTesting != null) {
        sFakeIntentReceiverForTesting.setIntentToSendBack(intent);
    }
    fireIntent(activity, chooserIntent);
}
 
源代码16 项目: BaseProject   文件: BaseReceiver.java
/**
 * 解注册本广播接收者
 * @param context Context
 * @param unRegisterInLocal 是否解注册本广播为本地广播
 */
public void unRegister(Context context, boolean unRegisterInLocal) {
    if (unRegisterInLocal) {
        LocalBroadcastManager.getInstance(context).unregisterReceiver(this);
    }
    else{
        context.unregisterReceiver(this);
    }
}
 
源代码17 项目: letv   文件: AccountChangeReceiver.java
public void unregisterLogon(Context context) {
    context.unregisterReceiver(this);
}
 
源代码18 项目: MainScreenShow   文件: MSSService.java
public void unRegisterScreenActionReceiver(Context mContext) {
    if (isRegisterReceiver) {
        isRegisterReceiver = false;
        mContext.unregisterReceiver(ScreenReceiver.this);
    }
}
 
源代码19 项目: Musicoco   文件: BroadcastManager.java
/**
 * 注销广播接收者
 */
public void unregisterReceiver(Context context, BroadcastReceiver receiver) {
    context.unregisterReceiver(receiver);
}
 
源代码20 项目: Augendiagnose   文件: HeadsetPlugReceiver.java
/**
 * Unregister this receiver.
 *
 * @param context The context
 */
public void unregister(final Context context) {
	context.unregisterReceiver(this);
}
 
 方法所在类
 同类方法