aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/activity
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2014-04-24 20:08:52 +0200
committerArne Schwabe <arne@rfc2549.org>2014-05-18 21:56:43 +0200
commita0825983139c99a9799503cafdf0dd0e3ce54a2f (patch)
treeb018b9f0c42add75593656f90648a319aa98a8db /main/src/cgeo/geocaching/activity
parent916992dc8398db364927a50a8ceb46f3053fce96 (diff)
downloadcgeo-a0825983139c99a9799503cafdf0dd0e3ce54a2f.zip
cgeo-a0825983139c99a9799503cafdf0dd0e3ce54a2f.tar.gz
cgeo-a0825983139c99a9799503cafdf0dd0e3ce54a2f.tar.bz2
Implement Android Beam (NFC Sharing) for cgeo
To support direct opening of CGEO on the other device, introduce a distinction between getBrowserURL and getCgeoURL in providers.
Diffstat (limited to 'main/src/cgeo/geocaching/activity')
-rw-r--r--main/src/cgeo/geocaching/activity/AbstractActivity.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/activity/AbstractActivity.java b/main/src/cgeo/geocaching/activity/AbstractActivity.java
index 42eb825..a18f32c 100644
--- a/main/src/cgeo/geocaching/activity/AbstractActivity.java
+++ b/main/src/cgeo/geocaching/activity/AbstractActivity.java
@@ -16,8 +16,14 @@ import org.apache.commons.lang3.StringUtils;
import rx.Subscription;
import rx.subscriptions.Subscriptions;
+import android.annotation.TargetApi;
import android.content.Intent;
import android.content.res.Resources;
+import android.nfc.NdefMessage;
+import android.nfc.NdefRecord;
+import android.nfc.NfcAdapter;
+import android.nfc.NfcEvent;
+import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.ContextMenu;
@@ -198,4 +204,34 @@ public abstract class AbstractActivity extends ActionBarActivity implements IAbs
return false;
}
}
+
+ // Do not support older devices than Android 4.0
+ // Although there even are 2.3 devices (Nexus S)
+ // these are so few that we don't want to deal with the older (non Android Beam) API
+
+ public interface ActivitySharingInterface {
+ /** Return an URL that represent the current activity for sharing */
+ public String getUri();
+ }
+
+ protected void initializeAndroidBeam(ActivitySharingInterface sharingInterface) {
+ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH)
+ initializeICSAndroidBeam(sharingInterface);
+ }
+
+ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
+ protected void initializeICSAndroidBeam(final ActivitySharingInterface sharingInterface) {
+ NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
+ if (nfcAdapter == null) {
+ return;
+ }
+ nfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {
+ @Override
+ public NdefMessage createNdefMessage(NfcEvent event) {
+ NdefRecord record = NdefRecord.createUri(sharingInterface.getUri());
+ return new NdefMessage(new NdefRecord[]{record});
+ }
+ }, this);
+
+ }
}