I have an app that is devided in Frontend and Backend. (little like MVC). My app uses a special url scheme like "testscheme". When the user clicks on a testscheme:// Link I want to inform the backend and the backend should set the internal state and launch an matching activity.
Intercepting links from the browser to open my Android app
and
How to implement my very own URI scheme on Android cover part of my problem but not quite.
They both point me to add a <intent-filter>
to the <activity>
I want to react to the scheme. But at this point I don't know what Activity to start and even if I would format my urls in a way that this would be unique I want to save the internal state before starting the Activity.
My first try was using a broadcastReciever with the very same <intent-filter>
but this did not work.
This is the relevant part of my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testurls"
android:versionCode="2"
android:versionName="0.1" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<receiver android:name=".backend.BackendController" >
<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="testurls" />
</intent-filter>
</receiver>
</application>
</manifest>
And this is the part of my receiver
package com.example.testurls.backend;
public class BackendController extends BroadcastReceiver implements BackendControllerInterface, GameStateLoadedListener, UrlsLoadedListener {
@Override
public void onReceive(Context context, Intent intent) {
Uri data = intent.getData();
if(data.getHost()=="maillink"){
this.proceedlevel();
this.frontend.MailReturned();
}else if(data.getHost()=="level1finished"){
this.proceedlevel();
this.frontend.level1Finished();
}
}
}