日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

android app外唤起,Android 唤起app的多种方式

發(fā)布時間:2025/3/8 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android app外唤起,Android 唤起app的多种方式 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

方式一(通過Intent喚起):

我們自己的app代碼:

ComponentName componetName = new ComponentName(

"com.lh.jimtrency.webviewdemo",

"com.lh.jimtrency.webviewdemo.MainActivity");

//(另外一個應(yīng)用程序的包名,要啟動的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):

android:name=".MainActivity"

android:exported="true"/>

那對方怎么接受呢?

Bundle bundle=getIntent().getExtras();

if (bundle!=null){

Toast.makeText(this,

bundle.getStringArrayList("userInfo").toString()

,Toast.LENGTH_SHORT).show();

}

方式二(通過Uri喚起app):

其實也很簡單,就是換了一種方式而已。但,讀者,一定要對uri格式有一定連接才行(uri格式詳解:http://www.voidcn.com/article/p-tpjbxlwp-bae.html)。

下面看看,我們端app的代碼怎么寫:

Uri uri = Uri.parse("jimtrency://user.info.detail?password=1");

Intent intent = new Intent("android.jimtrency.schemeurl.activity");

intent.setData(uri);

startActivity(intent);

PS: “android.jimtrency.schemeurl.activity” 為跳轉(zhuǎn)時的action

“jimtrency” 為Uri的scheme

“user.info.detail” 為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的配置

android:name=".MainActivity">

android:scheme="jimtrency"

android:host="user.uri.activity" />

特別強調(diào):

uri跳轉(zhuǎn)時 ,action 配置 和 category 配置,一定不能缺。category 配置是固定的。如下:

方法三(簡單粗暴:直接通過包名喚起app):

PackageManager packageManager = getPackageManager();

Intent intent=new Intent();

intent = packageManager.getLaunchIntentForPackage("com.cmcc.jzfpb");

startActivity(intent);

那要是沒有對應(yīng)的app怎么辦?其實,你可以打卡對應(yīng)的下載頁面就行.

Intent view = new Intent

("android.intent.action.VIEW",Uri.parse(""));

startActivity(viewIntent);

總結(jié)

以上是生活随笔為你收集整理的android app外唤起,Android 唤起app的多种方式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。