我是真正的新机器人,我一直在研究有关的报警。我想报警,如果有那一天生日。我已经使用报警管理。我很困惑,因为我已阅读,它重新启动后会清除。我这样做,我只是用模拟器没有一款Android手机。
I am really new to android, I have been researching about alarms. I want to alarm if there is a birthday on that day. I've have used alarm manager. I was confused because i have read that it clears after reboot. I don't have an android phone so I'm just using the emulator.
下面是我的code:
public void schedAlarm() { AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); Intent intent = new Intent(this, AlarmService.class); pendingIntent = PendingIntent.getBroadcast(this, contact.id, intent, PendingIntent.FLAG_ONE_SHOT); am.setRepeating(AlarmManager.RTC, timetoAlarm, nextalarm, pendingIntent); }
我提出这个BroadcastRecever在替换为AlarmSerivce 这里:
I made this BroadcastRecever in replace for AlarmSerivce Here :
public void onReceive(Context context, Intent intent) { nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); CharSequence from = "It Birthday!"; CharSequence message =" Greet your friend."; PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(), 0); Notification notif = new Notification(R.drawable.ic_launcher, "Birthday", System.currentTimeMillis()); notif.setLatestEventInfo(context, from, message, contentIntent); nm.notify(1, notif); }
这是不够??
is this enough??
推荐答案一个简单的答案是否。但是,是的,你可以通过创建实现这一的BroadcastReceiver 将启动报警,同时启动装置完成。
A simple answer would be NO. But yes you can achieve this by creating a BroadCastReceiver which will start the Alarm while booting completes of the device.
使用<作用机器人:名称=android.intent.action.BOOT_COMPLETED/> 诱捕启动活动的BroadcastReceiver类
Use <action android:name="android.intent.action.BOOT_COMPLETED" /> for trapping boot activity in BroadCastReceiver class.
您需要添加上面一行在AndroidManifest.xml中有:
You need to add above line in AndroidManifest.xml as follows,
<receiver android:name=".AutoStartUp" android:enabled="true" android:exported="false" android:permission="android.permission.RECEIVE_BOOT_COMPLETED"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>更多推荐
确实,即使重启后报警管理器持续?
发布评论