标签:perm 使用 生成 ica http ble log system UI
使用Android Studio帮我们创建广播,点击包名-->New-->BroadcastReceiver
在清单文件中会自动生成
我们加上开机广播的action
<receiver android:name=".BootReceiver" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> </intent-filter> </receiver>
还要加上开机启动的权限
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
修改广播的onReceive方法,让其开机后弹出通知栏,方便我们观察
@Override public void onReceive(Context context, Intent intent) { Notification.Builder builder = new Notification.Builder(context); builder.setTicker("中奖通知"); builder.setAutoCancel(true); builder.setContentTitle("恭喜你中奖了"); builder.setContentText("你的号码被我公司抽中,中奖100万,请及时联络:139999"); builder.setSmallIcon(R.mipmap.ic_launcher); Notification notification = builder.build(); NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(1,notification); }
这样就完成了,我们多数是让它启动一个服务的。
标签:perm 使用 生成 ica http ble log system UI
原文地址:http://www.cnblogs.com/yeyupiaoling/p/7281190.html