Add Android Beam (NFC) support

This commit is contained in:
fkloft
2014-01-26 14:35:12 +01:00
parent 6b7525836d
commit 23a092f187
4 changed files with 54 additions and 1 deletions

View File

@ -16,6 +16,7 @@
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.NFC"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application

View File

@ -227,4 +227,9 @@ public class IITC_JSInterface {
public String getFileRequestUrlPrefix() {
return mIitc.getFileManager().getFileRequestPrefix();
}
@JavascriptInterface
public void setPermalink(final String href) {
mIitc.setPermalink(href);
}
}

View File

@ -14,6 +14,10 @@ import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.res.Configuration;
import android.net.Uri;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.NfcEvent;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
@ -44,7 +48,8 @@ import java.net.URISyntaxException;
import java.util.Stack;
import java.util.Vector;
public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeListener {
public class IITC_Mobile extends Activity
implements OnSharedPreferenceChangeListener, NfcAdapter.CreateNdefMessageCallback {
private static final String mIntelUrl = "https://www.ingress.com/intel";
private SharedPreferences mSharedPrefs;
@ -68,6 +73,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
private boolean mIsLoading = true;
private boolean mShowMapInDebug = false;
private final Stack<String> mDialogStack = new Stack<String>();
private String mPermalink = null;
// Used for custom back stack handling
private final Stack<Pane> mBackStack = new Stack<IITC_NavigationHelper.Pane>();
@ -142,6 +148,9 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
// afterwards install iitc update
registerReceiver(mBroadcastReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
final NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
nfc.setNdefPushMessageCallback(this, this);
handleIntent(getIntent(), true);
}
@ -777,4 +786,19 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
public interface ResponseHandler {
void onActivityResult(int resultCode, Intent data);
}
public void setPermalink(final String href) {
mPermalink = href;
}
@Override
public NdefMessage createNdefMessage(final NfcEvent event) {
if (mPermalink == null) { // no permalink yet, just provide AAR
return new NdefMessage(NdefRecord.createApplicationRecord(getPackageName()));
}
return new NdefMessage(
NdefRecord.createUri(mPermalink),
NdefRecord.createApplicationRecord(getPackageName()));
}
}