按钮通知被点击时关闭状态栏

编程入门 行业动态 更新时间:2024-10-25 20:19:30
本文介绍了按钮通知被点击时关闭状态栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我

如何关闭通知按钮后,状态栏中点击?

我想这个,但我有一个例外:

java.lang.NoSuchMethodException:崩溃[]    在java.lang.Class.getConstructorOrMethod(Class.java:460)    在java.lang.Class.getMethod(Class.java:915)    ...

我的code:

NotificationCompat.Builder建设者=新NotificationCompat.Builder(上下文)     .setSmallIcon(R.drawable.icon)     .setContentTitle(同步失败)     .setContentText(Lorem存有悲坐阿梅特)     .setStyle(新NotificationCompat.BigTextStyle()。bigText(Lorem存有悲坐阿梅特))     .addAction(R.drawable.change,更改通行证,pChangePass)     .addAction(R.drawable.remove,忽略,pIgnore)     .setAutoCancel(假); mNotificationManager.notify(accountUnique,builder.build());

目前NotificationIntent类

@覆盖 公共无效的onReceive(上下文的背景下,意图意图){     INT notificationID = intent.getExtras()调用getInt(NOT_ID)。     this.callbackContext = StatusBarNotification.getCallback();     this.mNotificationManager = StatusBarNotification.getNotificationManager();     this.mNotificationManager.cancel(notificationID);     this.callbackContext.success(returnJSON(意向)); }

解决方案

好吧,我解决了这个问题。

私人INT currentApiVersion = android.os.Build.VERSION.SDK_INT; ... 对象sbservice = context.getSystemService(状态栏); 尝试 {     类<> statusbarManager =的Class.forName(android.app.StatusBarManager);     如果(currentApiVersion< = 16){         方法塌陷= statusbarManager.getMethod(崩溃);         collapse.invoke(sbservice);     } 其他 {         方法collapse2 = statusbarManager.getMethod(collapsePanels);         collapse2.invoke(sbservice);     } }赶上(例外五){     e.printStackTrace(); }

How can I close status bar after notification button click?

I tried this, but I had an exception:

java.lang.NoSuchMethodException: collapse [] at java.lang.Class.getConstructorOrMethod(Class.java:460) at java.lang.Class.getMethod(Class.java:915) ...

My code:

NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.icon) .setContentTitle("Sync Failed") .setContentText("Lorem ipsum dolor sit amet") .setStyle(new NotificationCompat.BigTextStyle().bigText("Lorem ipsum dolor sit amet")) .addAction(R.drawable.change, "Change Pass", pChangePass) .addAction(R.drawable.remove, "Ignore", pIgnore) .setAutoCancel(false); mNotificationManager.notify(accountUnique, builder.build());

At NotificationIntent class

@Override public void onReceive(Context context, Intent intent) { int notificationID = intent.getExtras().getInt("NOT_ID"); this.callbackContext = StatusBarNotification.getCallback(); this.mNotificationManager = StatusBarNotification.getNotificationManager(); this.mNotificationManager.cancel(notificationID); this.callbackContext.success(returnJSON(intent)); }

解决方案

Ok, I solved it.

private int currentApiVersion = android.os.Build.VERSION.SDK_INT; ... Object sbservice = context.getSystemService("statusbar"); try { Class<?> statusbarManager = Class.forName("android.app.StatusBarManager"); if (currentApiVersion <= 16) { Method collapse = statusbarManager.getMethod("collapse"); collapse.invoke(sbservice); } else { Method collapse2 = statusbarManager.getMethod("collapsePanels"); collapse2.invoke(sbservice); } } catch (Exception e) { e.printStackTrace(); }

更多推荐

按钮通知被点击时关闭状态栏

本文发布于:2023-11-27 12:06:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638002.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:状态栏   按钮   通知

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!