开发者

intent filter for ical URLs

I'm trying to register my Android app as a handler for iCal URLs. To do this I set intent filters in my Manifest for the webcal:// pseudo protocol and for HTTP URLs using the text/calendar MIME type (see below).

This works perfectly fine in the emulator, but on a real device I'm having problems. The webcal:// filter works, but the text/calendar one doesn't. Instead the Browser displays the ical file as plain text instead of passing the URL to my app.

I checked that the browser isn't configured as a default handler for ical (in Settings->Applications->Browser) and I asked a few other people if they could reproduce the problem on their mobiles. All with the same result.

What's the correct way to register for text/calendar URLs?

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="org.splitbrain.giraffe"
  android:versionName="0.31" android:versionCode="4">
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.Light.NoTitleBar">
    <activity androi开发者_如何学JAVAd:label="@string/app_name" android:name="MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <category android:name="android.intent.category.BROWSABLE"></category>
            <action android:name="android.intent.action.VIEW"></action>
            <data android:mimeType="text/calendar" android:scheme="http"></data>
            <category android:name="android.intent.category.DEFAULT"></category>
        </intent-filter>
        <intent-filter>
            <category android:name="android.intent.category.BROWSABLE"></category>
            <action android:name="android.intent.action.VIEW"></action>
            <data android:scheme="webcal"></data>
            <category android:name="android.intent.category.DEFAULT"></category>
        </intent-filter>
    </activity>
    <activity android:name="OptionsActivity"></activity>
    <activity android:name="DetailActivity"></activity>
    <activity android:name="AboutActivity"></activity>

</application>
</manifest>

Update: Turns out the above works fine in the Android 1.6 emulator, but not on a 2.3.3 emulator where it shows the same behavior as on my phone. Is this a bug in Android maybe?


I opened a bug report at https://code.google.com/p/android/issues/detail?id=18796


Just use the DEFAULT category, the BROWSABLE category is might be causing the problem.

Add a .*.ics path pattern to capture any files that have been given the wrong mime type by the server

Put all the data matching into the same filter

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="org.splitbrain.giraffe"
  android:versionName="0.31" android:versionCode="4">
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.Light.NoTitleBar">
    <activity android:label="@string/app_name" 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" />
            <data android:mimeType="text/calendar" />
            <data android:scheme="webcal" />
            <data android:pathPattern=".*.ics" />
        </intent-filter>
    </activity>
    <activity android:name="OptionsActivity"></activity>
    <activity android:name="DetailActivity"></activity>
    <activity android:name="AboutActivity"></activity>

</application>
</manifest>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜