2016-08-03 19 views
0

8個のバージョンの次のコードを試しましたが、通知をクリックしたときにホームアクティビティが起動していません。ここで通知のクリック後にアクティビティが起動していません。

は、コードが

NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()); 
builder.setSmallIcon(R.mipmap.alert); 
builder.setContentTitle(""); 
builder.setContentText("Running in Background"); 
builder.setOngoing(true); 

IntenIntenticationIntent = new Intent(getApplicationContext(), Home.class); 

PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0,notificationIntent, 0); 
notificationManager = (NotificationManager) getApplicationContext().getSystemService(getApplicationContext().NOTIFICATION_SERVICE); 
notificationManager.notify(NOTIFICATION_ID, builder.build()); 

答えて

1

あなたは以下のコードを喜ばでした(それはサービスの内側です)のですか?

Intent notificationIntent = new Intent(this, Home.class); 
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
builder.setSmallIcon(R.mipmap.alert); 
builder.setContentTitle(""); 
builder.setContentText("Running in Background"); 
builder.setOngoing(true); 
builder.setContentIntent(contentIntent); 

notificationManager = (NotificationManager) this.getSystemService(Service.NOTIFICATION_SERVICE); 
notificationManager.notify(NOTIFICATION_ID, builder.build()); 
+0

あなたは素晴らしいです!私はこれを働かせるために数時間努力してきました。私はそれが私が行方不明だったsetContentIntentだと思います。 – Movieboy

関連する問題