Android如何做到应用程序图标隐藏,由第三方程序启动

在你App的AndroidManifest.xml中,将启动页做如下修改

<intent-filter>
     <action android:name="android.intent.action.MAIN" />
     <category android:name="android.intent.category.DEFAULT"/>
  </intent-filter>

在第三方程序中如下调用

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.test.app",
           "com.test.app.MainActivity"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

其中com.test.app为应用程序包名,而com.test.app.MainActivity为你所要启动的第一个Activity,即上面所指的启动页

如果你不知道启动页,或者你的启动页会变化,那么你也可以如下调用

public boolean startApp(String packageName) {
          Intent intent = new Intent(Intent.ACTION_MAIN, null);
          intent.addCategory(Intent.CATEGORY_DEFAULT);
          PackageManager pm = getPackageManager();
          List<ResolveInfo> listInfos = pm.queryIntentActivities(intent, 0);
          String className = null;
          for (ResolveInfo info : listInfos) {
           if (packageName.equals(info.activityInfo.packageName)) {
            className = info.activityInfo.name;
            break;
           }
          }
          if (className != null && className.length() > 0) {
           intent.setComponent(new ComponentName(packageName, className));
           intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
             | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
           startActivity(intent);
           return true;
          }
          return false;
         }

 

转载于:https://www.cnblogs.com/wenhui92/p/6246043.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值