【发布时间】:2016-02-27 16:56:16
【问题描述】:
我是开发新手,对于我的第一个应用程序,我正在尝试制作一个网络浏览器。我的问题是我无法让我的 webview 从共享 Intent 加载 url。我得到的只是一个空白页。我花了几天时间在网上搜索,任何帮助将不胜感激。提前谢谢!
我获取意图的代码(在 oncreate 和 onresume 中)
Intent receivedIntent = getIntent();
String receivedAction = receivedIntent.getAction();
String receivedType = receivedIntent.getType();
try {
if (receivedAction.equals(Intent.ACTION_VIEW)) {
String receivedText = receivedIntent.getStringExtra(Intent.EXTRA_TEXT);
if (receivedText != null) {
if (receivedType.equals("text/plain")) {
webView.loadUrl(receivedText);
}
}
我的清单
<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.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
【问题讨论】:
-
您是否记录了 receivedText 以确保它是有效的 URL?
-
@chRyNaN 好主意!这是我的日志。
-
I/CLOCKS: CLOCKS Intent { act=android.intent.action.VIEW dat=cbc.ca/news/business/… I/CLOCKS: CLOCKS android.intent.action.VIEW I/CLOCKS: CLOCKS null
标签: android url android-intent webview shared