2016-08-03 4 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

관련 문제