相关疑难解决方法(0)

如何在Android中清除通知

是否可以以编程方式清除通知?

我尝试了它NotificationManager但它不起作用.还有其他办法吗?

notifications android

94
推荐指数
8
解决办法
11万
查看次数

如何在android中添加通知按钮?

我的应用程序播放音乐,当用户通过从屏幕顶部(或平板电脑屏幕右下角的通用)打开通知屏幕时,我想向他们显示一个按钮,以停止当前播放的音乐并再次启动它他们要.

我不打算将小部件放在用户的主屏幕上,而只是放入通知中.我怎样才能做到这一点?

notifications android widget button

74
推荐指数
4
解决办法
7万
查看次数

事件OnClick用于自定义通知中的按钮

我有一个带按钮的自定义通知.要设置通知并使用事件OnClick on my button,我使用了以下代码:

//Notification and intent of the notification 
Notification notification = new Notification(R.drawable.stat_notify_missed_call,
            "Custom Notification", System.currentTimeMillis());

Intent mainIntent = new Intent(getBaseContext(), NotificationActivity.class);
PendingIntent pendingMainIntent = PendingIntent.getActivity(getBaseContext(),
    0, mainIntent , 0);
notification.contentIntent = pendingMainIntent;

//Remoteview and intent for my button
RemoteViews notificationView = new RemoteViews(getBaseContext().getPackageName(),
    R.layout.remote_view_layout);

Intent activityIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:190"));
PendingIntent pendingLaunchIntent = PendingIntent.getActivity(getBaseContext(), 0,
            activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);

notificationView.setOnClickPendingIntent(R.id.button1,
    pendingLaunchIntent);

notification.contentView = notificationView;

notificationManager.notify(CUSTOM_NOTIFICATION_ID, notification);
Run Code Online (Sandbox Code Playgroud)

使用此代码,我使用自定义布局自定义通知...但我无法单击按钮!每次我尝试单击按钮时,我都会单击整个通知,因此脚本会启动"mainIntent"而不是"activityIntent".

我在互联网上看到这段代码不适用于所有终端.我已经在模拟器和HTC Magic上尝试过但我总是遇到同样的问题:我无法点击按钮!

我的代码是对的?有人可以帮帮我吗?

谢谢,

西蒙娜

notifications android onclick button

27
推荐指数
2
解决办法
4万
查看次数

标签 统计

android ×3

notifications ×3

button ×2

onclick ×1

widget ×1