ste*_*pic 8 settings service notifications android
我正在使用此代码打开通知侦听器设置:
startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
Run Code Online (Sandbox Code Playgroud)
我想检查用户是否已授予我的应用程序授权.我已经尝试检查我的NotificationListenerService是否正在运行,但它似乎被系统暂停并重新启动(即使我返回START_STICKY).
ACh*_*hep 22
唯一正确的方法是检查安全设置:
ComponentName cn = new ComponentName(context, YourNotificationListenerService.class);
String flat = Settings.Secure.getString(context.getContentResolver(), "enabled_notification_listeners");
final boolean enabled = flat != null && flat.contains(cn.flattenToString());
Run Code Online (Sandbox Code Playgroud)
我错了,检查服务是否正在运行:
private boolean isNLServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (NLService.class.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
如果您使用的是 androidx,则可以使用
NotificationManagerCompat.getEnabledListenerPackages(Context context)
Run Code Online (Sandbox Code Playgroud)
检查您的侦听器是否已启用。 来源
| 归档时间: |
|
| 查看次数: |
5178 次 |
| 最近记录: |