![](/img/trans.png)
[英]Android open file from my application into suitable application installed error
[英]How to open installed android application via browser in android?
我想讓我的應用程序在用戶在瀏覽器中輸入特定的URL(例如chrome或internet)時打開。為此,我已經提及並用谷歌搜索了這個主題,我發現這是相似的,並且我在清單文件中使用過但仍然無法正常工作。 我已經在下面提到了我的問題的鏈接
從Android瀏覽器/ Chrome啟動自定義Android應用程序
所有這些都有相同的答案,但是當我使用它時,當我鍵入url www.myurl.co.gdf或http://www.myurl.co.gdf時,它沒有任何作用,它不會提示用戶在瀏覽器本身而不是瀏覽器中打開打開myapp或顯示選擇對話框
我在清單文件中使用的代碼如下
<application
android:icon="@drawable/logo"
android:label="@string/app" >
<activity
android:name="com.app.secondActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/service"
android:screenOrientation="portrait"
android:theme="@style/aa_theme" >
<intent-filter android:label="@string/app" >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data
android:host="www.myurl.co.gdf"
android:pathPrefix="/"
android:scheme="http" >
</data>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.VIEW" />
</intent-filter>
</activity>
<activity
android:name="com.app.firstActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/activity_title"
android:screenOrientation="portrait"
android:theme="@style/aa_theme" />
</application>
如果這對其他人有用,為什么對我不呢? 注意:我僅在清單中更改了以上代碼,並且沒有更改或添加任何.java文件或其他文件中的其他內容。
為此,我應該對設備設置進行任何更改,還是應該添加Uri intentUri = getIntent()。getData(); 在.java文件中(應該使用然后為什么?),或者我應該在瀏覽器中鍵入不同的內容?還是我在錯誤的活動中使用了intentfilter,或者我缺少什么?
我在此應用程序中使用了一些cordova插件,我認為這與打開應用程序無關。
我對android非常陌生,請給我一些有關此的想法。
問題不在於您的代碼,而在於您的測試策略。
在瀏覽器中鍵入URL通常不會啟動Intent
,因此Android不會檢查是否有其他應用程序可以處理該URL。 例如,當用戶在Chrome中輸入鏈接時,Chrome會假定該用戶希望繼續使用Chrome,並會處理對URL本身的瀏覽。
相反,您需要創建一個包含URL的意圖,以測試Android是否將正確處理到您應用程序的深層鏈接。
最簡單的方法是通過以下ADB命令:
adb shell am start
-W -a android.intent.action.VIEW
-d http://www.myurl.co.gdf/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.