summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartijn Coenen <maco@google.com>2012-05-23 17:34:06 -0700
committerMartijn Coenen <maco@google.com>2012-05-25 11:25:46 -0700
commit4fe787c0237d00e96018ac2185961451c6d4851d (patch)
treecb44cb3edcb7624ba4d1b759f5ebd7a9e2de81cc /src
parenta3715d12aeba988c1104726e935462ea4f39eca7 (diff)
downloadpackages_apps_nfc-4fe787c0237d00e96018ac2185961451c6d4851d.zip
packages_apps_nfc-4fe787c0237d00e96018ac2185961451c6d4851d.tar.gz
packages_apps_nfc-4fe787c0237d00e96018ac2185961451c6d4851d.tar.bz2
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
Diffstat (limited to 'src')
-rw-r--r--src/com/android/nfc/handover/BluetoothOppHandover.java23
-rw-r--r--src/com/android/nfc/handover/HandoverManager.java21
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;
}