2011-06-03 6 views
15

Mi problema es el siguiente:La apertura de un enlace del navegador mediante la notificación no está funcionando

les dejo una notificación a la barra de notificaciones, y he puesto un enlace URI en la intención de ser enviado con él. Tan pronto como hago clic en la notificación, obtengo un diálogo de lo que quiero hacer, pero muestra basura como Información de la aplicación, Escáner de código de barras, Diálogo de llamadas. en lugar de navegador

presento mi código:

 Intent notificationIntent = new Intent(Intent.ACTION_VIEW); 

     PendingIntent contentIntent = PendingIntent.getActivity(contexta, 0, notificationIntent, 0); 
     notificationIntent.setData(Uri.parse("http://www.google.com")); 
     notification.setLatestEventInfo(contexta, contentTitle, contentText, contentIntent); 
     mNotificationManager.notify(970970, notification); 

así que estoy probablemente no pensar en la dirección correcta. ¿Debo insertar un intento y tener un controlador en mi propia aplicación para crear un nuevo intento para el navegador? Pero eso sería extraño, ¿por qué Android no maneja mi intención inicial correctamente entonces?

Como siempre, Cualquier ayuda es muy apreciada.

Gracias, Rohan.

Respuesta

30

Creo que el problema es que está configurando los datos en "notificationIntent" después de dárselos a PendingIntent.

Prueba esto:

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

     PendingIntent contentIntent = PendingIntent.getActivity(contexta, 0, notificationIntent, 0); 
     notification.setLatestEventInfo(contexta, contentTitle, contentText, contentIntent); 
     mNotificationManager.notify(970970, notification); 

O pruebe esto:

 Intent notificationIntent = new Intent(Intent.ACTION_VIEW); 

     notificationIntent.setData(Uri.parse("http://www.google.com")); 
     PendingIntent contentIntent = PendingIntent.getActivity(contexta, 0, notificationIntent, 0); 
     notification.setLatestEventInfo(contexta, contentTitle, contentText, contentIntent); 
     mNotificationManager.notify(970970, notification); 
4

su trabajo para mí

Intent notificationIntent = new Intent(Intent.ACTION_VIEW); 
      notificationIntent.setData(Uri.parse("http://www.google.com")); 
      PendingIntent pi = PendingIntent.getActivity(context, 0, notificationIntent, 0); 
      // Resources r = getResources(); 
       Notification notification = new NotificationCompat.Builder(context) 
         .setTicker("yortext") 
         .setSmallIcon(android.R.drawable.ic_menu_report_image) 
         .setContentTitle("yortext") 
         .setContentText("sdsd") 
         .setContentIntent(pi) 
         .setAutoCancel(true) 
         .build(); 

       NotificationManager notificationManager2 = (NotificationManager) context.getSystemService(Service.NOTIFICATION_SERVICE); 
       notificationManager2.notify(0, notification); 
+0

Hola, sirmagid. Tu código funciona genial ¿Sabes qué cambios se deben realizar para analizar el enlace en la aplicación (aplicación webview en mi caso) y no en el navegador? Realmente apreciaría cualquier ayuda. – JohnA10

+0

@ JohnA10, ¿logra encontrar el código para analizar? si es así, por favor publícalo. –

+0

@ChrisHarris ¿Tiene esta pregunta abierta en otro hilo? si publico el código aquí en la respuesta, se verá mal. – JohnA10

Cuestiones relacionadas