Apertura del navegador en la notificación push

Estoy tratando de abrir el navegador con una url cuando el usuario haga clic en la notificación push, busco en stackoverflow y encuentro esto

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(browserIntent); 

Pero no funciona para mí, cuando pongo que la notificación no aparece, lo depuré y sólo lanzar el editor de archivos de clase ningún error o nada.

Este es el codigo

  public void mostrarNotificacion(Context context, String body,String title, String icon, String url,String superior) { String ns = Context.NOTIFICATION_SERVICE; NotificationManager notManager = (NotificationManager) context.getSystemService(ns); int icono = R.drawable.mydrawable; CharSequence textoEstado = superior; long hora = System.currentTimeMillis(); Notification notif = new Notification(icono, textoEstado, hora); Context contexto = context.getApplicationContext(); CharSequence titulo = title; CharSequence descripcion = body; PendingIntent contIntent; if(url.equalsIgnoreCase("NULL")) { Intent notIntent = new Intent(contexto,MainActivity.class); contIntent = PendingIntent.getActivity( contexto, 0, notIntent, 0); } else { // Intent i = new Intent(Intent.ACTION_VIEW); //i.setData(Uri.parse(url)); // contIntent = PendingIntent.getActivity(contexto, 0, i, 0); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(browserIntent); } // notif.setLatestEventInfo(contexto, titulo, descripcion, contIntent); //AutoCancel: notif.flags |= Notification.FLAG_AUTO_CANCEL; //send notif notManager.notify(1, notif); } 

Lo que debe hacer es establecer una intención pendiente, que se invocará cuando el usuario haga clic en la notificación. (Sobre usted apenas comenzó una actividad …)

He aquí un ejemplo de código:

 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 implicit intent to view url Intent resultIntent = new Intent(Intent.ACTION_VIEW); resultIntent.setData(Uri.parse(link)); PendingIntent pending = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); 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()); } 

Editar 1: He cambiado la respuesta para utilizar PendingIntent.FLAG_UPDATE_CURRENT para el propósito de la muestra. Gracias Aviv Ben Shabat por el comentario.

Editar 2: Después del comentario de Alex Zezekalo, tenga en cuenta que al abrir la notificación desde la pantalla de bloqueo, suponiendo que se utilice cromo, se producirá un error como se explica en el problema abierto: https://code.google.com/p/chromium/issues/detail? Id = 455126 –
Chrome ignorará la intención, y deberías poder encontrarla en tu logcat – E / cr_document.CLActivity: Ignorando la intención: Intent {act = android.intent.action.VIEW dat = http://google.com/ … Flg = 0x1000c000 cmp = com.android.chrome / com.google.android.apps.chrome.Main (tiene extras)}

  • Android OnNewIntent no se llama
  • ADB push -p Descripción incorrecta del archivo
  • No se puede establecer el sonido de notificación push en android
  • Iniciar la aplicación sólo si no está en ejecución
  • Anular el registro del cliente android desde el servidor de empuje unificado aerogear
  • MQTT Eclipse Paho cliente en Android, desconectar se bloquea y nunca termina
  • GCM Mantenga mensajes en el servidor hasta que llegue uno nuevo
  • Notificaciones push iOS y código nativo cliente-cliente de Android
  • Gestionar notificaciones múltiples / apilar notificaciones desde GCM
  • Enviar notificaciones push en android sin utilizar C2DM
  • Mensajes de GCM no se entregan
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.