2017-04-25 4 views
0

알림을 클릭 한 후 내 응용 프로그램을 실행하고 싶습니다!알림을 클릭 한 후 응용 프로그램을 엽니 다. Android

나는 실행하려면 : 응용 프로그램 -> com.zaglebiefm.Radio

이 파일 diectory을 : 라이브러리 -> com.zaglebiefm.library.Notyfication

Notification.class :

private void buildNotification() { 

     Intent intentPlayPause = new Intent(NOTIFICATION_INTENT_PLAY_PAUSE); 
     Intent intentOpenPlayer = new Intent(NOTIFICATION_INTENT_OPEN_PLAYER); 
     Intent intentCancel = new Intent(NOTIFICATION_INTENT_CANCEL); 

     PendingIntent playPausePending = PendingIntent.getBroadcast(this, 23, intentPlayPause, 0); 
     PendingIntent openPending = PendingIntent.getBroadcast(this, 31, intentOpenPlayer, 0); 
     PendingIntent cancelPending = PendingIntent.getBroadcast(this, 12, intentCancel, 0); 


     RemoteViews mNotificationTemplate = new RemoteViews(this.getPackageName(), R.layout.notification); 
     Notification.Builder notificationBuilder = new Notification.Builder(this); 

     if (artImage == null) 
      artImage = BitmapFactory.decodeResource(getResources(), R.drawable.default_art); 

     mNotificationTemplate.setTextViewText(R.id.notification_line_one, singerName); 
     mNotificationTemplate.setTextViewText(R.id.notification_line_two, songName); 
     mNotificationTemplate.setImageViewResource(R.id.notification_play, isPlaying() ? R.drawable.btn_playback_pause : R.drawable.btn_playback_play); 
     mNotificationTemplate.setImageViewBitmap(R.id.notification_image, artImage); 

     mNotificationTemplate.setOnClickPendingIntent(R.id.notification_play, playPausePending); 




     Notification notification = notificationBuilder 
       .setSmallIcon(smallImage) 
       .setContentIntent(openPending) 
       .setPriority(Notification.PRIORITY_DEFAULT) 
       .setContent(mNotificationTemplate) 
       .setUsesChronometer(true) 
       .build(); 


     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 

      RemoteViews mExpandedView = new RemoteViews(this.getPackageName(), R.layout.notification_expanded); 

      mExpandedView.setTextViewText(R.id.notification_line_one, singerName); 
      mExpandedView.setTextViewText(R.id.notification_line_two, songName); 
      mExpandedView.setImageViewResource(R.id.notification_expanded_play, isPlaying() ? R.drawable.btn_playback_pause : R.drawable.btn_playback_play); 
      mExpandedView.setImageViewBitmap(R.id.notification_image, artImage); 

      mExpandedView.setOnClickPendingIntent(R.id.notification_expanded_play, playPausePending); 

      notification.bigContentView = mExpandedView; 
     } 

     if (mNotificationManager != null) 
      mNotificationManager.notify(NOTIFICATION_ID, notification); 

    } 

나는 몇 가지 시도했지만 그들은 나를 위해 작동하지 않습니다.

아이디어 나 해결책.

+0

사용이 작동합니다 : 의도 intentOpenPlayer = 새로운 의도 (getApplicationContext(), Radio.class를); –

+0

나는 시도했다. 그러나 나는 달리기를 원하는 파일이 다른 diectory에있다. –

+0

는 문제가되지 않습니다. 위의 방법을 시도하십시오 –

답변

0

대신 아래 코드를 사용하여 원하는/대상 응용 프로그램 활동을 실행하십시오.

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context,YourTargetActivity.class), 0); 
mBuilder.setContentIntent(pendingIntent); 

이렇게하면됩니다.

+0

app -> com.zaglebiefm.Radio library -> com.zaglebiefm.library.Notyfication –

+0

의견을 명확히하십시오. –

+0

http://imgur.com/a/T7pBo –

0
Intent myintent = new Intent(this, Splash_Activity.class); 
     myintent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | 
       Intent.FLAG_ACTIVITY_NEW_TASK); 
int randomPIN = (int)(Math.random()*9000)+1000; 
    PendingIntent conIntent = PendingIntent.getActivity(this, randomPIN, 
      myintent, PendingIntent.FLAG_UPDATE_CURRENT); 
    builder.setContentIntent(conIntent); 

+0

http://imgur.com/a/1KYPZ –

+0

RadioPlayerServiece에서 응용 프로그램을 열려고합니다. –

관련 문제