2015-04-06 31 views
0

我想我學會了如何從他們的網站創建android studio中的noitification,並簡單瞭解它如何貫穿。 Mebe更多地複製並粘貼一點修改= \。但是我沒有看到如何使用意圖在同一活動/類中啓動方法。使用意圖在同一類或新類中啓動方法

%來自Android的工作室我複製和粘貼代碼:

public void showNotification() 
{ 
    Intent emptyIntent = new Intent(this, JellyNotify.class); 
    TaskStackBuilder backStack = TaskStackBuilder.create(this) 
      .addNextIntent(emptyIntent) 
      .addParentStack(JellyNotify.class); 

    PendingIntent emptyPending = backStack.getPendingIntent(
      0, 
      PendingIntent.FLAG_UPDATE_CURRENT); 

    Notification buildNoti = new NotificationCompat.Builder(this) 
      .setSmallIcon(R.drawable.jelly) 
      .setContentTitle("Feeling Jelly") 
      .setContentText("Tap to launch Jar of Jelly") 
      .setContentIntent(emptyPending) 
      .build(); 

    NotificationManager manageNotification = (NotificationManager) 
      getSystemService(Context.NOTIFICATION_SERVICE); 

    manageNotification.notify(0,buildNoti); 
} 

我猜我想說的是,我試圖在類中啓動和活動或新的意圖,mebe連的方法或當用戶點擊正在進行的通知時創建的新活動。所以我的大腦因爲過去一週搜索而感到油炸。爲了說明我已經想出了我發現的網站,如:

android-er.blogspot

Clickable Notification - StackOverflow

回答

1

試試這個,

更新你的意圖如下,

public void showNotification() 
{ 
NotificationManager manageNotification = (NotificationManager) 
     getSystemService(Context.NOTIFICATION_SERVICE); 

Notification buildNoti = new NotificationCompat.Builder(this) 
     .setSmallIcon(R.drawable.jelly) 
     .setContentTitle("Feeling Jelly") 
     .setContentText("Tap to launch Jar of Jelly") 
     .setContentIntent(emptyPending) 
     .build(); 

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,new Intent(this, Activity_you_needto_launch.class), PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT); 

manageNotification.notify(0,buildNoti); 
} 
+0

對不起這樣遲到的回覆,這確實解決了我的問題。非常感謝。 – herboren

+0

歡迎,如果幫助你,請接受答案。那麼未來可能會幫助其他人 –

相關問題