当前位置:   article > 正文

android 一个app启动另一个App的几种方法_启动别的应用 android

启动别的应用 android

先判断是否安装

  1. /**
  2. * 应用是否安装
  3. */
  4. public static boolean isAppInstalled(String packageName) {
  5. return new File("/data/data/" + packageName).exists();
  6. }

第一种方法:

以包名方法进入:

  1. Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.ok.o");
  2. startActivity(LaunchIntent);

第二种:

自定义action

这种方法没有测试

  1. Intent intent = new Intent();
  2. intent.setAction("com.joyodream.jiji.main");
  3. startActivity(intent);
  4. <intent-filter>
  5. <action android:name="com.ok.o" /><category android:name="android.intent.category.DEFAULT" /></intent-filter>

第三种通过scheme

  1. Intent intent = new Intent();
  2. intent.setData(Uri.parse("com.ok.o://......"));
  3. startActivity(intent);
  4. //com.ok.o相当于网址的http
  5. //下面的是另一个App的main入口下定义协议
  6. <intent-filter>
  7. <action android:name="android.intent.action.VIEW" />
  8. <category android:name="android.intent.category.DEFAULT" />
  9. <data android:scheme="com.ok.o" />
  10. </intent-filter>


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/144675
推荐阅读