Edytowałem kod za pomocą setOnClick w oczekiwaniu na intencję, a ten kod działa dla ImageView, a tekst powiadomień jest odseparowany, jak chcę, ale nadal potrzebuję pomocy.Niestandardowe powiadomienie ze zdalnym podglądem na Androidzie
Chcę przerwać lub odtwarzać mediaplayer z mojej klasy usług, więc w jaki sposób mogę uzyskać dostęp do metody zatrzymania lub gry z Powiadomienia w oczekiwaniu na intencję?
Niektórzy mówią, że odbiorniki telewizyjne pomogą ci, ale nie wiem dokładnie, jak to zadziała. Udało mi się otworzyć przeglądarkę internetową z przycisku pauzy z powiadomienia, ale nie wiem, jak uzyskać dostęp do metod obsługi. Udostępnij dowolny przykładowy kod, jeśli masz jakieś.
@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);
}
daje mi propozycję. buduję powiadamiania Powiększenie przy użyciu RemoteView kontrolować odtwarzanie/pauza jak tego linka (http://stackoverflow.com/questions/14508369/how-to-create-a -notyfikacja-podobna-do-play-music-app-from-google) Wszystkie mają rację, ale kiedy klikam przycisk powrotu urządzenia i wychodzę z aplikacji Przycisk kliknięcia jonowego (Play/Pause/Forward/Close) nie działa. Pomóż mi. –