我想在浏览器中实现文件关联,比如在浏览器中打开一个zip文件的url,直接关联我的程序,而不是启动下载管理器。
阅读了android的开发文档,有关信息如下描述:
Consider, for example, what the browser application does when the user follows a link on a web page. It first tries to display the data (as it could if the link was to an HTML page). If it can't display the data, it puts together an implicit intent with the scheme and data type and tries to start an activity that can do the job. If there are no takers, it asks the download manager to download the data.我实现了一个demo,在附件中,代码如下, 按照文档描述,这段代码应该可以实现这个功能,可实际上,根本没起作用,有谁知道到底是什么原因,谢谢.Androidmanifest.xml<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.glority"
    android:versionCode="1"
    android:versionName="1.0" >    <uses-sdk android:minSdkVersion="10" />    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:debuggable="true" >
        <activity
            android:name=".Test001Activity"
            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" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:mimeType="*/*" />
            </intent-filter>            
        </activity>
    </application></manifest>
Test001Activity.java
public class Test001Activity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Intent intent = getIntent();
        String action = intent.getAction();
        if (intent.ACTION_VIEW.equals(action)) {
            Uri uri = (Uri) intent.getData();
        }
    }
}