2014-02-23 3 views
0

아래 링크를 따라 가며 onCreate에 표시되는 2 개의 알림을 생성했습니다.Android 단순 알림

How to create a notification with NotificationCompat.Builder?

내 질문은 당신이 알림을 누를 때 나는 웹 브라우저에서 웹 페이지를 열 수있는 방법인가?

이것은

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); 

Ans By의가이 PendingIntent 설정을하여 NotificationCompat.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

좋아, 나는 이것을 좋아하지 않았다. –