Handle NFC action in UriHandlerActivity
This commit is contained in:
parent
d5f8a4dacb
commit
7dc68522a2
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
@ -806,11 +801,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;
|
||||
|
@ -826,27 +816,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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -27,6 +33,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);
|
||||
|
@ -62,6 +73,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();
|
||||
|
@ -76,6 +111,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();
|
||||
|
|
Loading…
Reference in a new issue