summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/gallery3d/app/PhotoPage.java26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java
index ea7e83982..29211ffee 100644
--- a/src/com/android/gallery3d/app/PhotoPage.java
+++ b/src/com/android/gallery3d/app/PhotoPage.java
@@ -26,6 +26,8 @@ import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.net.Uri;
import android.nfc.NfcAdapter;
+import android.nfc.NfcAdapter.CreateBeamUrisCallback;
+import android.nfc.NfcEvent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -163,7 +165,7 @@ public class PhotoPage extends ActivityState implements
private Path mDeletePath;
private boolean mDeleteIsFocus; // whether the deleted item was in focus
- private NfcAdapter mNfcAdapter;
+ private Uri[] mNfcPushUris = new Uri[1];
private final MyMenuVisibilityListener mMenuVisibilityListener =
new MyMenuVisibilityListener();
@@ -292,7 +294,7 @@ public class PhotoPage extends ActivityState implements
mSetPathString = data.getString(KEY_MEDIA_SET_PATH);
mOriginalSetPathString = mSetPathString;
- mNfcAdapter = NfcAdapter.getDefaultAdapter(mActivity.getAndroidContext());
+ setupNfcBeamPush();
String itemPathString = data.getString(KEY_MEDIA_ITEM_PATH);
Path itemPath = itemPathString != null ?
Path.fromString(data.getString(KEY_MEDIA_ITEM_PATH)) :
@@ -461,12 +463,24 @@ public class PhotoPage extends ActivityState implements
}
@TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN)
- private void setNfcBeamPushUris(Uri[] uris) {
- if (mNfcAdapter != null && ApiHelper.HAS_SET_BEAM_PUSH_URIS) {
- mNfcAdapter.setBeamPushUris(uris, mActivity);
+ private void setupNfcBeamPush() {
+ if (!ApiHelper.HAS_SET_BEAM_PUSH_URIS) return;
+
+ NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mActivity);
+ if (adapter != null) {
+ adapter.setBeamPushUrisCallback(new CreateBeamUrisCallback() {
+ @Override
+ public Uri[] createBeamUris(NfcEvent event) {
+ return mNfcPushUris;
+ }
+ }, mActivity);
}
}
+ private void setNfcBeamPushUri(Uri uri) {
+ mNfcPushUris[0] = uri;
+ }
+
private Intent createShareIntent(Path path) {
DataManager manager = mActivity.getDataManager();
int type = manager.getMediaType(path);
@@ -499,7 +513,7 @@ public class PhotoPage extends ActivityState implements
DataManager manager = mActivity.getDataManager();
Uri uri = manager.getContentUri(path);
mActionBar.setShareIntent(createShareIntent(path));
- setNfcBeamPushUris(new Uri[]{uri});
+ setNfcBeamPushUri(uri);
}
private void updateCurrentPhoto(MediaItem photo) {