From 4fe787c0237d00e96018ac2185961451c6d4851d Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Wed, 23 May 2012 17:34:06 -0700 Subject: Use new handover intent actions. Use the new handover intent actions that allow us to select any mime-type. Also, add unique filename counter before extension instead of after it. Bug: 6561169 Change-Id: I04b83460099b42ba6220d7eb4dcff7a095022304 --- .../android/nfc/handover/BluetoothOppHandover.java | 23 ++++++++++------------ src/com/android/nfc/handover/HandoverManager.java | 21 +++++++++++++++----- 2 files changed, 26 insertions(+), 18 deletions(-) (limited to 'src/com') diff --git a/src/com/android/nfc/handover/BluetoothOppHandover.java b/src/com/android/nfc/handover/BluetoothOppHandover.java index 3180e83..ece6a7b 100644 --- a/src/com/android/nfc/handover/BluetoothOppHandover.java +++ b/src/com/android/nfc/handover/BluetoothOppHandover.java @@ -35,8 +35,11 @@ public class BluetoothOppHandover implements Handler.Callback { static final int REMOTE_BT_ENABLE_DELAY_MS = 3000; - public static final String EXTRA_CONNECTION_HANDOVER = - "com.android.intent.extra.CONNECTION_HANDOVER"; + static final String ACTION_HANDOVER_SEND = + "android.btopp.intent.action.HANDOVER_SEND"; + + static final String ACTION_HANDOVER_SEND_MULTIPLE = + "android.btopp.intent.action.HANDOVER_SEND_MULTIPLE"; final Context mContext; final BluetoothDevice mDevice; @@ -115,28 +118,22 @@ public class BluetoothOppHandover implements Handler.Callback { } void sendIntent() { - //TODO: either open up BluetoothOppLauncherActivity to all MIME types - // or gracefully handle mime types that can't be sent Intent intent = new Intent(); intent.setPackage("com.android.bluetooth"); String mimeType = getMimeTypeForUri(mContext, mUris[0]); intent.setType(mimeType); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); if (mUris.length == 1) { - intent.setAction(Intent.ACTION_SEND); + intent.setAction(ACTION_HANDOVER_SEND); intent.putExtra(Intent.EXTRA_STREAM, mUris[0]); } else { ArrayList uris = new ArrayList(Arrays.asList(mUris)); - intent.setAction(Intent.ACTION_SEND_MULTIPLE); + intent.setAction(ACTION_HANDOVER_SEND_MULTIPLE); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); } - intent.putExtra(EXTRA_CONNECTION_HANDOVER, true); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - try { - mContext.startActivity(intent); - } catch (ActivityNotFoundException e) { - Log.e(TAG, "Failed to handover file to bluetooth, mimeType not allowed."); - } + + mContext.sendBroadcast(intent); + complete(); } diff --git a/src/com/android/nfc/handover/HandoverManager.java b/src/com/android/nfc/handover/HandoverManager.java index f229b65..12bf863 100644 --- a/src/com/android/nfc/handover/HandoverManager.java +++ b/src/com/android/nfc/handover/HandoverManager.java @@ -54,6 +54,7 @@ import android.os.Message; import android.os.SystemClock; import android.util.Log; import android.util.Pair; + import com.android.nfc.NfcService; import com.android.nfc.R; @@ -449,7 +450,7 @@ public class HandoverManager implements BluetoothProfile.ServiceListener, File srcFile = new File(uri.getPath()); - File dstFile = generateUniqueDestination(beamPath + "/" + + File dstFile = generateUniqueDestination(beamPath.getAbsolutePath(), uri.getLastPathSegment()); if (!srcFile.renameTo(dstFile)) { if (DBG) Log.d(TAG, "Failed to rename from " + srcFile + " to " + dstFile); @@ -546,14 +547,24 @@ public class HandoverManager implements BluetoothProfile.ServiceListener, return pi; } - synchronized File generateUniqueDestination(String baseFileName) { - File dstFile = new File(baseFileName); + synchronized File generateUniqueDestination(String path, String fileName) { + int dotIndex = fileName.lastIndexOf("."); + String extension = null; + String fileNameWithoutExtension = null; + if (dotIndex < 0) { + extension = ""; + fileNameWithoutExtension = fileName; + } else { + extension = fileName.substring(dotIndex); + fileNameWithoutExtension = fileName.substring(0, dotIndex); + } + File dstFile = new File(path + File.separator + fileName); int count = 0; while (dstFile.exists()) { - dstFile = new File(baseFileName + "-" + Integer.toString(count)); + dstFile = new File(path + File.separator + fileNameWithoutExtension + "-" + + Integer.toString(count) + extension); count++; } - return dstFile; } -- cgit v1.1