When specifying BroadcastReceiver in the manifest, I do not receive any of the following system actions:
public class BRMemoryHandler extends BroadcastReceiver { public BRMemoryHandler() { Log.d("BRMH", "ctor"); } @Override public void onReceive(Context arg0, Intent arg1) { Log.d("BRMH", "onReceive()"); } } <application android:name="Test" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" > <receiver android:name=".BRMemoryHandler" > <intent-filter> <action android:name="android.intent.action.ACTION_HEADSET_PLUG" /> <action android:name="android.intent.action.ACTION_DEVICE_STORAGE_OK" /> </intent-filter> </receiver>
However, I can get these actions if I create the same broadcast receiver programmatically in my main action:
void onCreate(Bundle b) { super.onCreate(Bundle b); BRMemoryHandler tbr = new BRMemoryHandler(); IntentFilter intF = new IntentFilter(); intF.addAction(Intent.ACTION_HEADSET_PLUG); intF.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); registerReceiver(tbr, intF);
source share