【问题标题】:How to open MIUI system Activity programmatically in Android如何在Android中以编程方式打开MIUI系统Activity
【发布时间】:2017-12-21 15:19:24
【问题描述】:

是否可以在 Android 中以编程方式打开上述页面?

【问题讨论】:

    标签: android android-activity


    【解决方案1】:

    MIUI 10.

    对于当前应用:

    try {
        Intent intent = new Intent();
        intent.setClassName("com.miui.powerkeeper",
        "com.miui.powerkeeper.ui.HiddenAppsConfigActivity");
        intent.putExtra("package_name", getPackageName());
        intent.putExtra("package_label", getText(R.string.app_name));
        startActivity(intent);
    } catch (ActivityNotFoundException anfe) {
    }
    

    【讨论】:

      【解决方案2】:

      据我所知,没有隐含的Intent 可以打开这个Activity

      要弄清楚如何明确执行此操作,请在您的设备上打开此菜单时查看 Logcat 输出以了解发生了什么。该流应该在某个时候由ActivityManager 处理,因此您可以对其进行过滤。

      您应该在日志中查找类似的内容:

      I/ActivityManager: 启动 u0 {cmp=com.miui.powerkeeper/.ui.PowerHideModeActivity} 从 uid 1000 开始 显示 0

      获取此信息后,您只需创建一个适当的Intent,这样您就可以自己启动相同的Activity

      try {
          Intent intent = new Intent();
          intent.setClassName("com.miui.powerkeeper",
              "com.miui.powerkeeper.ui.PowerHideModeActivity");
      
          startActivity(intent);
      } catch (ActivityNotFoundException anfe) {
          // this is not an MIUI device, or the component got moved/renamed
      }
      

      附带说明,您不应该像这样以显式方式打开操作系统组件。每当他们更改此组件的类名或包时,您的代码就会中断。

      【讨论】:

      • 如果我要打开OPPO设备的活动怎么办?
      • @ShaifaliPundir 基本上和这里一样。在 Oppo 设备上打开 Activity 并检查 Logcat 输出。从日志中,您应该能够找出系统打开的组件。然后为同一个组件创建一个显式的Intent(如上所示)。
      【解决方案3】:

      您可以在小米手机(MIUI)上使用跳转到应用详情活动

          Intent intent = new Intent(); 
          intent.setClassName("com.miui.securitycenter", "com.miui.appmanager.ApplicationsDetailsActivity");
          intent.putExtra("package_name", packageName);
          intent.putExtra("package_label", "Dev Tools");
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          context.startActivity(intent);
      

      这是由开发工具应用程序使用的,https://play.google.com/store/apps/details?id=cn.trinea.android.developertools

      【讨论】:

        猜你喜欢
        • 2018-05-16
        • 1970-01-01
        • 2016-02-22
        • 1970-01-01
        • 2015-04-23
        • 1970-01-01
        • 2019-05-02
        • 2010-10-30
        • 1970-01-01
        相关资源
        最近更新 更多