【发布时间】:2014-12-23 17:14:18
【问题描述】:
我有一项服务会显示通知。通知正在正确显示,但是当我单击通知时没有任何反应。它应该在我的应用程序中打开一个活动。这是我的代码:
public class ServiceCheckExpensesRecurring extends Service{
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
int mNotificationId = 001;
Intent myIntent = new Intent(this, MenuDashboard.class);
myIntent.setAction(Intent.ACTION_VIEW);
myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pIntent = PendingIntent.getActivity(getBaseContext(), 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder n = new NotificationCompat.Builder(this)
.setContentTitle("New mail from " + "test@gmail.com")
.setContentText("Subject")
.setSmallIcon(R.drawable.common_signin_btn_icon_light)
.setContentIntent(pIntent)
.setAutoCancel(true);
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(mNotificationId, n.build());
return Service.START_NOT_STICKY;
}
}
仅供参考,MenuDashboard 是一个片段(如果有帮助的话)。我正在使用我的索尼 experia mini 和 ICS
【问题讨论】:
-
试过这个stackoverflow.com/a/21204851/301584 但还是不行
标签: android android-pendingintent