Har*_*ish 6 settings notifications android system android-intent
有没有办法检查Android中是否以编程方式启用或禁用了以下设置?
Settings > Security > Device Administration > Notification Access > My App
Run Code Online (Sandbox Code Playgroud)
目前我正在通过以下方法从我的应用程序调用设置对话框,但如果设置已经启用,那么我不想提供此设置.
Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
Ash*_*ahu 15
简单一点
if (Settings.Secure.getString(this.getContentResolver(),"enabled_notification_listeners").contains(getApplicationContext().getPackageName()))
{
//service is enabled do something
} else {
//service is not enabled try to enabled by calling...
getApplicationContext().startActivity(new Intent(
"android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
}
Run Code Online (Sandbox Code Playgroud)
根据您的问题,'else'部分是可选的
将状态保存在 onBind() 和 onUnbind() 的静态变量中对我有用。
public boolean onUnbind(Intent mIntent) {
boolean mOnUnbind = super.onUnbind(mIntent);
Common.isNotificationAccessEnabled = false;
return mOnUnbind;
}
public IBinder onBind(Intent mIntent) {
IBinder mIBinder = super.onBind(mIntent);
Common.isNotificationAccessEnabled = true;
return mIBinder;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8359 次 |
| 最近记录: |