1

当单击浏览器中的 Web 链接时,我想启动我自己的应用程序。我在网上搜索了很多,解决这个问题的方法是相似的。但是我的不行。当我点击网页链接时没有任何效果 还有其他一些我没有注意到的事情吗?谁能告诉我我的申请哪里错了?谢谢

这是我的程序:

链接是:谷歌

URLApp.java:

public class URLApp extends Activity {
/** Called when the activity is first created. */

public void OnCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);

    final Intent intent = getIntent();
    final Uri uri = intent.getData();

    Log.i("++++++++++++++++++++++", uri.getScheme().toString());
}
}

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.receiver"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".URLApp"
        android:label="@string/app_name" 
        android:launchMode="singleTask">
        <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>
            <data android:host="www.google.com"></data>
        </intent-filter>   
    </activity>
</application>
</manifest>

编辑:在我定义了自己的 URL 方案后,程序就可以工作了。我自己的网页链接是

<a href="myapp://test">click me!</a>
<data android:scheme="myapp"></data>

为什么使用 android:scheme="http" 不起作用有没有人有同样的问题?

4

1 回答 1

0
<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:host="www.YOUR-URL-HERE.com" android:scheme="http"></data>
</intent-filter>

也许您可以删除android:host标签以对所有网址做出反应。

另请参阅: Android 响应意图中的 URL

于 2012-05-15T09:10:17.780 回答