如果你知道目标应用的包名和想打开的界面类名,那就很方便。

//这些代码是启动另外的一个应用程序的主Activity,当然也可以启动任意一个Activity        ComponentName componetName = new ComponentName(                  //这个是另外一个应用程序的包名                  "com.poynt.weibo",                  //这个参数是要启动的Activity                  "com.poynt.weibo.ui.IndexActivity");              try {                  Intent intent = new Intent();                  intent.setComponent(componetName);                  startActivity(intent);              } catch (Exception e) {  //              Toast.makeText(getApplicationContext(), "可以在这里提示用户没有找到应用程序,或者是做其他的操作!", 0).show();  

如果你不知道目标应用的界面类名,可以使用下面的方法,启动目标应用。

  /**  获取PackageManager对象 */     PackageManager packageManager = getPackageManager();        PackageInfo pi = null;        try {            pi = packageManager.getPackageInfo("com.welove520.welove", 0);        } catch (PackageManager.NameNotFoundException e) {        }        // 设置标签内需要满足的条件        Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);        resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);        resolveIntent.setPackage(pi.packageName);        // 通过queryIntentActivities获取ResolveInfo对象        List apps = packageManager.queryIntentActivities(resolveIntent, 0);        ResolveInfo ri = apps.iterator().next();        if (ri != null ) {            String className = ri.activityInfo.name;            Intent intent = new Intent();            ComponentName cn = new ComponentName("com.welove520.welove", className);            intent.setComponent(cn);            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);            Context context = getApplicationContext();            context.startActivity(intent);        }

更多相关文章

  1. Android(安卓)基础
  2. Android(安卓)WMS分析(一) WindowManager
  3. Android(安卓)5.0 SystemServer--->Android入口
  4. 【Android】Activity_习题
  5. Android应用启动优化:一种DelayLoad的实现和原理
  6. android之mainfest 参数解说
  7. Android(安卓)Framework初步认识
  8. android使用广播退出应用程序
  9. VLC for Android源码下载和编译

随机推荐

  1. Android(安卓)输入法键盘和activity页面
  2. Android(安卓)布局
  3. Android(安卓)Layout XML属性
  4. Android(安卓)Handler机制2--ThreadLocal
  5. [置顶] [Android基础]Android中SharedPrefe
  6. Android(安卓)Studio安装与配置
  7. android 使用Intent传递数据之返回结果
  8. 通过xml布局文件实现按钮改变焦点设置背
  9. Android(安卓)viewpager 实现画廊效果 左
  10. android:backgroundDimEnabled的作用