Android 一个app启动另一个app

来源:互联网 发布:mac柔感哑光唇膏15 编辑:程序博客网 时间:2024/04/29 07:17

第一个App中

[java] view plaincopy在CODE上查看代码片派生到我的代码片
  1. // 通过包名获取要跳转的app,创建intent对象  
  2.                 Intent intent = activity().getPackageManager()  
  3.                         .getLaunchIntentForPackage("com.zsl.download");  
  4.                 // 这里如果intent为空,就说名没有安装要跳转的应用嘛  
  5.                 if (intent != null) {  
  6.                     // 这里跟Activity传递参数一样的嘛,不要担心怎么传递参数,还有接收参数也是跟Activity和Activity传参数一样  
  7.                     intent.putExtra("name""郑松岚");  
  8.                     startActivity(intent);  
  9.                 } else {  
  10.                     // 没有安装要跳转的app应用,提醒一下  
  11.                     ToastUtils.showLongToast(activity(), "没安装此APP");  
  12.                 }  

第二个App中

[java] view plaincopy在CODE上查看代码片派生到我的代码片
  1. Intent intent = getIntent();  
  2.         Bundle bundle = intent.getExtras();  
  3.         if (bundle != null) {  
  4.             String name = bundle.getString("name");  
  5.             if (name != null) {  
  6.                 Toast.makeText(getApplicationContext(), "name:" + name, Toast.LENGTH_SHORT).show();  
  7.             }  
  8.         }  
0 0
原创粉丝点击