ver silenciosas silencio silenciar significa que puede notificaciones mis grupo estados dan cuenta alguien android android-layout push-notification android-notifications

silenciosas - Android: usa una imagen de perfil externa en la barra de notificaciones como Facebook



si silencio a alguien en whatsapp puede ver mis estados (4)

Sé que puede enviar información en los parámetros de notificación de inserción como mensaje, título, URL de imagen, etc. ¿Cómo muestra Facebook su foto de perfil con su mensaje en el área de notificación? Quiero usar una imagen externa en el área de notificación, de modo que cuando la baje, verá la imagen del perfil con el mensaje. En este momento, el mío solo muestra el icono predeterminado de la carpeta dibujable. Pensé que esto podría ser una pregunta común, pero no pudo encontrar nada. Cualquier tipo de ayuda sería buena.


Usé Universal Image Loader para resolver esto. Echa un vistazo a la wiki sobre cómo configurarlo. Después de crear una instancia, este es el código que uso en mi escucha GCM para descargar y mostrar la imagen. Descargo el mapa de bits y luego lo configuro en la notificación:

// Download profile picture of the user with Universal Image Loader Bitmap bitmap = ImageLoader.getInstance().loadImageSync(profilePhotoUrl); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_my_app) .setLargeIcon(bitmap) // This is the image displayed on the lock screen .setContentTitle("My App") .setContentText(message) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent);


Esta declaración utilizará un método para convertir una URL (naturalmente, una que apunta a una imagen) en un Bitmap .

Bitmap bitmap = getBitmapFromURL("https://graph.facebook.com/YOUR_USER_ID/picture?type=large");

Nota: como mencionó un perfil de Facebook, he incluido una URL que le permite obtener una imagen de perfil de gran tamaño de un usuario de Facebook. Sin embargo, puede cambiar esto a cualquier URL que apunte a una imagen que necesita mostrar en la Notification .

Y el método que obtendrá la imagen de la URL que especificó en la declaración anterior:

public Bitmap getBitmapFromURL(String strURL) { try { URL url = new URL(strURL); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); Bitmap myBitmap = BitmapFactory.decodeStream(input); return myBitmap; } catch (IOException e) { e.printStackTrace(); return null; } }

Ahora pase la instancia de bitmap creada anteriormente a la instancia de Notification.Builder . Lo llamo builder en este código de ejemplo. Se usa en esta línea: builder.setLargeIcon(bitmap); . Supongo que usted sabe cómo mostrar la Notification real y sus configuraciones. Así que me saltaré esa parte y añadiré solo el constructor .

// CONSTRUCT THE NOTIFICATION DETAILS builder.setAutoCancel(true); builder.setSmallIcon(R.drawable.ic_launcher); builder.setContentTitle("Some Title"); builder.setContentText("Some Content Text"); builder.setLargeIcon(bitmap); builder.setContentIntent(pendingIntent);

Oh, casi lo olvido, si aún no lo ha hecho, necesitará esta configuración de permiso en el Manifiesto:

<uses-permission android:name="android.permission.INTERNET" />


descarga la imagen primero usando el siguiente código:

private Bitmap getBitmap(String url) { File f=fileCache.getFile(url); //from SD cache Bitmap b = decodeFile(f); if(b!=null) return b; //from web try { Bitmap bitmap=null; URL imageUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection(); conn.setConnectTimeout(30000); conn.setReadTimeout(30000); conn.setInstanceFollowRedirects(true); InputStream is=conn.getInputStream(); OutputStream os = new FileOutputStream(f); Utils.CopyStream(is, os); os.close(); bitmap = decodeFile(f); return bitmap; } catch (Exception ex){ ex.printStackTrace(); return null; } } //decodes image and scales it to reduce memory consumption private Bitmap decodeFile(File f){ try { //decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //Find the correct scale value. It should be the power of 2. final int REQUIRED_SIZE=70; int width_tmp=o.outWidth, height_tmp=o.outHeight; int scale=1; while(true){ if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE) break; width_tmp/=2; height_tmp/=2; scale*=2; } //decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize=scale; return BitmapFactory.decodeStream(new FileInputStream(f), null, o2); } catch (FileNotFoundException e) {} return null; }

usa esa imagen como mapa de bits en el siguiente código:

Bitmap icon1 = downloadedBitmap; NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( this).setAutoCancel(true) .setContentTitle("DJ-Android notification") .setSmallIcon(R.drawable.ic_launcher) .setContentText("Hello World!"); NotificationCompat.BigPictureStyle bigPicStyle = new NotificationCompat.BigPictureStyle(); bigPicStyle.bigPicture(icon1); bigPicStyle.setBigContentTitle("Dhaval Sodha Parmar"); mBuilder.setStyle(bigPicStyle); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, testActivity.class); // The stack builder object will contain an artificial back stack // for // the // started Activity. // This ensures that navigating backward from the Activity leads out // of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(testActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( 0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(100, mBuilder.build());

Creo que no sabes nada sobre el permiso de Android:

<uses-permission android:name="android.permission.INTERNET" />

para más detalles revisa este desarrollador artical y android


Notification notif = new Notification.Builder(context) .setContentTitle("Title") .setContentText("content") .setSmallIcon(R.drawable.ic_small) .setLargeIcon(bitmap) .setStyle(new Notification.BigPictureStyle() .bigPicture(bigBitmap) .setBigContentTitle("big title")) .build();