Search code examples
androidservicebroadcastreceiverandroid-manifestintentfilter

intent-filter for a service : using a custom mime type


I want to add a custom mime so that my Android Service or a BroadcastReceiver would detect my custom files. I have seen answers to questions like How to add custom mime type? and How to add custom mime type?

The answers here are shown for an Activity. But what modifications are required for service or BroadcastReceiver? I tried the same code for them, but it did not work. I am new to android development. Some nice and detailed explanation is welcome. Is it possible? Where am I going wrong.

The code that I used is :

   <service android:name="XcardReceivedService"
        android:exported="true"
        android:enabled="true">


           <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="file" />
                    <data android:mimeType="*/*" />
                    <data android:pathPattern=".*\\.Xcard" />
                    <data android:host="*" />
</intent-filter>


      </service>

Solution

  • but before the activity is started I want to add the data from that file to the database

    You have to do that in the activity.

    or that purpose I wanted to write a service or a broadcast receiver.

    Files do not open in to a service or a broadcast receiver.

    Is there any other possible way?

    Put your code into your activity.

    how should i differentiate between "how the activity was started" whether from other activity or when user clicked on this file.

    Examine the Intent that was used to start your activity. You get this Intent via getIntent(). You can call getData() on the Intent to get the Uri associated with it. If this is not null, it should be the path to your file.