背景:android MIUI系统
每次手动打开APP的activity的时候,就可以接收到broadcast(我的是接受耳机键按下)
但是如果退出并且杀掉内存,就会连receiver也没反应了,按耳机键就只有系统自带的音乐弹出
我想让一个service常驻,所以想用接受到Intent.ACTION_TIME_TICK来检查并启动service,但是现在连receiver都保不了...
请高人施救
<receiver
android:name="com.pushreceive.Rec1"
android:exported="true" >
<intent-filter android:priority="2147483647" >
<action android:name="android.intent.action.MEDIA_BUTTON" />
<action android:name="android.media.AUDIO_BECOMING_NOISY" />
</intent-filter>
</receiver>
<service
android:name=".Ser1"
android:enabled="true"
android:exported="false" >
<intent-filter android:priority="1000" >
<action android:name="com.demo.SERVICE_DEMO" />
<category android:name="android.intent.category.default" />
</intent-filter>
</service>
下面的是onReceive里面的代码
String intentAction = arg1.getAction();
if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
Toast.makeText(arg0, "你插入/拔出了耳机", 1).show();
} else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
arg0.startService(new Intent(arg0, Ser1.class));
Toast.makeText(arg0, "你按下了耳机键", 1).show();
}
}