在清单中指定BroadcastReceiver时,我没有收到以下系统操作:
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>
但是,如果我在主要活动中以编程方式创建相同的广播接收器,我将能够收到此操作:
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);