2014-06-11 3 views
0

나는 실제로 안드로이드에서 notifications와 함께 일하고있다.android에서 알림을 클릭 한 후 앱에 새보기를 추가 하시겠습니까?

응용 프로그램 테스트를 수행하려면 the guide on android.developer을 따르십시오.

알림을 생성합니다. 정상적으로 작동합니다. 클릭하면 알림 탭에서 알림을 제거하고 내 활동으로 이동합니다. 여기

내가 그렇게하는 데 사용하는 코드입니다 :

public void createSimpleNotification() { 
    NotificationCompat.Builder mNotifBuilder = new NotificationCompat.Builder(this.getApplicationContext()) 
    .setSmallIcon(R.drawable.ic_notif).setContentTitle("Simple notif").setContentText("Welcome on our app, click here"); 

    Intent resultIntent = new Intent(this, MainActivity.class); 

    TaskStackBuilder mStackBuilder = TaskStackBuilder.create(this.getApplicationContext()); 
    mStackBuilder.addParentStack(MainActivity.class); 
    mStackBuilder.addNextIntent(resultIntent); 

    PendingIntent resultPendingIntent = mStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); 

    mNotifBuilder.setContentIntent(resultPendingIntent); 

    NotificationManager mNotifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    mNotifManager.notify(0, mNotifBuilder.build()); 
} 

난 단지가 내 MainActivityButton. 버튼을 클릭하면 알림이 나타나고 알림을 클릭하면 MainActivity로 돌아옵니다. 내가 통지를 클릭 한 후 내 MainActivity UI을 업데이트 할

:

여기 내 문제입니다. 알림을 클릭 한 후 알림 텍스트를 표시하는 Dialog을 만들어야합니다.

알림을 클릭 한 후 Activity을 수정하고 View을 새로 추가하려면 어떻게해야합니까?

답변

0

이미있는보기를 사용하십시오. 따라서 액티비티에서 생성하고 가시성을 FALSE으로 설정하십시오.

이제 표시하려는 경우 알림 텍스트를 넣고 가시성을 TRUE으로 설정하십시오. 이것은 귀하의 요청을 처리한다)

+0

을에 그것을 처리 나는 당신과 동의하지만 어떻게 통지에 onClick 내보기에 액세스 할 수 있습니까? – Androzr

+0

활동에보기를 만듭니다. 그냥 정적 클래스 변수로 만드십시오. 'ActivityWithView.myNotificationView' (예 : – PKlumpp

+0

)를 통해 액세스 할 수 있습니다. 네가하는 말을 이해하지만 알림이 클릭되었는지 어떻게 알 수 있습니까? – Androzr

0
당신이 의도 당신의 결과에 추가를 넣어 추가 할 수 있습니다

같은 :

resultIntent.putExtra(EXTRA_NAME, EXTRA_VALUE);

다음

당신의 MainActivity onNewIntent

protected void onNewIntent(Intent intent) { 
     if (intent.hasExtra(EXTRA_NAME)) { 
      // do your things here 
     } 
    } 
관련 문제