所以我做了一个很好的网页浏览应用程序,它运行得很好。当我启动我的应用程序时,链接在我的应用程序中打开,一切都进行得很顺利。但是,当我单击应用程序外部的链接(例如在短信中)时,Android 会询问我选择哪个浏览器打开我的链接,而我的未列出。我试图让我的应用程序能够打开外部链接并处理它们。
谢谢你的帮助!
编辑:已解决
我找到了让它工作的方法。这是我的AndroidManifest.xml的片段
<activity
android:name=".MainActivity"
<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" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
</activity>
这是我如何检索和使用通过链接启动我的应用程序的意图:
主活动.java
@Override
protected void onCreate(Bundle savedInstanceState) {
//...
Uri startIntentData = getIntent().getData();
if(startIntentData!=null) {
String intentUrl = startIntentData.toString();
if(intentUrl.contains("http://")||intentUrl.contains("https://")) { // checking if the intent's data was meant to be a url
addTab(intentUrl); // a method that handle opening urls by calling webView.loadUrl(String url)
}
}
我不知道这是最安全还是最有效的方式,但至少它有效!
我不知道如何让我的应用成为我的默认浏览器
你没有。该用户可以选择将您的应用是默认的浏览器。只需<activity>
使用适当的<intent-filter>
,设置一个以查看ACTION_VIEW
Intents
您支持的任何方案和 MIME 类型。Android 和用户将从那里获取它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句