如題,android 4.1以上可以關閉應用通知按鈕,app開發時想獲取到是否被關閉,有沒有辦法代碼實作。
uj5u.com熱心網友回復:
樓主解決了嗎uj5u.com熱心網友回復:
同問!!
uj5u.com熱心網友回復:
INotificationManager nm = INotificationManager.Stub.asInterface(
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
boolean enabled = true; // default on
try {
enabled = nm.areNotificationsEnabledForPackage(mAppEntry.info.packageName);
} catch (android.os.RemoteException ex) {
// this does not bode well
}
uj5u.com熱心網友回復:
可以通過反射來呼叫uj5u.com熱心網友回復:
樓上方法貌似找不到類啊。INotificationManager,難道你說的反射就是反這個?不知道版本支持是多少?uj5u.com熱心網友回復:
該怎么使用啊,送佛送到西,給全啊,謝啦uj5u.com熱心網友回復:
http://blog.csdn.net/zcllige/article/details/52444258 看看這個文章uj5u.com熱心網友回復:
可以參考下這個https://www.jianshu.com/p/28b8c0391c8dpublic static boolean isEnableV26(Context context, String pkg, int uid) {
try {
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Method sServiceField = notificationManager.getClass().getDeclaredMethod("getService");
sServiceField.setAccessible(true);
Object sService = sServiceField.invoke(notificationManager);
Method method = sService.getClass().getDeclaredMethod("areNotificationsEnabledForPackage"
, String.class, Integer.TYPE);
method.setAccessible(true);
return (boolean) method.invoke(sService, pkg, uid);
} catch (Exception e) {
return true;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/72526.html
標籤:Android
