0

I have followed this link below and I have generated 2 notifications that shows up at onCreate.

How to create a notification with NotificationCompat.Builder?

My question is, how can I open a web page in a web browser when you press on a notification ?

This is my code

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

where should I put that intent ?

Community
  • 1
  • 1
Alex Bonta
  • 101
  • 4
  • 15

1 Answers1

0

Try to set this way:

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 set this PendingIntent to your NotificationCompat.Builder notificationBuilder like:

notificationBuilder.setContentIntent(pending);

Update: try to implement like this way:

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

For more information go to:http://www.vogella.com/tutorials/AndroidNotifications/article.html

M D
  • 47,665
  • 9
  • 93
  • 114