0
我也跟着教程在一定的時間來顯示通知消息,但我不知道爲什麼它不工作通知消息不起作用
這裏是方法
//notification
private void startAlarm() {
AlarmManager alarmManager = (AlarmManager) this.getSystemService(this.ALARM_SERVICE);
Calendar Calendar_Object = Calendar.getInstance();
Calendar_Object.set(Calendar.MONTH, 12);
Calendar_Object.set(Calendar.YEAR, 2014);
Calendar_Object.set(Calendar.DAY_OF_MONTH, 31);
Calendar_Object.set(Calendar.HOUR_OF_DAY, 9);
Calendar_Object.set(Calendar.MINUTE, 06);
Calendar_Object.set(Calendar.SECOND, 0);
Intent intent = new Intent(ManagePassengers.this, AlarmReciver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(ManagePassengers.this, 0, intent, 0);
alarmManager.set(AlarmManager.RTC, Calendar_Object.getTimeInMillis(), pendingIntent);
}
廣播類
public class AlarmReciver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// When our Alaram time is triggered , this method will be excuted (onReceive)
// We're invoking a service in this method which shows Notification to the User
Intent myIntent = new Intent(context, NotificationService.class);
context.startService(myIntent);
}}
服務類
public class NotificationService extends Service {
private NotificationManager mManager;
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
// Getting Notification Service
mManager = (NotificationManager) this.getApplicationContext()
.getSystemService(
this.getApplicationContext().NOTIFICATION_SERVICE);
Intent intent1 = new Intent(this.getApplicationContext(), ManageRides.class);
Notification notification = new Notification(R.drawable.icon,
"See My App something for you", System.currentTimeMillis());
...
mManager.notify(0, notification);
}
....
}
清單編輯
<uses-permission android:name="android.permission.WAKE_LOCK" />
<activity android:name=".AlarmReciver" />
<activity android:name=".NotificationService" />
我等待我的日曆對象指定的,但似乎什麼都沒有,我不知道如果我錯過了什麼東西
任何幫助將受到讚賞時