2012-10-16 2 views
0

3 가지 버튼 중 하나에 따라 Android 알림을 표시하는 간단한 앱이 있습니다.Android - 알림을 클릭하면 주요 활동이 열립니다. 다른 앱을 여는 방법은 무엇입니까?

개, 고양이, 또는 마우스

당신은 개 "개"쇼를 말한다 알림을 누르면. cat을 누르면 "Cat"이라고 표시된 알림이 표시됩니다. 마우스를 누르면 "마우스"라는 알림이 표시됩니다.

알림을 클릭하면 내 주요 활동으로 이동합니다 (세 개의 버튼이 다시 표시됨). 별도의 액티비티로 이동하여 알림을 클릭 한 내용을 읽은 다음 알림에서 textView로 텍스트를 설정합니다.

방법에 대한 아이디어가 있으십니까?

답변

2
NotificationCompat.Builder mBuilder = 
     new NotificationCompat.Builder(this) 
     .setSmallIcon(R.drawable.notification_icon) 
     .setContentTitle("My notification") 
     .setContentText("Hello World!"); 
// Creates an explicit intent for an Activity in your app 
Intent resultIntent = new Intent(this, ResultActivity.class); 

// The stack builder object will contain an artificial back stack for the 
// started Activity. 
// This ensures that navigating backward from the Activity leads out of 
// your application to the Home screen. 
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); 
// Adds the back stack for the Intent (but not the Intent itself) 
stackBuilder.addParentStack(ResultActivity.class); 
// Adds the Intent that starts the Activity to the top of the stack 
stackBuilder.addNextIntent(resultIntent); 
PendingIntent resultPendingIntent = 
     stackBuilder.getPendingIntent(
      0, 
      PendingIntent.FLAG_UPDATE_CURRENT 
     ); 
mBuilder.setContentIntent(resultPendingIntent); 
NotificationManager mNotificationManager = 
    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
// mId allows you to update the notification later on. 
mNotificationManager.notify(mId, mBuilder.build()); 

출처 : http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Actions

+0

쿨, 내 ResultActivity에 날 잡으려고했다,하지만 코드가 나는'.setContentTitle를 읽어 내 ResultActivity에 넣어 것입니다 ("내 통지")' – EGHDK

+0

ERR, 나는 그것이 통보의 제목이라고 생각한다. 이 값을 ResultActivity에 전달하려면 Intent.putExtra()를 사용하여 ResultActivity에 해당 값을 가져옵니다. – speakingcode

관련 문제