android.app.Application#registerReceiver ( )源码实例Demo

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

源代码1 项目: UPMiss   文件: MissService.java
@Override
public void onCreate() {
    super.onCreate();
    Model.log(TAG, "onCreate");

    Application application = getApplication();
    mReceiver = new MissServiceBroadcastReceiver();

    try {
        IntentFilter filter = new IntentFilter();
        filter.addAction(ACTION_MISS_WIDGET_REFRESH);
        application.registerReceiver(mReceiver, filter);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Register Alarm
    addAlarm(getApplication());
}
 
源代码2 项目: XPrivacy   文件: XApplication.java
@Override
protected void after(XParam param) throws Throwable {
	switch (mMethod) {
	case onCreate:
		// Install receiver for package management
		if (PrivacyManager.isApplication(Process.myUid()) && !mReceiverInstalled)
			try {
				Application app = (Application) param.thisObject;
				if (app != null) {
					mReceiverInstalled = true;
					Util.log(this, Log.INFO, "Installing receiver uid=" + Process.myUid());
					app.registerReceiver(new Receiver(app), new IntentFilter(ACTION_MANAGE_PACKAGE),
							PERMISSION_MANAGE_PACKAGES, null);
				}
			} catch (SecurityException ignored) {
			} catch (Throwable ex) {
				Util.bug(this, ex);
			}
		break;
	}
}
 
源代码3 项目: easyble-x   文件: EasyBLE.java
public synchronized void initialize(@NonNull Application application) {
    if (isInitialized()) {
        return;
    }
    Inspector.requireNonNull(application, "application can't be");
    this.application = application;
    //检查是否支持BLE
    if (!application.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
        return;
    }
    //获取蓝牙配置器
    BluetoothManager bluetoothManager = (BluetoothManager) application.getSystemService(Context.BLUETOOTH_SERVICE);
    if (bluetoothManager == null || bluetoothManager.getAdapter() == null) {
        return;
    }
    bluetoothAdapter = bluetoothManager.getAdapter();
    //注册蓝牙开关状态广播接收者
    if (broadcastReceiver == null) {
        broadcastReceiver = new InnerBroadcastReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
        filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
        filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
        filter.addAction(BluetoothDevice.ACTION_FOUND);
        application.registerReceiver(broadcastReceiver, filter);
    }        
    isInitialized = true;
}
 
源代码4 项目: ZjDroid   文件: ModuleContext.java
@Override
public void afterHookedMethod(HookParam param) {
    if (!HAS_REGISTER_LISENER) {
        fristApplication = (Application) param.thisObject;
        BroadcastReceiver broadcastReceiver = new CommandBroadcastReceiver();

        fristApplication.registerReceiver(broadcastReceiver, new IntentFilter(CommandBroadcastReceiver.INTENT_ACTION));


        HAS_REGISTER_LISENER = true;
    }
}
 
源代码5 项目: mcumgr-android   文件: ScannerViewModel.java
/**
 * Register for required broadcast receivers.
 */
private void registerBroadcastReceivers(@NonNull final Application application) {
    application.registerReceiver(mBluetoothStateBroadcastReceiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
    if (Utils.isMarshmallowOrAbove()) {
        application.registerReceiver(mLocationProviderChangedReceiver, new IntentFilter(LocationManager.MODE_CHANGED_ACTION));
    }
}
 
源代码6 项目: LiveEventBus   文件: LiveEventBusCore.java
void registerReceiver() {
    if (isRegisterReceiver) {
        return;
    }
    Application application = AppUtils.getApp();
    if (application != null) {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(IpcConst.ACTION);
        application.registerReceiver(receiver, intentFilter);
        isRegisterReceiver = true;
    }
}
 
源代码7 项目: LiveEventBus   文件: LiveEventBusCore.java
void registerReceiver() {
    if (isRegisterReceiver) {
        return;
    }
    Application application = AppUtils.getApp();
    if (application != null) {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(IpcConst.ACTION);
        application.registerReceiver(receiver, intentFilter);
        isRegisterReceiver = true;
    }
}
 
源代码8 项目: zjdroid   文件: ModuleContext.java
@Override
public void afterHookedMethod(HookParam param) {
	// TODO Auto-generated method stub
	if (!HAS_REGISTER_LISENER) {
		fristApplication = (Application) param.thisObject;
		IntentFilter filter = new IntentFilter(CommandBroadcastReceiver.INTENT_ACTION);
		fristApplication.registerReceiver(new CommandBroadcastReceiver(), filter);
		HAS_REGISTER_LISENER = true;
	}
}
 
源代码9 项目: AppTroy   文件: Oncreatehook.java
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
    Log.d("cc", "after, register receiver");
    if (!ModuleContext.HAS_REGISTER_LISENER) {
        Application firstApplication = (Application) param.thisObject;
        IntentFilter filter = new IntentFilter(CommandBroadcastReceiver.INTENT_ACTION);
        firstApplication.registerReceiver(new CommandBroadcastReceiver(), filter);
        ModuleContext.HAS_REGISTER_LISENER = true;
        ModuleContext.getInstance().setFirstApplication(firstApplication);
        Log.d("cc", "register over");
    }
}
 
源代码10 项目: Android-nRF-Blinky   文件: ScannerViewModel.java
/**
 * Register for required broadcast receivers.
 */
private void registerBroadcastReceivers(@NonNull final Application application) {
	application.registerReceiver(bluetoothStateBroadcastReceiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
	if (Utils.isMarshmallowOrAbove()) {
		application.registerReceiver(locationProviderChangedReceiver, new IntentFilter(LocationManager.MODE_CHANGED_ACTION));
	}
}
 
源代码11 项目: HeyGirl   文件: ModuleContext.java
@Override
public void afterHookedMethod(HookParam param) {
	// TODO Auto-generated method stub
	if (!HAS_REGISTER_LISENER) {
		fristApplication = (Application) param.thisObject;
		IntentFilter filter = new IntentFilter(CommandBroadcastReceiver.INTENT_ACTION);
		fristApplication.registerReceiver(new CommandBroadcastReceiver(), filter);
		HAS_REGISTER_LISENER = true;
	}
}
 
源代码12 项目: ZjDroid   文件: ModuleContext.java
@Override
public void afterHookedMethod(HookParam param) {
	// TODO Auto-generated method stub
	if (!HAS_REGISTER_LISENER) {
		fristApplication = (Application) param.thisObject;
		IntentFilter filter = new IntentFilter(CommandBroadcastReceiver.INTENT_ACTION);
		fristApplication.registerReceiver(new CommandBroadcastReceiver(), filter);
		HAS_REGISTER_LISENER = true;
	}
}
 
源代码13 项目: buck   文件: ExoHelper.java
/**
 * Enable hotswapping on an application instance. This call is not necessary if using {@link
 * ExopackageApplication}. If enabling manually, make sure the app is set up to support the
 * "modules" exopackage mode, and the initial call to {@link
 * ExopackageDexLoader#loadExopackageJars(Context, boolean)} passed true as the second arg
 */
public static synchronized void setupHotswap(Application application) {
  if (!sIsHotswapSetup) {
    final File dexOptDir = application.getDir("exopackage_modular_dex_opt", Context.MODE_PRIVATE);
    DelegatingClassLoader.getInstance().setDexOptDir(dexOptDir);
    application.registerReceiver(
        new ModularDexChangedReceiver(),
        ModularDexChangedReceiver.getIntentFilter(application.getPackageName()));

    sIsHotswapSetup = true;
  }
}
 
源代码14 项目: 1Rramp-Android   文件: ConnectivityViewModel.java
public ConnectivityViewModel(@NonNull Application application) {
  super(application);
  application.registerReceiver(new NetworkChangeReceiver(), new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}