开发者

Android Intent-Filter for Multi Screen

I want to launch my application from web browser in Android using Intent-Filter based on scheme, host in the DATA tag like this.

    <activity android:name=".activity.LogoActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".activity.phone.MainActivityPhone" android:configChanges="orientation|keyboard"
         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="my" android:host="mystore" />
        </intent-filter>
    </activity>

    <activity android:name=".activity.tablet.MainActivityTablet"  android:configChanges="orientation|keyboard"
         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="my"开发者_StackOverflow android:host="mystore" />     
        </intent-filter>
    </activity>

As you see, There are two Main Activities for phone and tablet, and in LogoActivity determine which Main Activity will be opened by screen size. But the problem is when user clicks my://mystore link in web browser, there are two choices to launch that MainActivtyPhone and MainActivityTablet.

What I want is there is only one proper intent-filter works for uri my://mystore . Any help? Thanks.


On the first run of your application, use PackageManager to disable the activity you do not want to use.

Please do not invent custom schemes. Please use HTTP URLs instead:

<data android:scheme="http" android:host="yourdomain.com" android:path="/something/or/another" />

That way, you can actually put a real Web page at http://yourdomain.com/something/or/another, so if somebody gets your link but does not have your app installed, they will see your Web page, instead of getting an error.

Also, please remove android:configChanges, or handle all configuration changes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜