I want my application to detect if the state of the external storage has changed. First BroadcastReceiver was defined in my AndroidManifest. Here I can set the android:process and android:exported attributes as follows:
<receiver android:name=".StorageStateReceiver" android:process=":storage_state" android:exported="false"> <intent-filter> <action android:name="android.intent.action.MEDIA_UNMOUNTED" /> <action android:name="android.intent.action.MEDIA_MOUNTED" /> <action android:name="android.intent.action.MEDIA_EJECT" /> <action android:name="android.intent.action.MEDIA_BAD_REMOVAL" /> <data android:scheme="file" /> </intent-filter> </receiver>
Then I realized that I use this receiver in only one action, so there is no need to create it when the application starts, instead I can define it programmatically in the code. Here is what I came up with:
BroadcastReceiver StorageStateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) {
I put this code in the onCreate () method of my activity.
But I can not find a way to install process from the code. I read the documentation for the BroadcastReceiver and Context classes. BroadcastReceiver does not seem to contain methods that allow you to determine the process name. registerReceiver (), on the other hand, can take two additional arguments: String broadcastPermission , Handler scheduler . The handler sounds promising, but I could not find a Handler constructor that would accept the process name as a string. I feel like I'm running out of ideas. Is there a way to set the process name programmatically?
source share