2014-04-08 10 views
0

내 음악 플레이어 용으로 notification을 구축 중이므로 어떤 음악이 재생되는지 표시합니다. 하지만 터치 할 때 함수를 추가하고 싶습니다. 내 레이아웃 player.xml을 엽니 다. MainActivity.class을 통해 배포됩니다.알림을 건드릴 때 어떻게 활동을 열 수 있습니까?

developer.android.com의 알림을 조사하고 알림을 클릭하면 배포 및 활동 방법을 찾았습니다. 그러나 그것은 효과가 없습니다. 답변에 대한 모든 사람에게

Notification.Builder builder = new Notification.Builder(getApplicationContext()); 
       builder.setContentTitle(songsList.get(songIndex).get("songTitle")); 
       builder.setContentText("NexPlay™"); 
       builder.setTicker(songsList.get(songIndex).get("songTitle")); 
       builder.setSmallIcon(R.drawable.ic_launcher); 
       builder.setSmallIcon(R.drawable.play_default); 
       builder.setAutoCancel(true); 
       builder.setPriority(0); 
       builder.setOngoing(true);   
       Notification notification = builder.build(); 
       NotificationManager notificationManger = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);   
       notificationManger.notify(01, notification); 

감사합니다 -

여기에 내 현재 코드입니다!

나는 내 알림에

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, NotificationToPlayer.class), 0); 
builder.setContentIntent(pendingIntent); 

을 추가하고 그것은 큰 일!

+0

코드에서 '알림 내용 의도'를 설정해야하는 곳은 무엇입니까? –

+0

다음 예제를 따르십시오 http://developer.android.com/training/notify-user/build-notification.html –

답변

0

이를이

private void showNotification() { 
     // In this sample, we'll use the same text for the ticker and the expanded notification 
     CharSequence text = getText(R.string.service_started); 

     // Set the icon, scrolling text and timestamp 
     Notification notification = new Notification(R.drawable.android, text, 
       System.currentTimeMillis()); 

     // The PendingIntent to launch our activity if the user selects this notification 
     PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
       new Intent(this, ServiceLauncher.class), 0); 

     // Set the info for the views that show in the notification panel. 
     notification.setLatestEventInfo(this, getText(R.string.service_label), 
         text, contentIntent); 
     notification.defaults |= Notification.DEFAULT_SOUND; 
     // Send the notification. 
     // We use a layout id because it is a unique number. We use it later to cancel. 
     nm.notify(R.string.service_started, notification); 
    } 

희망을 봅니다 당신의 문제를 해결할 것입니다

+0

고맙습니다. 귀하의 도움이되고 도움이되었습니다. 방금 추가했습니다. \t \t PendingIntent pendingIntent = PendingIntent.getActivity 0, 새로운 인 텐트 (this, NotificationToPlayer.class), 0); \t \t \t \t builder.setContentIntent (pendingIntent); 그리고 t는 일했다 :) – SmallVille

+0

좋아, 다행스럽게 도왔다. –

0

의도를 추가 할 수도 있습니다. 뭔가 같이 : 빌더에서 다음

Intent actIntent = new Intent(this, do MyActivity.class); 

:

.setContentIntent(PendingIntent.getActivity(MyActivity, 131314, actIntent, 
        PendingIntent.FLAG_UPDATE_CURRENT)) 
0

당신은 UR 코드에 의도를 추가해야합니다 : -

int icon = R.drawable.app_launcher; 
       long when = System.currentTimeMillis(); 
       NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 

       Notification notification = new Notification(icon, message.split(":::")[1], when); 

       String title = context.getString(R.string.app_name); 
       Intent notificationIntent = null; 
        notificationIntent = new Intent(context, MessageDetail.class); 

       PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
       notification.setLatestEventInfo(context, title, message.split(":::")[1], intent); 
       notification.flags |= Notification.FLAG_AUTO_CANCEL; 

       // Play default notification sound 
       notification.defaults |= Notification.DEFAULT_SOUND; 
       // Vibrate if vibrate is enabled 
       notification.defaults |= Notification.DEFAULT_VIBRATE; 
       notificationManager.notify(0, notification); 
관련 문제