我有一個服務將顯示通知。通知顯示正確,但是當我點擊nofitification時沒有任何反應。它應該在我的應用程序中打開一個活動。這裏是我的代碼:PendingIntent不起作用
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 " + "[email protected]")
.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是一個片段(如果有幫助)。我正在使用我的索尼體驗迷你ICS
嘗試此http://stackoverflow.com/a/21204851/301584但仍然不起作用 – imin