android broadcastreceiver广播怎么用
1个回答
展开全部
下面是一个监听开机广播的接收器:
public class BootCompletedReceiver extends BroadcastReceiver {
// private PendingIntent mAlarmSender;
@Override
public void onReceive(final Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
intent.setClass(context, Timerk.class);
context.startService(intent);
}
}
}
注意:在manifest添加拿租:
<receiver
android:name=".BootCompletedReceiver"
android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED"盯仔 >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" >
<category android:name="android.intent.category.DEFAULT" />
</action>
</intent-filter>
<消则兆/receiver>
public class BootCompletedReceiver extends BroadcastReceiver {
// private PendingIntent mAlarmSender;
@Override
public void onReceive(final Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
intent.setClass(context, Timerk.class);
context.startService(intent);
}
}
}
注意:在manifest添加拿租:
<receiver
android:name=".BootCompletedReceiver"
android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED"盯仔 >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" >
<category android:name="android.intent.category.DEFAULT" />
</action>
</intent-filter>
<消则兆/receiver>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询