Android 4.0 custom notification like google music

↘锁芯ラ 提交于 2019-12-05 08:31:34

I'm not sure how it's made in google music, but you can set onClickListener for any view in layout that passed to RemoteViews. Just do like this:

RemoteViews remoteViews = new RemoteViews(widgetPackage, R.layout.widget);
Intent action = new Intent(context, Your_cancel_broadcast.class);
action.setAction(CANCEL_BROADCAST_ACTION);
actionPendingIntent = PendingIntent.getBroadcast(context, 0, action, 0);
remoteViews.setOnClickPendingIntent(R.id.your_x_btn, actionPendingIntent);

and create broadcast, that receives CANCEL_BROADCAST_ACTION and stops what you want, and cancel this notification.

Also, I think (according to the documentation) that your method is deprecated.

You should use sth like:

Notification.Builder builder = new Notification.Builder(context);
builder.setContentTitle("Your notification title");
builder.setContentText("Your notification text");
builder.setSmallIcon(R.drawable.ic_your_icon);
builder.setContentIntent(yourIntent);
notificationManager.notify(null, YOUR_UNIQUE_NOTIFICATION_ID, builder.getNotification());

http://developer.android.com/reference/android/app/NotificationManager.html

http://developer.android.com/reference/android/app/Notification.Builder.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!