Java Code Examples for android.app.Activity#registerReceiver()
The following examples show how to use
android.app.Activity#registerReceiver() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: NovarumBluetooth File: NovarumbluetoothModule.java License: MIT License | 6 votes |
@Kroll.method public boolean searchDevices() { Log.d(TAG, "searchDevices called"); //Halilk: if not enabled, enable bluetooth enableBluetooth(); //Get Current activity// TiApplication appContext = TiApplication.getInstance(); Activity activity = appContext.getCurrentActivity(); IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND); activity.registerReceiver(myReceiver, intentFilter); bluetoothAdapter.cancelDiscovery(); //cancel if it's already searching bluetoothAdapter.startDiscovery(); return true; }
Example 2
Source Project: PocketMaps File: DownloadMapActivity.java License: MIT License | 6 votes |
protected StatusUpdate createStatusUpdater() { StatusUpdate s = new StatusUpdate() { @Override public void logUserThread(String txt) { DownloadMapActivity.this.logUserThread(txt); } @Override public void updateMapStatus(MyMap map) { DownloadMapActivity.this.myDownloadAdapter.refreshMapView(map); } @Override public void onRegisterBroadcastReceiver(Activity activity, MyMap myMap, long enqueueId) { BroadcastReceiver br = createBroadcastReceiver(activity, this, myMap, enqueueId); activity.registerReceiver(br, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); DownloadMapActivity.this.receiverList.add(br); } }; return s; }
Example 3
Source Project: MiBandDecompiled File: AuthorizeHelper.java License: Apache License 2.0 | 6 votes |
private static void a(Activity activity, int i, long l, String s, String s1, String s2, String s3, String s4) { if (l < 0L) { throw new IllegalArgumentException("client id is error!!!"); } if (TextUtils.isEmpty(s)) { throw new IllegalArgumentException("redirect url is empty!!!"); } if (TextUtils.isEmpty(s1)) { throw new IllegalArgumentException("responseType is empty!!!"); } else { IntentFilter intentfilter = new IntentFilter(APP2SDKReceiver.AUTH_ACTION_NAME); APP2SDKReceiver app2sdkreceiver = new APP2SDKReceiver(); activity.registerReceiver(app2sdkreceiver, intentfilter); a(activity, s4); (new Handler()).postDelayed(new b(activity, app2sdkreceiver, l, s, s1, s2, s3, i), 100L); return; } }
Example 4
Source Project: Android-Plugin-Framework File: PluginActivityMonitor.java License: MIT License | 6 votes |
public void onActivityCreate(final Activity activity) { if (!activity.isChild()) { if (activity.getClass().getClassLoader() instanceof RealPluginClassLoader) { String pluginPackageName = ((PluginContextTheme)activity.getApplication().getBaseContext()).getPluginDescriptor().getPackageName(); BroadcastReceiver br = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { LogUtil.w("onReceive", intent.getAction(), "activity.finish()"); activity.finish(); } }; receivers.put(activity, br); LogUtil.v("registerReceiver", pluginPackageName + ACTION_STOP_PLUGIN); activity.registerReceiver(br, new IntentFilter(pluginPackageName + ACTION_STOP_PLUGIN)); } } }
Example 5
Source Project: react-native-appearance File: RNCAppearanceModule.java License: MIT License | 5 votes |
@Override public void onHostResume() { final Activity activity = getCurrentActivity(); if (activity == null) { FLog.e(ReactConstants.TAG, "no activity to register receiver"); return; } activity.registerReceiver(mBroadcastReceiver, new IntentFilter("onConfigurationChanged")); // Send updated preferences to JS when the app is resumed, because we don't receive updates // when backgrounded updateAndSendAppearancePreferences(); }
Example 6
Source Project: alpha-wallet-android File: TokensReceiver.java License: MIT License | 5 votes |
public TokensReceiver(Activity ctx, TokenInterface tokenInterface) { ctx.registerReceiver(this, new IntentFilter(C.RESET_WALLET)); ctx.registerReceiver(this, new IntentFilter(C.ADDED_TOKEN)); ctx.registerReceiver(this, new IntentFilter(C.CHANGED_LOCALE)); ctx.registerReceiver(this, new IntentFilter(C.REFRESH_TOKENS)); this.tokenInterface = tokenInterface; }
Example 7
Source Project: react-native-orientation-locker File: OrientationModule.java License: MIT License | 5 votes |
@Override public void onHostResume() { FLog.i(ReactConstants.TAG, "orientation detect enabled."); mOrientationListener.enable(); final Activity activity = getCurrentActivity(); if (activity == null) return; activity.registerReceiver(mReceiver, new IntentFilter("onConfigurationChanged")); }
Example 8
Source Project: OkUSB File: USB.java License: Apache License 2.0 | 5 votes |
private void register() { IntentFilter usbFilter = new IntentFilter(); usbFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED); usbFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); usbFilter.addAction(ACTION_USB_PERMISSION); Activity activity = ctx.get(); if (activity != null) { activity.registerReceiver(mUsbPermissionActionReceiver, usbFilter); } }
Example 9
Source Project: TvAppRepo File: PackageInstaller.java License: Apache License 2.0 | 5 votes |
public static PackageInstaller initialize(Activity activity) { mPackageInstaller = new PackageInstaller(); activity.registerReceiver(mPackageInstaller.mDownloadCompleteReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); DOWNLOAD_MANAGER = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE); mPackageInstaller.mActivity = activity; mPackageInstaller.chmod(); return mPackageInstaller; }
Example 10
Source Project: AppTroy File: ActivityHook.java License: Apache License 2.0 | 5 votes |
@Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { Log.d("cc", "after, register receiver"); if (!ModuleContext.HAS_REGISTER_LISENER) { Activity app = (Activity) param.thisObject; IntentFilter filter = new IntentFilter(CommandBroadcastReceiver.INTENT_ACTION); app.registerReceiver(new CommandBroadcastReceiver(), filter); ModuleContext.HAS_REGISTER_LISENER = true; ModuleContext.getInstance().setFirstApplication(app.getApplication()); Log.d("cc", "register over"); } }
Example 11
Source Project: FamilyChat File: HeadSetReceiver.java License: Apache License 2.0 | 5 votes |
/** * 注册广播的公共方法 */ public static HeadSetReceiver registInActivity(Activity activity, onHeadSetStateChangeListener l) { HeadSetReceiver receiver = new HeadSetReceiver(); receiver.setOnHeadSetStateChangeListener(l); IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_HEADSET_PLUG); activity.registerReceiver(receiver, filter); return receiver; }
Example 12
Source Project: DeviceConnect-Android File: ConfirmationFragment.java License: MIT License | 5 votes |
@Override public void onResume() { super.onResume(); Activity activity = getActivity(); if (activity != null) { activity.registerReceiver(mReceiver, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION)); } }
Example 13
Source Project: esc-pos-android File: SearchPrinterDialog.java License: Apache License 2.0 | 5 votes |
public SearchPrinterDialog(Activity activity, BTService service) { this.activity = activity; this.service = service; deviceItems = new HashMap<>(); @SuppressLint("InflateParams") View view = LayoutInflater.from(activity).inflate(R.layout.serach_dialog_layout, null, false); insets = dpToPx(16); activity.registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_FOUND)); activity.registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_CLASS_CHANGED)); activity.registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_NAME_CHANGED)); activity.registerReceiver(receiver, new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)); Set<BluetoothDevice> pairedDevices = service.getBondedDevices(); availableDevicesContainer = (LinearLayout) view.findViewById(R.id.available_devices_container); progress = view.findViewById(R.id.search_devices_progress); if (pairedDevices.size() > 0) { fillPairedDevices(pairedDevices, (LinearLayout) view.findViewById(R.id.paired_devices_container)); } else { view.findViewById(R.id.paired_devices).setVisibility(View.GONE); } service.startDiscovery(); dialog = new Dialog(activity); dialog.setCancelable(true); dialog.setContentView(view); dialog.setTitle(R.string.pos_title_choose_printer); dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogInterface) { SearchPrinterDialog.this.onCancel(); } }); dialog.show(); }
Example 14
Source Project: slide-android File: SystemSettings.java License: GNU General Public License v2.0 | 5 votes |
public boolean isUsbConnected(final Activity a) { final Intent intent = a.registerReceiver( null, new IntentFilter( "android.hardware.usb.action.USB_STATE") ); return intent != null && intent.getExtras().getBoolean("connected"); }
Example 15
Source Project: commcare-android File: SessionActivityRegistration.java License: Apache License 2.0 | 5 votes |
/** * Redirect to login if session expired, otherwise register activity to * listen for session expiration broadcasts. Call this method in onResume * methods of activities that are session sensitive. */ public static boolean handleOrListenForSessionExpiration(Activity activity) { activity.registerReceiver(userSessionExpiredReceiver, expirationFilter); synchronized (registrationLock) { if (unredirectedSessionExpiration) { unredirectedSessionExpiration = false; redirectToLogin(activity); return true; } return false; } }
Example 16
Source Project: FirefoxReality File: ConnectivityReceiver.java License: Mozilla Public License 2.0 | 4 votes |
public void register(Activity aActivity, Delegate aDelegate) { mDelegate = aDelegate; aActivity.registerReceiver(this, new IntentFilter(CONNECTIVITY_ACTION)); }
Example 17
Source Project: alpha-wallet-android File: FinishReceiver.java License: MIT License | 4 votes |
public FinishReceiver(Activity ctx) { activity = ctx; ctx.registerReceiver(this, new IntentFilter(C.PRUNE_ACTIVITY)); }
Example 18
Source Project: google-authenticator-android File: BarcodeConditionChecker.java License: Apache License 2.0 | 4 votes |
/** * Check if the device has low storage. */ public boolean isLowStorage(Activity activity) { IntentFilter lowStorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); return activity.registerReceiver(null, lowStorageFilter) != null; }
Example 19
Source Project: LoveTalkClient File: FinishReceiver.java License: Apache License 2.0 | 4 votes |
public static FinishReceiver register(Activity activity) { FinishReceiver receiver = new FinishReceiver(activity); activity.registerReceiver(receiver, new IntentFilter( FinishReceiver.FINISH_ACTION)); return receiver; }
Example 20
Source Project: geopaparazzi File: GpsServiceUtilities.java License: GNU General Public License v3.0 | 2 votes |
/** * register an activity for {@link GpsService} broadcasts. * * @param activity the activity. * @param receiver the receiver. */ public static void registerForBroadcasts(Activity activity, BroadcastReceiver receiver) { activity.registerReceiver(receiver, new IntentFilter(GPS_SERVICE_BROADCAST_NOTIFICATION)); }