Start an Android Service or an Android Broadcast Receiver using a custom URI scheme

902 views Asked by At

I would like to start an Android service using a URI scheme. Is this possible?

At the moment I have the following:

    <service android:name="com.domain.app.services.MyService" >
        <intent-filter>
            <data android:scheme="myapp1"/>
        </intent-filter>
    </service>
    <receiver android:name="com.domain.app.receivers.MyReceiver" >
        <intent-filter>
            <data android:scheme="myapp2"/>
        </intent-filter>
    </receiver>

But when I try to start it with a browser writting the cusom URI scheme (myapp1://hello or myapp2://hello) niether of them are started.

Does someone know how to do this?

1

There are 1 answers

3
ztan On

I think you have to use intent-filer with scheme to launch an application from browser. You can read this tutorial for more information about the implementation in manifest file. Or this answer.

Sample code:

<intent-filter>
   <data android:scheme="myapp1" />
   <action android:name="android.intent.action.VIEW" />
   <category android:name="android.intent.category.DEFAULT"/>
   <category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>

A broadcast receiver (short receiver) is an Android component which allows you to register for system or application events. All registered receivers for an event are notified by the Android runtime once this event happens.

So broadcast receiver is for system or application events, not for you to launch your application from browser. You can read this tutorial for more information about broadcast receiver in Android.