blob: 34de006d8a6180a859d0648af90bde66255a88f8 [file] [log] [blame]
Michael Kolb8233fac2010-10-26 16:08:53 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
Michael Kolb8233fac2010-10-26 16:08:53 -070018
19import android.app.Activity;
Ben Murdoche4c0cae2011-02-18 11:25:38 +000020import android.content.ActivityNotFoundException;
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -070021import android.content.ComponentName;
Vivek Sekharb54614f2014-05-01 19:03:37 -070022import android.content.ContentResolver;
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -070023import android.content.ContentUris;
24import android.content.Context;
Michael Kolb8233fac2010-10-26 16:08:53 -070025import android.content.Intent;
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -070026import android.content.pm.PackageManager;
27import android.content.pm.ResolveInfo;
28import android.content.pm.ActivityInfo;
kaiyiz4b59d262013-07-30 10:41:38 +080029import android.database.Cursor;
Michael Kolb8233fac2010-10-26 16:08:53 -070030import android.net.Uri;
31import android.os.Environment;
32import android.provider.MediaStore;
33import android.webkit.ValueCallback;
Vivek Sekharb54614f2014-05-01 19:03:37 -070034import android.util.Log;
Ben Murdoche4c0cae2011-02-18 11:25:38 +000035import android.widget.Toast;
Michael Kolb8233fac2010-10-26 16:08:53 -070036
Bijan Amirzada41242f22014-03-21 12:12:18 -070037import com.android.browser.R;
38import com.android.browser.reflect.ReflectHelper;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080039
Michael Kolb8233fac2010-10-26 16:08:53 -070040import java.io.File;
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -070041import java.util.ArrayList;
42import java.util.List;
Michael Kolb8233fac2010-10-26 16:08:53 -070043
44/**
45 * Handle the file upload callbacks from WebView here
46 */
47public class UploadHandler {
48
Vivek Sekharb54614f2014-05-01 19:03:37 -070049 private static final String TAG = "UploadHandler";
Michael Kolb8233fac2010-10-26 16:08:53 -070050 /*
51 * The Object used to inform the WebView of the file to upload.
52 */
53 private ValueCallback<Uri> mUploadMessage;
Vivek Sekharb54614f2014-05-01 19:03:37 -070054 private ValueCallback<String[]> mUploadFilePaths;
Michael Kolb8233fac2010-10-26 16:08:53 -070055 private String mCameraFilePath;
56
Ben Murdoch51f6a2f2011-02-21 12:27:07 +000057 private boolean mHandled;
58 private boolean mCaughtActivityNotFoundException;
59
Michael Kolb8233fac2010-10-26 16:08:53 -070060 private Controller mController;
61
62 public UploadHandler(Controller controller) {
63 mController = controller;
64 }
65
66 String getFilePath() {
67 return mCameraFilePath;
68 }
69
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -070070 protected boolean handled() {
Ben Murdoch51f6a2f2011-02-21 12:27:07 +000071 return mHandled;
72 }
73
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -070074 protected void setHandled(boolean handled) {
75 mHandled = handled;
76 mCaughtActivityNotFoundException = false;
77 if (!mHandled)
78 mUploadFilePaths.onReceiveValue(null);
79 }
Ben Murdoch51f6a2f2011-02-21 12:27:07 +000080
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -070081 void onResult(int resultCode, Intent intent) {
Ben Murdoch51f6a2f2011-02-21 12:27:07 +000082 if (resultCode == Activity.RESULT_CANCELED && mCaughtActivityNotFoundException) {
83 // Couldn't resolve an activity, we are going to try again so skip
84 // this result.
85 mCaughtActivityNotFoundException = false;
86 return;
87 }
88
Michael Kolb8233fac2010-10-26 16:08:53 -070089 Uri result = intent == null || resultCode != Activity.RESULT_OK ? null
90 : intent.getData();
91
92 // As we ask the camera to save the result of the user taking
93 // a picture, the camera application does not return anything other
94 // than RESULT_OK. So we need to check whether the file we expected
95 // was written to disk in the in the case that we
96 // did not get an intent returned but did get a RESULT_OK. If it was,
97 // we assume that this result has came back from the camera.
98 if (result == null && intent == null && resultCode == Activity.RESULT_OK) {
99 File cameraFile = new File(mCameraFilePath);
100 if (cameraFile.exists()) {
101 result = Uri.fromFile(cameraFile);
102 // Broadcast to the media scanner that we have a new photo
103 // so it will be added into the gallery for the user.
104 mController.getActivity().sendBroadcast(
105 new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, result));
106 }
107 }
108
Vivek Sekharb54614f2014-05-01 19:03:37 -0700109 // try to get local file path from uri
110 boolean hasGoodFilePath = false;
111 String filePath = null;
112 if (result != null) {
113 String scheme = result.getScheme();
114 if ("file".equals(scheme)) {
115 filePath = result.getPath();
116 hasGoodFilePath = filePath != null && !filePath.isEmpty();
117 } else if ("content".equals(scheme)) {
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700118 filePath = getFilePath(mController.getContext(), result);
119 hasGoodFilePath = filePath != null && !filePath.isEmpty();
Vivek Sekharb54614f2014-05-01 19:03:37 -0700120 }
121 }
122
123 // Add for carrier feature - prevent uploading DRM type files.
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700124 boolean drmUploadEnabled = mController.getContext().getResources().getBoolean(
125 R.bool.drm_uploads);
Vivek Sekharb54614f2014-05-01 19:03:37 -0700126 boolean isDRMFileType = false;
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700127 if (drmUploadEnabled && filePath != null
Vivek Sekharb54614f2014-05-01 19:03:37 -0700128 && (filePath.endsWith(".fl") || filePath.endsWith(".dm")
129 || filePath.endsWith(".dcf") || filePath.endsWith(".dr")
130 || filePath.endsWith(".dd"))) {
131 isDRMFileType = true;
132 Toast.makeText(mController.getContext(), R.string.drm_file_unsupported,
133 Toast.LENGTH_LONG).show();
134 }
135
136 if (mUploadMessage != null) {
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700137
Vivek Sekharb54614f2014-05-01 19:03:37 -0700138 if (!isDRMFileType) {
139 mUploadMessage.onReceiveValue(result);
140 } else {
141 mUploadMessage.onReceiveValue(null);
142 }
143 }
144
145 if (mUploadFilePaths != null) {
146 if (hasGoodFilePath && !isDRMFileType) {
147 Log.d(TAG, "upload file path:" + filePath);
148 mUploadFilePaths.onReceiveValue(new String[]{filePath});
149 } else {
150 mUploadFilePaths.onReceiveValue(null);
151 }
kaiyiz4b59d262013-07-30 10:41:38 +0800152 }
153
Ben Murdoch51f6a2f2011-02-21 12:27:07 +0000154 mHandled = true;
155 mCaughtActivityNotFoundException = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700156 }
157
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700158
159 public String getDocumentId(final Uri uri) {
160 String id = null;
161 try {
162 Object[] params = {(android.net.Uri)uri};
163 Class[] type = new Class[] {Class.forName("android.net.Uri") };
164 id = (String) ReflectHelper.invokeMethod(
165 "android.provider.DocumentsContract","getDocumentId",
166 type, params);
167
168 } catch(java.lang.ClassNotFoundException e) {
169
170 }
171 return id;
172 }
173
174
175 public String getFilePath(final Context context, final Uri uri) {
176 String id = getDocumentId(uri);
177
178 // DocumentProvider is new API exposed in Kitkat
179 // Its a way of exposing unified file explorer
180 if (id != null) {
181 // ExternalStorageProvider
182 if (isExternalStorageDocument(uri)) {
183 final String docId = id;
184 final String[] split = docId.split(":");
185 final String type = split[0];
186
187 if ("primary".equalsIgnoreCase(type)) {
188 return Environment.getExternalStorageDirectory() + "/" + split[1];
189 }
190 }
191 // DownloadsProvider
192 else if (isDownloadsDocument(uri)) {
193 final Uri contentUri = ContentUris.withAppendedId(
194 Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
195 return getDataColumn(context, contentUri, null, null);
196 }
197 // MediaProvider
198 else if (isMediaDocument(uri)) {
199 final String docId = id;
200 final String[] split = docId.split(":");
201 final String type = split[0];
202
203 Uri contentUri = null;
204 if ("image".equals(type)) {
205 contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
206 } else if ("video".equals(type)) {
207 contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
208 } else if ("audio".equals(type)) {
209 contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
210 }
211
212 final String selection = "_id=?";
213 final String[] selectionArgs = new String[] {
214 split[1]
215 };
216
217 return getDataColumn(context, contentUri, selection, selectionArgs);
218 }
219 }
220 // MediaStore (and general)
221 else if ("content".equalsIgnoreCase(uri.getScheme())) {
222 return getDataColumn(context, uri, null, null);
223 }
224
225 return null;
226 }
227
228 /**
229 * Get the value of the data column for this Uri. This is useful for
230 * MediaStore Uris, and other file-based ContentProviders.
231 * @return The value of the _data column, which is typically a file path.
232 */
233 private String getDataColumn(Context context, Uri uri, String selection,
234 String[] selectionArgs) {
235
236 Cursor cursor = null;
237 final String column = "_data";
238 final String[] projection = { column };
239
240 try {
241 cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
242 null);
243 if (cursor != null && cursor.moveToFirst()) {
244 final int column_index = cursor.getColumnIndexOrThrow(column);
245 return cursor.getString(column_index);
246 }
247 } finally {
248 if (cursor != null)
249 cursor.close();
250 }
251 return null;
252 }
253
254 /**
255 * @return Whether the Uri authority is ExternalStorageProvider.
256 */
257 private boolean isExternalStorageDocument(Uri uri) {
258 return "com.android.externalstorage.documents".equals(uri.getAuthority());
259 }
260
261 /**
262 * @return Whether the Uri authority is DownloadsProvider.
263 */
264 private boolean isDownloadsDocument(Uri uri) {
265 return "com.android.providers.downloads.documents".equals(uri.getAuthority());
266 }
267
268 /**
269 * @return Whether the Uri authority is MediaProvider.
270 */
271 public static boolean isMediaDocument(Uri uri) {
272 return "com.android.providers.media.documents".equals(uri.getAuthority());
273 }
274
275
Ben Murdoch8cad4132012-01-11 10:56:43 +0000276 void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700277
278 final String imageMimeType = "image/*";
279 final String videoMimeType = "video/*";
280 final String audioMimeType = "audio/*";
281 final String mediaSourceKey = "capture";
282 final String mediaSourceValueCamera = "camera";
283 final String mediaSourceValueFileSystem = "filesystem";
284 final String mediaSourceValueCamcorder = "camcorder";
285 final String mediaSourceValueMicrophone = "microphone";
286
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000287 // According to the spec, media source can be 'filesystem' or 'camera' or 'camcorder'
Ben Murdoch8cad4132012-01-11 10:56:43 +0000288 // or 'microphone' and the default value should be 'filesystem'.
289 String mediaSource = mediaSourceValueFileSystem;
Michael Kolb8233fac2010-10-26 16:08:53 -0700290
Michael Kolb8233fac2010-10-26 16:08:53 -0700291 if (mUploadMessage != null) {
292 // Already a file picker operation in progress.
293 return;
294 }
295
296 mUploadMessage = uploadMsg;
297
298 // Parse the accept type.
299 String params[] = acceptType.split(";");
300 String mimeType = params[0];
301
Ben Murdoch8cad4132012-01-11 10:56:43 +0000302 if (capture.length() > 0) {
303 mediaSource = capture;
304 }
305
306 if (capture.equals(mediaSourceValueFileSystem)) {
307 // To maintain backwards compatibility with the previous implementation
308 // of the media capture API, if the value of the 'capture' attribute is
309 // "filesystem", we should examine the accept-type for a MIME type that
310 // may specify a different capture value.
311 for (String p : params) {
312 String[] keyValue = p.split("=");
313 if (keyValue.length == 2) {
314 // Process key=value parameters.
315 if (mediaSourceKey.equals(keyValue[0])) {
316 mediaSource = keyValue[1];
317 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700318 }
319 }
320 }
321
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000322 //Ensure it is not still set from a previous upload.
323 mCameraFilePath = null;
324
325 if (mimeType.equals(imageMimeType)) {
326 if (mediaSource.equals(mediaSourceValueCamera)) {
327 // Specified 'image/*' and requested the camera, so go ahead and launch the
328 // camera directly.
329 startActivity(createCameraIntent());
330 return;
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000331 } else {
Ben Murdoch8cad4132012-01-11 10:56:43 +0000332 // Specified just 'image/*', capture=filesystem, or an invalid capture parameter.
333 // In all these cases we show a traditional picker filetered on accept type
334 // so launch an intent for both the Camera and image/* OPENABLE.
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000335 Intent chooser = createChooserIntent(createCameraIntent());
336 chooser.putExtra(Intent.EXTRA_INTENT, createOpenableIntent(imageMimeType));
337 startActivity(chooser);
338 return;
339 }
340 } else if (mimeType.equals(videoMimeType)) {
341 if (mediaSource.equals(mediaSourceValueCamcorder)) {
342 // Specified 'video/*' and requested the camcorder, so go ahead and launch the
343 // camcorder directly.
344 startActivity(createCamcorderIntent());
345 return;
Ben Murdoch8cad4132012-01-11 10:56:43 +0000346 } else {
347 // Specified just 'video/*', capture=filesystem or an invalid capture parameter.
348 // In all these cases we show an intent for the traditional file picker, filtered
349 // on accept type so launch an intent for both camcorder and video/* OPENABLE.
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000350 Intent chooser = createChooserIntent(createCamcorderIntent());
351 chooser.putExtra(Intent.EXTRA_INTENT, createOpenableIntent(videoMimeType));
352 startActivity(chooser);
353 return;
354 }
355 } else if (mimeType.equals(audioMimeType)) {
356 if (mediaSource.equals(mediaSourceValueMicrophone)) {
357 // Specified 'audio/*' and requested microphone, so go ahead and launch the sound
358 // recorder.
359 startActivity(createSoundRecorderIntent());
360 return;
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000361 } else {
Ben Murdoch8cad4132012-01-11 10:56:43 +0000362 // Specified just 'audio/*', capture=filesystem of an invalid capture parameter.
363 // In all these cases so go ahead and launch an intent for both the sound
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000364 // recorder and audio/* OPENABLE.
365 Intent chooser = createChooserIntent(createSoundRecorderIntent());
366 chooser.putExtra(Intent.EXTRA_INTENT, createOpenableIntent(audioMimeType));
367 startActivity(chooser);
368 return;
369 }
370 }
371
372 // No special handling based on the accept type was necessary, so trigger the default
373 // file upload chooser.
374 startActivity(createDefaultOpenableIntent());
375 }
376
Vivek Sekharb54614f2014-05-01 19:03:37 -0700377 void showFileChooser(ValueCallback<String[]> uploadFilePaths, String acceptTypes,
378 boolean capture) {
379
380 final String imageMimeType = "image/*";
381 final String videoMimeType = "video/*";
382 final String audioMimeType = "audio/*";
383
384 if (mUploadFilePaths != null) {
385 // Already a file picker operation in progress.
386 return;
387 }
388
389 mUploadFilePaths = uploadFilePaths;
390
391 // Parse the accept type.
392 String params[] = acceptTypes.split(";");
393 String mimeType = params[0];
394
395 // Ensure it is not still set from a previous upload.
396 mCameraFilePath = null;
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700397 List<Intent> intentList = new ArrayList<Intent>();
Vivek Sekharb54614f2014-05-01 19:03:37 -0700398
399 if (mimeType.equals(imageMimeType)) {
400 if (capture) {
401 // Specified 'image/*' and capture=true, so go ahead and launch the
402 // camera directly.
403 startActivity(createCameraIntent());
404 return;
405 } else {
406 // Specified just 'image/*', capture=false, or no capture value.
407 // In all these cases we show a traditional picker filetered on accept type
408 // so launch an intent for both the Camera and image/* OPENABLE.
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700409 intentList.add(createCameraIntent());
410 createUploadDialog(imageMimeType, intentList);
Vivek Sekharb54614f2014-05-01 19:03:37 -0700411 return;
412 }
413 } else if (mimeType.equals(videoMimeType)) {
414 if (capture) {
415 // Specified 'video/*' and capture=true, so go ahead and launch the
416 // camcorder directly.
417 startActivity(createCamcorderIntent());
418 return;
419 } else {
420 // Specified just 'video/*', capture=false, or no capture value.
421 // In all these cases we show an intent for the traditional file picker, filtered
422 // on accept type so launch an intent for both camcorder and video/* OPENABLE.
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700423 intentList.add(createCamcorderIntent());
424 createUploadDialog(videoMimeType, intentList);
Vivek Sekharb54614f2014-05-01 19:03:37 -0700425 return;
426 }
427 } else if (mimeType.equals(audioMimeType)) {
428 if (capture) {
429 // Specified 'audio/*' and capture=true, so go ahead and launch the sound
430 // recorder.
431 startActivity(createSoundRecorderIntent());
432 return;
433 } else {
434 // Specified just 'audio/*', capture=false, or no capture value.
435 // In all these cases so go ahead and launch an intent for both the sound
436 // recorder and audio/* OPENABLE.
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700437 intentList.add(createSoundRecorderIntent());
438 createUploadDialog(audioMimeType, intentList);
Vivek Sekharb54614f2014-05-01 19:03:37 -0700439 return;
440 }
441 }
442
443 // No special handling based on the accept type was necessary, so trigger the default
444 // file upload chooser.
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700445 createUploadDialog("*/*", null);
Vivek Sekharb54614f2014-05-01 19:03:37 -0700446 }
447
448
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000449 private void startActivity(Intent intent) {
450 try {
451 mController.getActivity().startActivityForResult(intent, Controller.FILE_SELECTED);
452 } catch (ActivityNotFoundException e) {
453 // No installed app was able to handle the intent that
454 // we sent, so fallback to the default file upload control.
455 try {
Ben Murdoch51f6a2f2011-02-21 12:27:07 +0000456 mCaughtActivityNotFoundException = true;
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000457 mController.getActivity().startActivityForResult(createDefaultOpenableIntent(),
458 Controller.FILE_SELECTED);
459 } catch (ActivityNotFoundException e2) {
460 // Nothing can return us a file, so file upload is effectively disabled.
461 Toast.makeText(mController.getActivity(), R.string.uploads_disabled,
462 Toast.LENGTH_LONG).show();
463 }
464 }
465 }
466
467 private Intent createDefaultOpenableIntent() {
468 // Create and return a chooser with the default OPENABLE
469 // actions including the camera, camcorder and sound
470 // recorder where available.
Michael Kolb8233fac2010-10-26 16:08:53 -0700471 Intent i = new Intent(Intent.ACTION_GET_CONTENT);
472 i.addCategory(Intent.CATEGORY_OPENABLE);
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000473 i.setType("*/*");
Michael Kolb8233fac2010-10-26 16:08:53 -0700474
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000475 Intent chooser = createChooserIntent(createCameraIntent(), createCamcorderIntent(),
476 createSoundRecorderIntent());
477 chooser.putExtra(Intent.EXTRA_INTENT, i);
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700478
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000479 return chooser;
480 }
481
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700482
483 private void createUploadDialog(String openableMimeType, List<Intent> intentList) {
484
485 Intent openable = new Intent(Intent.ACTION_GET_CONTENT);
486 openable.addCategory(Intent.CATEGORY_OPENABLE);
487 openable.setType(openableMimeType);
488
489 if (openableMimeType.equals("*/*") && intentList == null) {
490 intentList = new ArrayList<Intent>();
491 intentList.add(createCameraIntent());
492 intentList.add(createCamcorderIntent());
493 intentList.add(createSoundRecorderIntent());
494 }
495
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700496 PackageManager pm = mController.getActivity().getPackageManager();
Axesh R. Ajmera025fed32014-09-04 11:18:47 -0700497 ArrayList<ResolveInfo> uploadApps = new ArrayList<ResolveInfo>();
498
499 //Step 1:- resolve all apps for IntentList passed
500 for (Intent i: intentList) {
501 List<ResolveInfo> intentAppsList = pm.queryIntentActivities(i,
502 PackageManager.MATCH_DEFAULT_ONLY);
503 // limit only to first activity
504 uploadApps.add(intentAppsList.get(0));
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700505 }
506
Axesh R. Ajmera025fed32014-09-04 11:18:47 -0700507 // Step 2:- get all openable apps list and create corresponding intents
508 List<ResolveInfo> openableAppsList = pm.queryIntentActivities(openable,
509 PackageManager.MATCH_DEFAULT_ONLY);
510 // limit only to first activity
511 ResolveInfo topOpenableApp = openableAppsList.get(0);
512 uploadApps.add(topOpenableApp);
513 ActivityInfo activityInfo = topOpenableApp.activityInfo;
514 ComponentName name = new ComponentName(activityInfo.applicationInfo.packageName,
515 activityInfo.name);
516 Intent i = new Intent(Intent.ACTION_GET_CONTENT);
517 i.setType(openableMimeType);
518 i.setComponent(name);
519 intentList.add(i);
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700520
Axesh R. Ajmera025fed32014-09-04 11:18:47 -0700521 // Step 3: Pass all the apps and their corresponding intents to uploaddialog
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700522 UploadDialog upDialog = new UploadDialog(mController.getActivity());
Axesh R. Ajmera025fed32014-09-04 11:18:47 -0700523 upDialog.getUploadableApps(uploadApps, intentList);
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700524 upDialog.loadView(this);
525 }
526
527 public void initiateActivity(Intent intent) {
528 startActivity(intent);
529 }
530
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000531 private Intent createChooserIntent(Intent... intents) {
532 Intent chooser = new Intent(Intent.ACTION_CHOOSER);
533 chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents);
534 chooser.putExtra(Intent.EXTRA_TITLE,
535 mController.getActivity().getResources()
536 .getString(R.string.choose_upload));
537 return chooser;
538 }
539
540 private Intent createOpenableIntent(String type) {
541 Intent i = new Intent(Intent.ACTION_GET_CONTENT);
542 i.addCategory(Intent.CATEGORY_OPENABLE);
543 i.setType(type);
544 return i;
545 }
546
547 private Intent createCameraIntent() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700548 Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
549 File externalDataDir = Environment.getExternalStoragePublicDirectory(
550 Environment.DIRECTORY_DCIM);
551 File cameraDataDir = new File(externalDataDir.getAbsolutePath() +
552 File.separator + "browser-photos");
553 cameraDataDir.mkdirs();
554 mCameraFilePath = cameraDataDir.getAbsolutePath() + File.separator +
555 System.currentTimeMillis() + ".jpg";
556 cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mCameraFilePath)));
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000557 return cameraIntent;
Michael Kolb8233fac2010-10-26 16:08:53 -0700558 }
559
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000560 private Intent createCamcorderIntent() {
561 return new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
562 }
563
564 private Intent createSoundRecorderIntent() {
565 return new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
Michael Kolb8233fac2010-10-26 16:08:53 -0700566 }
567
568}