Tôi đã chỉnh sửa mã bằng cách sử dụng mục đích setOnClick đang chờ xử lý và mã này hoạt động cho ImageView và văn bản thông báo riêng biệt theo ý muốn nhưng tôi vẫn cần trợ giúp.Thông báo tùy chỉnh với chế độ xem từ xa trên Android
Tôi muốn tạm dừng hoặc phát mediaplayer từ lớp dịch vụ của mình, vậy làm cách nào tôi có thể truy cập vào phương thức dừng hoặc phát dịch vụ từ mục đích Thông báo đang chờ xử lý?
Một số người cho biết máy thu phát sóng sẽ giúp bạn, nhưng tôi không biết chính xác nó sẽ hoạt động như thế nào. Tôi đã quản lý để mở trình duyệt web từ nút tạm dừng từ thông báo, nhưng tôi không biết cách truy cập các phương thức dịch vụ. Chia sẻ bất kỳ mã mẫu nào nếu bạn có.
@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);
}
Cung cấp cho tôi một gợi ý. tôi xây dựng một cái nhìn thông báo lớn sử dụng để kiểm soát RemoteView chơi/tạm dừng như liên kết này (http://stackoverflow.com/questions/14508369/how-to-create-a -notification-similar-to-play-music-app-from-google) Tất cả đều đúng nhưng khi tôi nhấp vào nút quay lại thiết bị và ra khỏi ứng dụng nút bấm sự kiện ion (Phát/Tạm dừng/Chuyển tiếp/Đóng) không hoạt động.Vui lòng giúp tôi. –