0
我想实现的是赶上启动完成事件的广播接收机。引导接收器不工作
我把权限在manifet
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
我把意图过滤清单中的接收器标签后(类文件是在接收包)
<receiver android:name=".receivers.BootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.REBOOT" />
</intent-filter>
</receiver>
最后我宣布接收者类。该类应从数据库加载一些数据并设置警报。然而为了检查它是否有效,我已经放了一个吐司,但它没有显示和振动。
public class BootReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent callingIntent) {
Vibrator vibrator=(Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(5000);
Toast.makeText(context, "BOOT RECEIVED", Toast.LENGTH_LONG).show();
}
}
有人知道为什么请吗?
+1有趣的解释 - 我只是想回答说你需要先运行应用程序,然后才能收到它。尼斯。 –
谢谢。 BTW预装的应用程序不会去的/data/system/packages-stopped.xml,因此所有的人都能够接受的事件。此外,应用程序的强制停止使该应用程序进入该文件,意味着停止状态。 –