aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schink <xmpp-dev@marcschink.de>2017-12-10 12:36:21 +0100
committerAndroid Development <you@example.com>2017-12-10 14:59:42 +0100
commite7ae9b5ec0371468ff0c40ce7c2d98dbe7db63df (patch)
tree424298c4c284204f566a727fb227d6bdd4971a9c
parent3c6024276355a85d88b0ff56d74506a4ee2bc856 (diff)
Handle NFC action in UriHandlerActivityuri_message3
-rw-r--r--src/main/AndroidManifest.xml20
-rw-r--r--src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java31
-rw-r--r--src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java37
3 files changed, 43 insertions, 45 deletions
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index 8677eff..07055fc 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -69,14 +69,6 @@
<data android:scheme="xmpp" />
</intent-filter>
- <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 android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
@@ -88,20 +80,20 @@
<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" />
+ <action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="imto" />
<data android:host="jabber" />
</intent-filter>
-
+ </activity>
+ <activity
+ android:name=".ui.StartConversationActivity"
+ android:label="@string/title_activity_start_conversation"
+ android:launchMode="singleTop">
</activity>
<activity
android:name=".ui.WelcomeActivity"
diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
index ec3dd34..e74d993 100644
--- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
@@ -2,7 +2,6 @@ package eu.siacs.conversations.ui;
import android.Manifest;
import android.annotation.SuppressLint;
-import android.annotation.TargetApi;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
@@ -20,12 +19,8 @@ import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
-import android.nfc.NdefMessage;
-import android.nfc.NdefRecord;
-import android.nfc.NfcAdapter;
import android.os.Build;
import android.os.Bundle;
-import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.Editable;
@@ -807,11 +802,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
setIntent(null);
}
- @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
- Invite getInviteJellyBean(NdefRecord record) {
- return new Invite(record.toUri());
- }
-
protected boolean handleIntent(Intent intent) {
if (intent == null || intent.getAction() == null) {
return false;
@@ -827,27 +817,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} else {
return false;
}
- case NfcAdapter.ACTION_NDEF_DISCOVERED:
- for (Parcelable message : getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)) {
- if (message instanceof NdefMessage) {
- for (NdefRecord record : ((NdefMessage) message).getRecords()) {
- switch (record.getTnf()) {
- case NdefRecord.TNF_WELL_KNOWN:
- if (Arrays.equals(record.getType(), NdefRecord.RTD_URI)) {
- if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- return getInviteJellyBean(record).invite();
- } else {
- byte[] payload = record.getPayload();
- if (payload[0] == 0) {
- return new Invite(Uri.parse(new String(Arrays.copyOfRange(
- payload, 1, payload.length)))).invite();
- }
- }
- }
- }
- }
- }
- }
}
return false;
}
diff --git a/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java b/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java
index cb1b659..2b81bfb 100644
--- a/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java
@@ -1,8 +1,14 @@
package eu.siacs.conversations.ui;
+import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
+import android.nfc.NdefMessage;
+import android.nfc.NdefRecord;
+import android.nfc.NfcAdapter;
+import android.os.Build;
+import android.os.Parcelable;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
@@ -26,6 +32,11 @@ public class UriHandlerActivity extends Activity {
handleIntent(intent);
}
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
+ Uri getInviteJellyBean(NdefRecord record) {
+ return record.toUri();
+ }
+
private void handleUri(Uri uri) {
final Intent intent;
final XmppUri xmppUri = new XmppUri(uri);
@@ -53,6 +64,30 @@ public class UriHandlerActivity extends Activity {
startActivity(intent);
}
+ private void handleNfcIntent(Intent data) {
+ for (Parcelable message : data.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)) {
+ if (message instanceof NdefMessage) {
+ for (NdefRecord record : ((NdefMessage) message).getRecords()) {
+ switch (record.getTnf()) {
+ case NdefRecord.TNF_WELL_KNOWN:
+ if (Arrays.equals(record.getType(), NdefRecord.RTD_URI)) {
+ if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ handleUri(getInviteJellyBean(record));
+ } else {
+ byte[] payload = record.getPayload();
+ if (payload[0] == 0) {
+ Uri uri = Uri.parse(new String(Arrays.copyOfRange(
+ payload, 1, payload.length)));
+ handleUri(uri);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
private void handleIntent(Intent data) {
if (data == null) {
finish();
@@ -67,6 +102,8 @@ public class UriHandlerActivity extends Activity {
case ACTION_SCAN_QR_CODE:
new IntentIntegrator(this).initiateScan(Arrays.asList("AZTEC", "QR_CODE"));
return;
+ case NfcAdapter.ACTION_NDEF_DISCOVERED:
+ handleNfcIntent(data);
}
finish();