首页 > 系统 > Android > 正文

Android应用间跳转

2019-11-09 14:36:16
字体:
来源:转载
供稿:网友
/** * * @ClassName: MainActivity* @Description: 从一个应用跳转到另一个应用* @author guoyizhe* @email gyzboy@126.com* @date 2015-6-9 下午3:49:07* */public class MainActivity extends Activity {    PRivate Intent intent = null;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        //知道要跳转应用的包名、类名//        ComponentName comp = new ComponentName("com.gyz.mytextswitchertest", "com.gyz.mytextswitchertest.MainActivity");//        final Intent intent = new Intent();//        intent.setComponent(comp);//        intent.setAction("android.intent.action.VIEW");        //不知道类名        PackageManager pm = getPackageManager();        PackageInfo pi = null;        try {            pi = pm.getPackageInfo("com.gyz.mytextswitchertest", 0);        } catch (NameNotFoundException e) {            e.printStackTrace();        }                  Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);           resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);           resolveIntent.setPackage(pi.packageName);           //找到匹配intent的所有Activity,这个方法可以在intent跳转前调用用来检测是否有符合条件的activity          List<ResolveInfo> apps = pm.queryIntentActivities(resolveIntent, 0);          ResolveInfo ri = apps.iterator().next();           if (ri != null ) {               String className = ri.activityInfo.name;               intent = new Intent(Intent.ACTION_MAIN);               intent.addCategory(Intent.CATEGORY_LAUNCHER);               ComponentName cn = new ComponentName("com.gyz.mytextswitchertest", className);               intent.setComponent(cn);           }         Button button = (Button) findViewById(R.id.btn_jump);        button.setOnClickListener(new OnClickListener() {                        @Override            public void onClick(View v) {                startActivity(intent);            }        });    }}

原文地址:http://www.cnblogs.com/gyzboy/p/4563774.html


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表