setOnClick 보류중인 인 텐트를 사용하여 코드를 편집했으며이 코드는 ImageView 및 알림 텍스트를 원하는대로 분리하여 작동하지만 여전히 도움이 필요합니다.Android에서 원격보기가있는 사용자 정의 알림
내 서비스 클래스에서 미디어 플레이어를 일시 중지하거나 재생하려면 알림 보류 의도에서 서비스 중지 또는 재생 방법에 어떻게 액세스 할 수 있습니까?
일부 사람들은 방송 수신기가 도움이 될 것이라고 말하지만 정확히 어떻게 작동하는지 알 수는 없습니다. 알림에서 일시 중지 버튼으로 웹 브라우저를 열 수 있었지만 서비스 방법에 액세스하는 방법을 모르겠습니다. 가지고 있다면 샘플 코드를 공유하십시오.
@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);
}
를 확인하실 수 있습니다 것은 내게 재생을 제어하는 리모트 뷰를 사용하여 알림 큰 뷰를 구축 할 수 있습니다. 제안을 제공합니다 /이 링크 (http://stackoverflow.com/questions/14508369/how-to-create-a처럼 일시 정지 -notification-similar-to-play-music-app-from-google) 모든 것이 옳다. 그러나 내가 device back button을 클릭했을 때 그리고 applicat 이온 클릭 이벤트 (재생/일시 정지/앞으로/닫기) 버튼이 작동하지 않습니다. 제발 도와주세요. –