Implement simple URI handler activity

This commit is contained in:
Marc Schink 2017-12-07 21:59:13 +01:00
parent 9a796df2a3
commit b8b7cc2635
2 changed files with 56 additions and 11 deletions

View File

@ -58,17 +58,10 @@
</intent-filter>
</activity>
<activity
android:name=".ui.StartConversationActivity"
android:name=".ui.UriHandlerActivity"
android:label="@string/title_activity_start_conversation"
android:theme="@android:style/Theme.NoDisplay"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="imto" />
<data android:host="jabber" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
@ -78,11 +71,12 @@
<data android:scheme="xmpp" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="xmpp" />
<data android:scheme="imto" />
<data android:host="jabber" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
@ -95,6 +89,19 @@
<data android:pathPrefix="/i/" />
<data android:pathPrefix="/j/" />
</intent-filter>
</activity>
<activity
android:name=".ui.StartConversationActivity"
android:label="@string/title_activity_start_conversation"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="imto" />
<data android:host="jabber" />
</intent-filter>
</activity>
<activity

View File

@ -0,0 +1,38 @@
package eu.siacs.conversations.ui;
import android.app.Activity;
import android.content.Intent;
public class UriHandlerActivity extends Activity {
@Override
public void onStart() {
super.onStart();
handleIntent(getIntent());
}
@Override
public void onNewIntent(Intent intent) {
handleIntent(intent);
}
private void handleIntent(Intent data) {
if (data == null) {
finish();
return;
}
switch (data.getAction()) {
case Intent.ACTION_VIEW:
case Intent.ACTION_SENDTO:
final Intent intent = new Intent(getApplicationContext(),
StartConversationActivity.class);
intent.setAction(data.getAction());
intent.setData(data.getData());
intent.setAction(data.getAction());
startActivity(intent);
}
finish();
}
}