android - 无法以编程方式在 Gionee A1 中打开静音模式
问题描述
嘿,我正在使用下面的代码将设备变成静音模式。
public static void setDeviceOnSilent(Context context) {
AudioManager audioManager = (AudioManager) context.getSystemService(AUDIO_SERVICE);
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
上面的代码在除金立 A1之外的所有设备上都能正常工作。请建议我已经授予NotificationAccessPolicyEnabled权限的问题是什么。下面是代码。
public static boolean isNotificationAccessPolicyEnabled(Context context) {
NotificationManager notificationManager;
notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
&& !notificationManager.isNotificationPolicyAccessGranted()) {
Intent intent = new Intent(
android.provider.Settings
.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
context.startActivity(intent);
return false;
}
return true;
}
解决方案
代码看起来还不错。检查清单以获得必要的权限。
推荐阅读
- pymc3 - pymc3: Beta Distribution sd vs sigma
- c - 关于 malloc 的 valgrind 错误:它们是什么意思?
- c# - Web API 2:如何声明可以在控制器中访问的 global-per-user 变量?
- python - 为 numpy.array 定义 dtype 时字符串变为空
- firebase - 从匿名火力基地覆盖用户,但不会刷新屏幕颤动
- python - Combining repeating date/value pairs into single date/value pair
- python - 使用线程更新 Tkinter GUI
- html - 如何填补这两个 td 之间的空白?
- wordpress - 在 wordpress 中读取外部文本文件
- grpc - gRPC 异步流式客户端仅处理第一条消息(c++)