Android 從外部網頁拉起跳轉到App
業務場景
當需要從外部第三方網頁中通過點選某個連結或按鈕啟動App應用程式。
實現
- 新建demo工程,並實現一個Activity,用來接收從外部跳轉傳入的資訊。程式碼如下:
public class MainActivity extends Activity {
private TextView tv_content;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv_content = (TextView)findViewById(R.id.tv_content);
Intent intent = getIntent();
if (intent != null){
Uri uri = intent.getData();
if (uri != null){
String dataString = intent.getDataString();
String scheme = uri.getScheme();
String host = uri.getHost();
String query = uri.getQuery();
tv_content.setText("dataString = " + dataString + " | scheme = " + scheme + " | host = " + host + " | query = " + query);
}
}
}
- 修改AndroidManifest檔案,設定Activity的接收Action的屬性:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:scheme="ice"
android:host="start.app"/>
</intent-filter>
</activity>
</application>
如上所示,在data裡設定了 scheme和host,則該Activity可以接收和處理類似於 “ice://start.app/XXX”的連結。
- 接下來 就是要模擬一個第三方網頁環境用於啟動我們的app應用,我們可以新建一個包含WebView的工程2,用webview載入我們的測試html,html網頁程式碼如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>title</title>
</head>
<body>
<a href="ice://start.app/test?type=1&value=2">開啟app</a><br/>
</body>
</html>
- 執行工程2,效果如下:
點選連結“開啟app”,會啟動demo應用,且demo應用接收到了網頁傳過來的引數資訊,效果如下:
相關文章
- Android 外部URL跳轉到APP的操作AndroidAPP
- Android 外部喚起應用跳轉指定頁面Android
- 新浪微博app如何去喚起跳轉微信小程式APP微信小程式
- Android 網頁開啟App進入對應頁面Android網頁APP
- Android應用中,跳轉到App的詳細設定頁面,設定許可權頁面AndroidAPP
- 網頁外部注入vConsole除錯網頁除錯
- 案例分享,Appium+Python實現APP啟動頁跳轉到首頁APPPython
- Android跳轉到應用商店的APP詳情頁面,以及 Google GMS 各個apk的包AndroidAPPGoAPK
- 教你如何在快應用中跳轉到Android的appAndroidAPP
- 網頁渲染方式-從靜態頁面到服務端渲染網頁服務端
- Android 從 Web 喚起 APPAndroidWebAPP
- 你的網頁有多快 — 從 DOMReady 到 Element Timing網頁
- 從列表頁跳轉到詳情頁,返回列表頁時列表頁與之前的狀態相同
- React Native 跳轉到 APP 推送頁面並獲取推送狀態React NativeAPP
- 網頁開發方式-從靜態頁面到服務端渲染網頁服務端
- APP 開發從 0 到 1(二)框架與網路APP框架
- Android 外部儲存Android
- 微信跳轉外部瀏覽器下載app詳解瀏覽器APP
- android app 啟動第一個頁面AndroidAPP
- 用weexplus從0到1寫一個app(2)-頁面跳轉和文章列表及文章詳情的編寫APP
- 從輸入url到顯示網頁發生了什麼網頁
- TCP/IP--圖解從URL到網頁通訊原理TCP圖解網頁
- 404頁面自動跳轉到首頁
- Android 安卓從1.0到11.0總結(跟隨Android官網實時更新)Android安卓
- 網址連結跳轉外部安全提醒程式碼
- 一個APP從啟動到主頁面顯示經歷了哪些過程?APP
- 使用Chrome開發者工具除錯Android端內網頁(微信,QQ,UC,App內嵌頁等)Chrome除錯Android內網網頁APP
- Android Jetpack - 使用 Navigation 管理頁面跳轉AndroidJetpackNavigation
- 問題解決:下載的網頁開啟後自動跳轉到首頁網頁
- Flutter實戰 | 從 0 搭建「網易雲音樂」APP(二、Splash Page、登入頁、發現頁)FlutterAPP
- Android輪播圖從0到1Android
- Android DataBinding 從入門到進階Android
- 爬蟲工作原理詳解:從網頁請求到資料提取爬蟲網頁
- 用weexplus從0到1寫一個app(1)-環境搭建和首頁編寫APP
- js頁面跳轉的問題(跳轉到父頁面、最外層頁面、本頁面)JS
- 【UniApp】-uni-app-打包成網頁APP網頁
- Flutter Webview網頁與App通訊FlutterWebView網頁APP
- Python從入門到轉行Python
- 從 Godaddy 轉移域名到 NamesiloGo