我正在尝试实现在Android 4.3中添加的NotificationListnerService,但我无法获取通知详细信息.
我的代码如下
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
mBuilder.setSmallIcon(R.drawable.ic_launcher);
mBuilder.setContentTitle("notification test");
mBuilder.setContentText("Notification text");
mBuilder.setAutoCancel(true);
Intent resultIntent = new Intent(this, ResultActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(ResultActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(1, …Run Code Online (Sandbox Code Playgroud) 我正在尝试用2个按钮发出通知:
有没有人知道如何捕捉按钮点击事件(请记住活动暂停)?
自从在Android上出现单挑通知以来,一些人喜欢它的快速处理,但有些人讨厌它在应用程序(尤其是游戏)之上展示.
为了显示单挑通知,开发人员可以使用类似的东西:
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setContentTitle("aa").setContentText("bb").setTicker("cc")
.setColor(0xffff0000).setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setPriority(Notification.PRIORITY_HIGH);
if (Build.VERSION.SDK_INT >= 21)
builder.setVibrate(new long[0]);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, builder.build());
Run Code Online (Sandbox Code Playgroud)
因此,一些应用程序提出了显示以某种方式替换它们的自动收录器文本通知的想法,就像在单挑通知之前一样:
https://play.google.com/store/apps/details?id=com.jamworks.noheadsup&hl=en
有各种可能有用的情况.例如,对于使用全屏的游戏,它可能是有用的.这是因为如果用户要按顶部区域并显示抬头通知,我们希望避免意外点击此通知.
不仅我找不到人们如何做到这一点的方式,但它似乎不再适用于Android的新版本(在Android 7上测试).
我发现阻止通知的唯一应用是:https: //play.google.com/store/apps/details?id = com.aboutmycode.NotificationsOff&hl = zh-CN
但它不会将抬头通知转换为"正常"通知.相反,它只是阻止它们.此外,它需要root,似乎只是将通知的设置更改为"已阻止".
是否可以临时阻止抬头通知(并将其转换为没有抬头通知的那些)?如果是这样,怎么样?
它有哪些限制?没有root可以工作吗?如果有可能与root,怎么样?"NotificationsOff"如何运作?
也许这种能力以前是可能的,但现在不是吗?
我有一个运行后台服务来获取数据.我检查新数据并发送状态栏通知.发送通知是服务的一部分.当用户看到该通知时,他登录到应用程序并接受它.那个时候我想从状态栏中删除它.我能这样做吗?
您好我正在开发一个应用程序,我想在Sms收到时向用户发送推送通知.现在的问题是当用户通过启动器图标打开应用程序时,通知图标仍然无法删除这是我的代码:
NotificationCompat.Builder notify = new NotificationCompat.Builder(context);
notify.setSmallIcon(R.drawable.appicon);
notify.setContentTitle(title);
notify.setContentText(msgBody);
notify.setAutoCancel(true);
Notification notification = new Notification();
notification.defaults |= Notification.DEFAULT_VIBRATE;
//notify.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
notify.setLights(Color.GREEN, 2000, 2000);
notify.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
Intent notificationIntent = new Intent(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_DEFAULT);
notificationIntent.setType("vnd.android-dir/mms-sms");
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intentt = PendingIntent.getActivity(context, 0,notificationIntent, 0);
notify.setContentIntent(intentt);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notify.build());
Run Code Online (Sandbox Code Playgroud)
我也是这样试过的:
notificationManager.cancel(0);
Run Code Online (Sandbox Code Playgroud)
并试过这个:
notificationManager.cancelAll();
Run Code Online (Sandbox Code Playgroud)
但这两个都行不通.它们不允许发生通知.也许他们在创建之前取消了推送通知.请帮忙!