2017-04-25 79 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

我試過但我想運行的文件是在不同的難題。 –

+0

這不是問題。嘗試以上方法 –

回答

0

使用下面的代碼來啓動所需/目標應用程序活動。

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

這應該有效。

+0

應用程序 - > com.zaglebiefm.Radio庫 - > 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打開應用程序。 –

相關問題