Java Code Examples for android.app.Activity#registerReceiver()

The following examples show how to use android.app.Activity#registerReceiver() . 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 File: PluginActivityMonitor.java    From Android-Plugin-Framework with MIT License 6 votes vote down vote up
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 2
Source File: AuthorizeHelper.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
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 3
Source File: DownloadMapActivity.java    From PocketMaps with MIT License 6 votes vote down vote up
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 4
Source File: NovarumbluetoothModule.java    From NovarumBluetooth with MIT License 6 votes vote down vote up
@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 5
Source File: ActivityHook.java    From AppTroy with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: SessionActivityRegistration.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
/**
 * 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 7
Source File: SystemSettings.java    From slide-android with GNU General Public License v2.0 5 votes vote down vote up
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 8
Source File: SearchPrinterDialog.java    From esc-pos-android with Apache License 2.0 5 votes vote down vote up
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 9
Source File: ConfirmationFragment.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    Activity activity = getActivity();
    if (activity != null) {
        activity.registerReceiver(mReceiver,
                new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));
    }
}
 
Example 10
Source File: HeadSetReceiver.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
/**
 * 注册广播的公共方法
 */
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 11
Source File: RNCAppearanceModule.java    From react-native-appearance with MIT License 5 votes vote down vote up
@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 12
Source File: PackageInstaller.java    From TvAppRepo with Apache License 2.0 5 votes vote down vote up
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 13
Source File: USB.java    From OkUSB with Apache License 2.0 5 votes vote down vote up
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 14
Source File: OrientationModule.java    From react-native-orientation-locker with MIT License 5 votes vote down vote up
@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 15
Source File: TokensReceiver.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
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 16
Source File: BarcodeConditionChecker.java    From google-authenticator-android with Apache License 2.0 4 votes vote down vote up
/**
 * 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 17
Source File: FinishReceiver.java    From LoveTalkClient with Apache License 2.0 4 votes vote down vote up
public static FinishReceiver register(Activity activity) {
	FinishReceiver receiver = new FinishReceiver(activity);
	activity.registerReceiver(receiver, new IntentFilter(
			FinishReceiver.FINISH_ACTION));
	return receiver;
}
 
Example 18
Source File: FinishReceiver.java    From alpha-wallet-android with MIT License 4 votes vote down vote up
public FinishReceiver(Activity ctx)
{
    activity = ctx;
    ctx.registerReceiver(this, new IntentFilter(C.PRUNE_ACTIVITY));
}
 
Example 19
Source File: ConnectivityReceiver.java    From FirefoxReality with Mozilla Public License 2.0 4 votes vote down vote up
public void register(Activity aActivity, Delegate aDelegate) {
    mDelegate = aDelegate;
    aActivity.registerReceiver(this, new IntentFilter(CONNECTIVITY_ACTION));
}
 
Example 20
Source File: GpsServiceUtilities.java    From geopaparazzi with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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));
}