有没有办法检查Android中是否以编程方式启用或禁用了以下设置?
Settings > Security > Device Administration > Notification Access > My App
目前我通过以下方法从我的应用调用设置对话框,但如果设置已经启用,那么我不想提供此设置。
Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
startActivity(intent);
答案 0 :(得分:14)
简单
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"));
}
'其他'根据您的问题,部分是可选的
答案 1 :(得分:2)
要判断Android设置通知是否包含您的应用,您应该执行以下操作:
import android.provider.Settings;
String enabledAppList = Settings.Secure.getString(
this.getContentResolver(), "enabled_notification_listeners");
boolean temp = enabledAppList.contains("youAppName");
答案 2 :(得分:0)
将状态保存在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;
}