1. 程式人生 > >Android呼叫第三方app(Scheme隱式以及顯示呼叫)

Android呼叫第三方app(Scheme隱式以及顯示呼叫)

一、隱式呼叫

1.第三方app:manifest中配置能接受Scheme方式啟動的

<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE"

/>
        <data
android:host="test"
android:scheme="app"
/>
    </intent-filter>
</activity>

2. 自己app呼叫

Uri uri=Uri.parse("app://test");   //   app://test" 相當於 http://www.baidu.com
 Intent intent=new Intent(Intent.ACTION_VIEW,uri);
 startActivity(intent);

二、顯示呼叫

1.第三方app:manifest中設定exported = ‘true’

<activity android:name=".WelcomeActivity"
android:exported="true"
>
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

</activity>

3. 自己app呼叫

Intent intent =

new Intent();
intent.setAction(Intent.ACTION_MAIN);
//前提:知道要跳轉應用的包名、類名
String packageName = "com.wpl.csdemo";
String className = "com.wpl.csdemo.WelcomeActivity";
ComponentName componentName = new ComponentName(packageName, className);
intent.setComponent(componentName);
startActivity(intent);

注意:這兩種方式的設定只是針對某個頁面,都只是在自己應用中跳轉第三方應用,並不是真正的喚醒,比如應用A已經在後臺存在了,應用B呼叫以上兩種方式後,只是在應用B中重新打開了一個應用A,此時的應用A是相當與存在兩個,一個是在後臺單獨存在,一個是依存應用B存在,是新增到應用B的棧中的。

真正意義的喚醒app,實現ios scheme相同效果:https://blog.csdn.net/Silence_Sep/article/details/80527472