Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fragments and intent filters

We all know how we can use intent-filters in our AndroidManifest.xml to declare capabilities of activities such as search, push, and so on. I currently use such an intent-filter to register a custom URL scheme in the following manner:

<activity android:name="NameOfActivity" >
    <intent-filter >
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWABLE" />
        <data
            android:host=""
            android:scheme="customscheme" />
    </intent-filter>
</activity>

This all worked very well until I decided to transform all my activities into fragments, as I needed to display the user interface in a different manner on tables. Now, on devices that are declared as large or greater, instead of switching between activities I have one activity that removes and adds new fragments as requested. This choice was taken as the left-hand side of the screen allways displays the same content, so instead of adding this content ito all activities I instead change the fragments.

The problem here is that while the intent-filter launches the correct activity on the phone, this activity should never be launched on a tablet. Instead, I would like to handle this URL in the fragment. As of now, I see no way of fixing this. One thought was to add the intent-filter programmatically, but after some research i cannot figure out if this is possible or not. Another thought was to somehow add the intent-filter on the fragment, but this would not work as a fragment cannot launch without an activity hosting it.

In short: On a phone, I need one activity to handle the intent-filter, but on a tablet I need another activity to handle the intent-filter.

Is there any way of accomplishing this?

like image 816
Bendik Avatar asked Nov 04 '22 11:11

Bendik


1 Answers

Wouldn't it be possible to have your intent-filter activity determine the resolution of the device, then start the appropriate activity for that?

Also, I thought Fragments were designed with your case in mind: describe aspects of the user interface and then depending on screen resolution show either all or some of that functionality.

http://developer.android.com/guide/topics/fundamentals/fragments.html

like image 76
skynet Avatar answered Nov 13 '22 20:11

skynet