我的通知是一项服务(service.java),该服务的作用是在选中首选项屏幕中的复选框首选项时启动电池电量通知。现在不起作用的是输入MainActivity
单击通知的意图。这是代码
if(mprefs.getBoolean("notification_a", false)==true){
notificationBuilder = new NotificationCompat.Builder(context);
notificationBuilder.setOngoing(true);
notificationBuilder.setContentTitle("Battery Stats Informations");
notificationBuilder.setContentText("Carica residua: " +level+"%" + " " + "Temperatura: " +temperature+ "°C");
//notificationBuilder.setTicker("Informazioni batteria");
notificationBuilder.setWhen(System.currentTimeMillis());
notificationBuilder.setSmallIcon(R.drawable.icon_small_not);
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getBroadcast(context, 0, notificationIntent, 0);
notificationBuilder.setContentIntent(contentIntent);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Notification not=notificationBuilder.build();
mNotificationManager.notify(SIMPLE_NOTIFICATION_ID,not);
} else {
mNotificationManager.cancelAll();
}
意图Intent notificationIntent = new Intent(context, MainActivity.class
不起作用。有什么帮助吗?