He editado el código mediante el uso de setOnClick pendiente de intento, y este código funciona para ImageView y el texto de las notificaciones se separa como yo quiero, pero aún necesito ayuda.Notificación personalizada con vista remota en Android
Quiero pausar o reproducir el reproductor de medios de mi clase de servicio, entonces, ¿cómo podría acceder al método de detención o reproducción desde el intento de notificación pendiente?
Algunos dicen que los receptores de difusión te ayudarán, pero no entiendo exactamente cómo va a funcionar. He logrado abrir un navegador web desde el botón de pausa desde la notificación, pero no sé cómo acceder a los métodos de servicio. Comparte cualquier código de muestra si tienes alguno.
@SuppressWarnings("deprecation")
void showNotification() {
int pendingRequestCode = 0;
int pendingFlag = 0;
final Resources res = getResources();
final NotificationManager notificationManager = (NotificationManager) getSystemService(
NOTIFICATION_SERVICE);
Intent intent = new Intent(this,MainActivity.class);
PendingIntent pi= PendingIntent.getActivity(this, 0, intent, 0);
Notification.Builder builder = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_action_search)
.setAutoCancel(true)
.setTicker("this is notification")
.setContentIntent(pi);
// Sets a custom content view for the notification, including an image button.
RemoteViews layout = new RemoteViews(getPackageName(), R.layout.notification);
layout.setTextViewText(R.id.notification_title, getString(R.string.app_name));
Intent clickIntent = new Intent(Intent.ACTION_VIEW, Uri_myBlog);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),pendingRequestCode, clickIntent, pendingFlag);
layout.setOnClickPendingIntent(R.id.notification_button,pendingIntent);
builder.setContent(layout);
// Notifications in Android 3.0 now have a standard mechanism for displaying large
// bitmaps such as contact avatars. Here, we load an example image and resize it to the
// appropriate size for large bitmaps in notifications.
Bitmap largeIconTemp = BitmapFactory.decodeResource(res,
R.drawable.pause);
Bitmap largeIcon = Bitmap.createScaledBitmap(
largeIconTemp,
res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height),
false);
largeIconTemp.recycle();
builder.setLargeIcon(largeIcon);
notificationManager.notify(NOTIFICATION_DEFAULT, builder.getNotification());
}
PendingIntent getDialogPendingIntent(String dialogText) {
return PendingIntent.getActivity(
this,
dialogText.hashCode(), // Otherwise previous PendingIntents with the same
// requestCode may be overwritten.
new Intent(ACTION_DIALOG)
.putExtra(Intent.EXTRA_TEXT, dialogText)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
0);
}
Me da una sugerencia. Construyo una vista grande de notificaciones usando RemoteView para controlar la reproducción/pausa como este enlace (http://stackoverflow.com/questions/14508369/how-to-create-a -notification-similar-to-play-music-app-from-google) Todos son correctos, pero cuando hago clic en el botón Atrás del dispositivo y salen de la aplicación El botón de evento de clic ión (Reproducir/Pausa/Avanzar/Cerrar) no funciona. Por favor, ayúdenme. –