Android APP间相互调用的方式一记

ComponetName方式

以甲方App调用乙方App为例

甲方如下操作:

Intent intent = new Intent();
ComponentName componentName = new ComponentName(pkg, cls);// 参数pkg与cls
intent.setComponent(componentName);
context.startActivity(intent);

参数pkg、cls分别是乙方的包名与类名(包含package路径),其中需要对类配置如下:

android:exported="true"

                
                

如此才能打开相应的类,并将参数传递到该类对象中。

URL Scheme方式

以甲方App调用乙方App为例

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("schemename://hostname:8080/releativepath?params=10011002"));
startActivity(intent);

同样,乙方的manifest文件中,要对响应类进行配置,如下:

 
     

     
     
     
 

以上参数要相互对应,比如scheme、host,

scheme是必须要写的,其他的host、path,可以省略不配置。

Scheme方式同样支持在网页上访问App,比如通过超链接的方式,具体如下:

打开什么呢?

你可能感兴趣的:(笔记)