简体   繁体   English

Android以编程方式启动程序包

[英]Android launch package programmatically

I got list of packaged from tablet(Samsung galaxy tab 2). 我从平板电脑获得了包装清单(三星银河标签2)。 I am trying to launch them using this. 我正在尝试使用它来启动它们。 "url" being package name like com.sec.android.app.camera “ url”是软件包名称,例如com.sec.android.app.camera

PackageManager pm = getPackageManager(); Intent intent = pm.getLaunchIntentForPackage(url); startActivity(intent);

It's working for certain packages only. 它仅适用于某些软件包。 Camera, browser works but digital clock and whole lot doesn't launch. 相机,浏览器都可以使用,但是数字时钟和全部时钟无法启动。 why ? 为什么呢?

MY GOAL IS TO LAUNCH "TASK MANAGER" OR "ACTIVE TASKS". 我的目标是启动“任务管理器”或“活动任务”。 IS THIS POSSIBLE? 这可能吗? ALSO I AM NOT ABLE TO FIND PACKAGE NAME FOR THAT. 我也无法为此找到包装名称。

THANKS, 谢谢,

I use the following bit to launch all the apps installed on my device one after another. 我使用以下代码来依次启动设备上安装的所有应用程序。 Some of the apps on android have the same package name and do not return the meta information unless you request it. android上的某些应用程序具有相同的程序包名称,除非您请求,否则不会返回信息。

public void onStart() {
    super.onStart();
    final PackageManager pm = getPackageManager();
    //get a list of installed applications.
    List<ApplicationInfo> packages = pm
                    .getInstalledApplications(PackageManager.GET_META_DATA);
          for (ApplicationInfo packageInfo : packages) {
              Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(packageInfo.packageName);

             if(LaunchIntent != null) {
               startActivity( LaunchIntent );
             }
          }
  }

Here's a way to get list of running apps : 这是获取正在运行的应用程序列表的方法:

ActivityManager actvityManager = (ActivityManager)
this.getSystemService( ACTIVITY_SERVICE );
List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM