Home > Mobile >  Notice the state of the switch for android applications
Notice the state of the switch for android applications

Time:09-24

As title, android 4.1 above inform button can turn off the application, app development for whether to shut down, is there any way to code implementation,

CodePudding user response:

The building Lord solved

CodePudding user response:

With q!!!!!

CodePudding user response:

 INotificationManager nm=INotificationManager. Stub. AsInterface (
ServiceManager. GetService (Context. NOTIFICATION_SERVICE));
Boolean enabled=true;//the default on
Try {
Enabled=nm. AreNotificationsEnabledForPackage (mAppEntry. Info. PackageName);
} the catch (android OS. RemoteException ex) {
//this does not bode well
}

CodePudding user response:

Can be invoked through reflection

CodePudding user response:

Upstairs method seems can't find the class INotificationManager, reflection is against this don't you say? Don't know how version support is?

CodePudding user response:

How to use ah, send Buddha to the west, to the whole, thanks

CodePudding user response:

Take a look at this article http://blog.csdn.net/zcllige/article/details/52444258

CodePudding user response:

You can refer to this https://www.jianshu.com/p/28b8c0391c8d
Public static Boolean isEnableV26 (Context Context, String PKG, int uid) {
Try {
NotificationManager NotificationManager=(NotificationManager)
The context. GetSystemService (context. NOTIFICATION_SERVICE);
Method sServiceField=notificationManager. GetClass (). GetDeclaredMethod (" getService ");
SServiceField. SetAccessible (true);
The Object sService=sServiceField. Invoke (notificationManager);

Method Method=sService. GetClass (). GetDeclaredMethod (" areNotificationsEnabledForPackage
", the String class, Integer. TYPE);
Method. SetAccessible (true);
Return (Boolean) method. The invoke (sService and PKG, uid);
} the catch (Exception e) {
return true;
}
}
  • Related