方式一(通过Intent唤起):

我们自己的app代码:

ComponentName componetName = new ComponentName(                               "com.lh.jimtrency.webviewdemo","com.lh.jimtrency.webviewdemo.MainActivity"); //(另外一个应用程序的包名,要启动的Activity )  Bundle bundle = new Bundle();  ArrayList strings=new ArrayList<>();  strings.add("18883250894");  strings.add("浮夸的小白菜");  bundle.putStringArrayList("userInfo", strings);  Intent intent = new Intent();  intent.putExtras(bundle);  intent.setComponent(componetName);  startActivity(intent);

PS:com.lh.jimtrency.webviewdemo 为对方的包名
com.lh.jimtrency.webviewdemo.MainActivity 为对方的MainActivity类

上面的代码就是唤起了对方App的MainActivity类,那对方还需要怎么配置呢?其实,只需要在AndroidManifest.xml中,对的MainActivity配置时,加上这个属性(exported):

  

对方怎么接受呢?

Bundle bundle=getIntent().getExtras();if (bundle!=null){       Toast.makeText(this,    bundle.getStringArrayList("userInfo").toString()   ,Toast.LENGTH_SHORT).show();}

方式二(通过Uri唤起app):

其实也很简单,就是换了一种方式而已。但,读者,一定要对uri格式有一定连接才行(uri格式详解:http://blog.csdn.net/harvic880925/article/details/44679239)。

下面看看,我们端app的代码怎么写:

Uri uri = Uri.parse("jimtrency://user.uri.activity?password=1");Intent intent = new Intent("android.jimtrency.schemeurl.activity");intent.setData(uri);startActivity(intent);

PS: “android.jimtrency.schemeurl.activity” 为跳转时的action

“jimtrency” 为Uri的scheme

“user.uri.activity” 为authority

对方 app怎么接受呢?

    Intent intent = getIntent();    if (null != intent) {        Uri uri = intent.getData();        if (uri == null) {            return;        }        String acionData = uri.getQueryParameter("password");        Toast.makeText(this,acionData,Toast.LENGTH_SHORT).show();    }

对方app的AndroidManifest.xml的配置

            

特别强调:

uri跳转时 ,action 配置 和 category 配置,一定不能缺。category 配置是固定的。如下:

   

方法三(简单粗暴:直接通过包名唤起app):

PackageManager packageManager = getPackageManager();Intent intent=new Intent();intent = packageManager.getLaunchIntentForPackage("com.cmcc.jzfpb");startActivity(intent);

那要是没有对应的app怎么办?其实,你可以打卡对应的下载页面就行.

Intent view = new Intent ("android.intent.action.VIEW",Uri.parse(""));startActivity(viewIntent);

更多相关文章

  1. Android Native C 之 Helloworld的四种编译方式
  2. 使用Git下载Google Android源代码
  3. Android中用代码设置ImageView的src和background
  4. Android 退出提示框 代码
  5. Android输入框格式化Edittexthelp(有项目可下载)
  6. 我的Android进阶之旅------>android api的源代码下载地址
  7. 简单几段代码实现窗口抖动
  8. android camera2 image 中获得的yuv数据的格式转换
  9. android之按钮单击事件及监听器的实现方式

随机推荐

  1. 模板字面量、标签函数、解构赋值与对象字
  2. PHP与JS数据遍历
  3. PHP基础学习与软件搭建
  4. 作业标题:0802-php是什么及运行原理 编程
  5. 【前端 · 面试 】HTTP 总结(二)—— HTTP
  6. 记一下网站被攻击经历
  7. 字符串 和数组的方法 以及js 的分支 和
  8. php遍历与js遍历区别
  9. PHP数组遍历与Javascript数组遍历的区别
  10. 07-12 作业