如何调用Android的Digital Wellbeing及专注模式Intent?
调用Digital Wellbeing与专注模式的Intent解决方案
启动Digital Wellbeing主界面
如果Settings.ACTION_DIGITAL_WELLBEING_SETTINGS无法生效,建议使用显式Intent直接指定Digital Wellbeing应用的组件,这种方式在不同设备上兼容性更强:
Intent digitalWellbeingIntent = new Intent(); // 指定Google原生Digital Wellbeing的组件信息 digitalWellbeingIntent.setComponent(new ComponentName( "com.google.android.apps.wellbeing", "com.google.android.apps.wellbeing.ui.MainActivity" )); try { startActivity(digitalWellbeingIntent); } catch (ActivityNotFoundException e) { // 处理设备未安装Digital Wellbeing或组件不存在的情况 e.printStackTrace(); }
注:国内定制ROM可能有自研的数字健康应用,需要替换对应的包名和类名(比如小米、华为等厂商的专属组件)。
直接启动专注模式界面
方式1:隐式Intent(Android 10+)
Android 10及以上系统提供了专注模式的隐式Intent Action:
Intent focusModeIntent = new Intent(Settings.ACTION_FOCUS_MODE_SETTINGS); try { startActivity(focusModeIntent); } catch (ActivityNotFoundException e) { // 隐式Intent失效时, fallback到显式Intent launchFocusModeExplicitly(); }
方式2:显式Intent(兼容性更强)
如果隐式Intent无法触发,直接指定专注模式的Activity组件:
private void launchFocusModeExplicitly() { Intent focusModeIntent = new Intent(); focusModeIntent.setComponent(new ComponentName( "com.google.android.apps.wellbeing", "com.google.android.apps.wellbeing.focusmode.ui.FocusModeSettingsActivity" )); try { startActivity(focusModeIntent); } catch (Exception e) { e.printStackTrace(); } }
关键注意事项
- 确保设备已安装Digital Wellbeing应用,部分定制ROM可能未预装,需引导用户手动安装
- 不同厂商的定制系统可能修改了组件路径,需针对特定品牌做适配
- 必须捕获
ActivityNotFoundException,避免因组件不存在导致应用崩溃
内容的提问来源于stack exchange,提问作者Saeed Kiyanzadeh
相关产品推荐
相关产品推荐

