美文网首页
三种方式A程序跳到B程序

三种方式A程序跳到B程序

作者: SlideException | 来源:发表于2018-09-12 19:43 被阅读0次

A跳到B

//判断B程序是否存在 

public static boolean isInstall(Context context, String packageName) {

if (packageName ==null ||"".equals(packageName))

return false;

    try {

ApplicationInfo info = context.getPackageManager().getApplicationInfo(

packageName, PackageManager.GET_UNINSTALLED_PACKAGES);

return true;

    }catch (PackageManager.NameNotFoundException e) {

return false;

    }

}

if (isInstall(MainActivity.this, "B程序包名")) {

1、Intent intent =new Intent();

    intent.setClassName("B程序包名", "要跳到B程序的那个activity全包名");

    Bundle bundle =new Bundle();

    bundle.putString("zrl", id_et.getText().toString());

    intent.putExtras(bundle);

    startActivity(intent);

              2、      Intent intent = getPackageManager().getLaunchIntentForPackage("B程序包名");

                    startActivity(intent);


            3、        Intent intent = new Intent(Intent.ACTION_MAIN);

                    intent.addCategory(Intent.CATEGORY_LAUNCHER);

                    ComponentName cn = new ComponentName("B程序包名", "要跳到B程序的那个activity全包名");

                    intent.setComponent(cn);

                    startActivity(intent);

}else {

Toast.makeText(MainActivity.this, "没有这个App", Toast.LENGTH_LONG).show();

}

相关文章

网友评论

      本文标题:三种方式A程序跳到B程序

      本文链接:https://www.haomeiwen.com/subject/evybgftx.html