diff options
author | Martijn Coenen <maco@google.com> | 2012-05-25 15:40:49 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2012-05-25 15:40:49 -0700 |
commit | fadd67f16ce9baafc23e8aa521530e7d59f53543 (patch) | |
tree | aec75c65387603b2829014c0ac811bc204db0a43 /src/com | |
parent | f2509ed17251d2707e6c3b803df3b37ff76174f4 (diff) | |
parent | 62a8997361a059183f2547365a6055db3d45e9c9 (diff) | |
download | packages_apps_nfc-fadd67f16ce9baafc23e8aa521530e7d59f53543.zip packages_apps_nfc-fadd67f16ce9baafc23e8aa521530e7d59f53543.tar.gz packages_apps_nfc-fadd67f16ce9baafc23e8aa521530e7d59f53543.tar.bz2 |
am 62a89973: am d0387061: Merge "Use new handover intent actions." into jb-dev
* commit '62a8997361a059183f2547365a6055db3d45e9c9':
Use new handover intent actions.
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/nfc/handover/BluetoothOppHandover.java | 23 | ||||
-rw-r--r-- | src/com/android/nfc/handover/HandoverManager.java | 21 |
2 files changed, 26 insertions, 18 deletions
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<Uri> uris = new ArrayList<Uri>(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; } |