2014-02-23 80 views
0

我按照下面的這個鏈接,我已經生成了2個通知,顯示在onCreate。Android簡單通知

How to create a notification with NotificationCompat.Builder?

我的問題是,我怎麼能在Web瀏覽器中打開一個網頁,當你按下的通知?

這是我的代碼

Wait a seccond , i'm a newbie .. I have this code 


public class MainActivity extends Activity { 
private WebView mWebView; 
NotificationCompat.Builder mBuilder = 
     new NotificationCompat.Builder(this) 
     .setSmallIcon(R.drawable.notif) 
     .setContentTitle("Notification title1") 
     .setContentText("Notification text1"); 

NotificationCompat.Builder pBuilder = 
     new NotificationCompat.Builder(this) 
     .setSmallIcon(R.drawable.photoline) 
     .setContentTitle("Photoline Studio") 
     .setContentText("App sponsorizate de Photoline Studio!"); 



@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    getWindow().requestFeature(Window.FEATURE_NO_TITLE); 

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.notify(0, mBuilder.build()); 
    notificationManager.notify(1, pBuilder.build()); 

我應該在哪裏把那個意圖是什麼?

回答

0

嘗試設置這樣:

Intent resultIntent = new Intent(Intent.ACTION_VIEW); 
resultIntent.setData(Uri.parse("http://www.google.com")); 

PendingIntent pending = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK); 

答設置此PendingIntentNotificationCompat.Builder notificationBuilder,如:

notificationBuilder.setContentIntent(pending); 

更新:嘗試實現像這樣:

private void createNotification(String text, String link){ 

NotificationCompat.Builder notificationBuilder = 
    new NotificationCompat.Builder(this) 
.setAutoCancel(true) 
.setSmallIcon(R.drawable.app_icon) 
.setContentTitle(text); 

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

// pending intent is redirection using the deep-link 
Intent resultIntent = new Intent(Intent.ACTION_VIEW); 
resultIntent.setData(Uri.parse(link)); 

PendingIntent pending = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK); 
notificationBuilder.setContentIntent(pending); 

// using the same tag and Id causes the new notification to replace an existing one 
mNotificationManager.notify(String.valueOf(System.currentTimeMillis()), PUSH, notificationBuilder.build()); 
} 

欲瞭解更多信息,請訪問:http://www.vogella.com/tutorials/AndroidNotifications/article.html

+0

啊我是個新手,我不知道如何實現代碼到我的腳本..我現在貼出我的代碼 –

+0

試圖實現按我的更新。 thnx –

+0

好吧,我發自我這樣做這樣 –