blob: e0d152765f6ce603479e878ab5660b84a5830527 [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 boolean hasGoodFilePath = false;
110 String filePath = null;
111 if (result != null) {
112 String scheme = result.getScheme();
Axesh R. Ajmerac3d90452014-10-29 18:12:19 -0700113 // try to get local file path from uri
Vivek Sekharb54614f2014-05-01 19:03:37 -0700114 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 }
Axesh R. Ajmerac3d90452014-10-29 18:12:19 -0700121
122 // The native layer only accepts path based on file scheme
123 // and skips anything else passed to it
124 filePath = "file://"+filePath;
Vivek Sekharb54614f2014-05-01 19:03:37 -0700125 }
126
127 // Add for carrier feature - prevent uploading DRM type files.
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700128 boolean drmUploadEnabled = mController.getContext().getResources().getBoolean(
129 R.bool.drm_uploads);
Vivek Sekharb54614f2014-05-01 19:03:37 -0700130 boolean isDRMFileType = false;
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700131 if (drmUploadEnabled && filePath != null
Vivek Sekharb54614f2014-05-01 19:03:37 -0700132 && (filePath.endsWith(".fl") || filePath.endsWith(".dm")
133 || filePath.endsWith(".dcf") || filePath.endsWith(".dr")
134 || filePath.endsWith(".dd"))) {
135 isDRMFileType = true;
136 Toast.makeText(mController.getContext(), R.string.drm_file_unsupported,
137 Toast.LENGTH_LONG).show();
138 }
139
140 if (mUploadMessage != null) {
141 if (!isDRMFileType) {
142 mUploadMessage.onReceiveValue(result);
143 } else {
144 mUploadMessage.onReceiveValue(null);
145 }
146 }
147
148 if (mUploadFilePaths != null) {
149 if (hasGoodFilePath && !isDRMFileType) {
150 Log.d(TAG, "upload file path:" + filePath);
Axesh R. Ajmerac3d90452014-10-29 18:12:19 -0700151
Vivek Sekharb54614f2014-05-01 19:03:37 -0700152 mUploadFilePaths.onReceiveValue(new String[]{filePath});
153 } else {
154 mUploadFilePaths.onReceiveValue(null);
155 }
kaiyiz4b59d262013-07-30 10:41:38 +0800156 }
157
Ben Murdoch51f6a2f2011-02-21 12:27:07 +0000158 mHandled = true;
159 mCaughtActivityNotFoundException = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700160 }
161
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700162
163 public String getDocumentId(final Uri uri) {
164 String id = null;
165 try {
166 Object[] params = {(android.net.Uri)uri};
167 Class[] type = new Class[] {Class.forName("android.net.Uri") };
168 id = (String) ReflectHelper.invokeMethod(
169 "android.provider.DocumentsContract","getDocumentId",
170 type, params);
171
172 } catch(java.lang.ClassNotFoundException e) {
173
174 }
175 return id;
176 }
177
178
179 public String getFilePath(final Context context, final Uri uri) {
180 String id = getDocumentId(uri);
181
182 // DocumentProvider is new API exposed in Kitkat
183 // Its a way of exposing unified file explorer
184 if (id != null) {
185 // ExternalStorageProvider
186 if (isExternalStorageDocument(uri)) {
187 final String docId = id;
188 final String[] split = docId.split(":");
189 final String type = split[0];
190
191 if ("primary".equalsIgnoreCase(type)) {
192 return Environment.getExternalStorageDirectory() + "/" + split[1];
193 }
194 }
195 // DownloadsProvider
196 else if (isDownloadsDocument(uri)) {
197 final Uri contentUri = ContentUris.withAppendedId(
198 Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
199 return getDataColumn(context, contentUri, null, null);
200 }
201 // MediaProvider
202 else if (isMediaDocument(uri)) {
203 final String docId = id;
204 final String[] split = docId.split(":");
205 final String type = split[0];
206
207 Uri contentUri = null;
208 if ("image".equals(type)) {
209 contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
210 } else if ("video".equals(type)) {
211 contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
212 } else if ("audio".equals(type)) {
213 contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
214 }
215
216 final String selection = "_id=?";
217 final String[] selectionArgs = new String[] {
218 split[1]
219 };
220
221 return getDataColumn(context, contentUri, selection, selectionArgs);
222 }
223 }
224 // MediaStore (and general)
225 else if ("content".equalsIgnoreCase(uri.getScheme())) {
226 return getDataColumn(context, uri, null, null);
227 }
228
229 return null;
230 }
231
232 /**
233 * Get the value of the data column for this Uri. This is useful for
234 * MediaStore Uris, and other file-based ContentProviders.
235 * @return The value of the _data column, which is typically a file path.
236 */
237 private String getDataColumn(Context context, Uri uri, String selection,
238 String[] selectionArgs) {
239
240 Cursor cursor = null;
241 final String column = "_data";
242 final String[] projection = { column };
243
244 try {
245 cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
246 null);
247 if (cursor != null && cursor.moveToFirst()) {
248 final int column_index = cursor.getColumnIndexOrThrow(column);
249 return cursor.getString(column_index);
250 }
251 } finally {
252 if (cursor != null)
253 cursor.close();
254 }
255 return null;
256 }
257
258 /**
259 * @return Whether the Uri authority is ExternalStorageProvider.
260 */
261 private boolean isExternalStorageDocument(Uri uri) {
262 return "com.android.externalstorage.documents".equals(uri.getAuthority());
263 }
264
265 /**
266 * @return Whether the Uri authority is DownloadsProvider.
267 */
268 private boolean isDownloadsDocument(Uri uri) {
269 return "com.android.providers.downloads.documents".equals(uri.getAuthority());
270 }
271
272 /**
273 * @return Whether the Uri authority is MediaProvider.
274 */
275 public static boolean isMediaDocument(Uri uri) {
276 return "com.android.providers.media.documents".equals(uri.getAuthority());
277 }
278
279
Ben Murdoch8cad4132012-01-11 10:56:43 +0000280 void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700281
282 final String imageMimeType = "image/*";
283 final String videoMimeType = "video/*";
284 final String audioMimeType = "audio/*";
285 final String mediaSourceKey = "capture";
286 final String mediaSourceValueCamera = "camera";
287 final String mediaSourceValueFileSystem = "filesystem";
288 final String mediaSourceValueCamcorder = "camcorder";
289 final String mediaSourceValueMicrophone = "microphone";
290
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000291 // According to the spec, media source can be 'filesystem' or 'camera' or 'camcorder'
Ben Murdoch8cad4132012-01-11 10:56:43 +0000292 // or 'microphone' and the default value should be 'filesystem'.
293 String mediaSource = mediaSourceValueFileSystem;
Michael Kolb8233fac2010-10-26 16:08:53 -0700294
Michael Kolb8233fac2010-10-26 16:08:53 -0700295 if (mUploadMessage != null) {
296 // Already a file picker operation in progress.
297 return;
298 }
299
300 mUploadMessage = uploadMsg;
301
302 // Parse the accept type.
303 String params[] = acceptType.split(";");
304 String mimeType = params[0];
305
Ben Murdoch8cad4132012-01-11 10:56:43 +0000306 if (capture.length() > 0) {
307 mediaSource = capture;
308 }
309
310 if (capture.equals(mediaSourceValueFileSystem)) {
311 // To maintain backwards compatibility with the previous implementation
312 // of the media capture API, if the value of the 'capture' attribute is
313 // "filesystem", we should examine the accept-type for a MIME type that
314 // may specify a different capture value.
315 for (String p : params) {
316 String[] keyValue = p.split("=");
317 if (keyValue.length == 2) {
318 // Process key=value parameters.
319 if (mediaSourceKey.equals(keyValue[0])) {
320 mediaSource = keyValue[1];
321 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700322 }
323 }
324 }
325
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000326 //Ensure it is not still set from a previous upload.
327 mCameraFilePath = null;
328
329 if (mimeType.equals(imageMimeType)) {
330 if (mediaSource.equals(mediaSourceValueCamera)) {
331 // Specified 'image/*' and requested the camera, so go ahead and launch the
332 // camera directly.
333 startActivity(createCameraIntent());
334 return;
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000335 } else {
Ben Murdoch8cad4132012-01-11 10:56:43 +0000336 // Specified just 'image/*', capture=filesystem, or an invalid capture parameter.
337 // In all these cases we show a traditional picker filetered on accept type
338 // so launch an intent for both the Camera and image/* OPENABLE.
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000339 Intent chooser = createChooserIntent(createCameraIntent());
340 chooser.putExtra(Intent.EXTRA_INTENT, createOpenableIntent(imageMimeType));
341 startActivity(chooser);
342 return;
343 }
344 } else if (mimeType.equals(videoMimeType)) {
345 if (mediaSource.equals(mediaSourceValueCamcorder)) {
346 // Specified 'video/*' and requested the camcorder, so go ahead and launch the
347 // camcorder directly.
348 startActivity(createCamcorderIntent());
349 return;
Ben Murdoch8cad4132012-01-11 10:56:43 +0000350 } else {
351 // Specified just 'video/*', capture=filesystem or an invalid capture parameter.
352 // In all these cases we show an intent for the traditional file picker, filtered
353 // on accept type so launch an intent for both camcorder and video/* OPENABLE.
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000354 Intent chooser = createChooserIntent(createCamcorderIntent());
355 chooser.putExtra(Intent.EXTRA_INTENT, createOpenableIntent(videoMimeType));
356 startActivity(chooser);
357 return;
358 }
359 } else if (mimeType.equals(audioMimeType)) {
360 if (mediaSource.equals(mediaSourceValueMicrophone)) {
361 // Specified 'audio/*' and requested microphone, so go ahead and launch the sound
362 // recorder.
363 startActivity(createSoundRecorderIntent());
364 return;
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000365 } else {
Ben Murdoch8cad4132012-01-11 10:56:43 +0000366 // Specified just 'audio/*', capture=filesystem of an invalid capture parameter.
367 // In all these cases so go ahead and launch an intent for both the sound
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000368 // recorder and audio/* OPENABLE.
369 Intent chooser = createChooserIntent(createSoundRecorderIntent());
370 chooser.putExtra(Intent.EXTRA_INTENT, createOpenableIntent(audioMimeType));
371 startActivity(chooser);
372 return;
373 }
374 }
375
376 // No special handling based on the accept type was necessary, so trigger the default
377 // file upload chooser.
378 startActivity(createDefaultOpenableIntent());
379 }
380
Vivek Sekharb54614f2014-05-01 19:03:37 -0700381 void showFileChooser(ValueCallback<String[]> uploadFilePaths, String acceptTypes,
382 boolean capture) {
383
384 final String imageMimeType = "image/*";
385 final String videoMimeType = "video/*";
386 final String audioMimeType = "audio/*";
387
388 if (mUploadFilePaths != null) {
389 // Already a file picker operation in progress.
390 return;
391 }
392
393 mUploadFilePaths = uploadFilePaths;
394
395 // Parse the accept type.
396 String params[] = acceptTypes.split(";");
397 String mimeType = params[0];
398
399 // Ensure it is not still set from a previous upload.
400 mCameraFilePath = null;
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700401 List<Intent> intentList = new ArrayList<Intent>();
Vivek Sekharb54614f2014-05-01 19:03:37 -0700402
403 if (mimeType.equals(imageMimeType)) {
404 if (capture) {
405 // Specified 'image/*' and capture=true, so go ahead and launch the
406 // camera directly.
407 startActivity(createCameraIntent());
408 return;
409 } else {
410 // Specified just 'image/*', capture=false, or no capture value.
411 // In all these cases we show a traditional picker filetered on accept type
412 // so launch an intent for both the Camera and image/* OPENABLE.
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700413 intentList.add(createCameraIntent());
414 createUploadDialog(imageMimeType, intentList);
Vivek Sekharb54614f2014-05-01 19:03:37 -0700415 return;
416 }
417 } else if (mimeType.equals(videoMimeType)) {
418 if (capture) {
419 // Specified 'video/*' and capture=true, so go ahead and launch the
420 // camcorder directly.
421 startActivity(createCamcorderIntent());
422 return;
423 } else {
424 // Specified just 'video/*', capture=false, or no capture value.
425 // In all these cases we show an intent for the traditional file picker, filtered
426 // on accept type so launch an intent for both camcorder and video/* OPENABLE.
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700427 intentList.add(createCamcorderIntent());
428 createUploadDialog(videoMimeType, intentList);
Vivek Sekharb54614f2014-05-01 19:03:37 -0700429 return;
430 }
431 } else if (mimeType.equals(audioMimeType)) {
432 if (capture) {
433 // Specified 'audio/*' and capture=true, so go ahead and launch the sound
434 // recorder.
435 startActivity(createSoundRecorderIntent());
436 return;
437 } else {
438 // Specified just 'audio/*', capture=false, or no capture value.
439 // In all these cases so go ahead and launch an intent for both the sound
440 // recorder and audio/* OPENABLE.
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700441 intentList.add(createSoundRecorderIntent());
442 createUploadDialog(audioMimeType, intentList);
Vivek Sekharb54614f2014-05-01 19:03:37 -0700443 return;
444 }
445 }
446
447 // No special handling based on the accept type was necessary, so trigger the default
448 // file upload chooser.
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700449 createUploadDialog("*/*", null);
Vivek Sekharb54614f2014-05-01 19:03:37 -0700450 }
451
452
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000453 private void startActivity(Intent intent) {
454 try {
455 mController.getActivity().startActivityForResult(intent, Controller.FILE_SELECTED);
456 } catch (ActivityNotFoundException e) {
457 // No installed app was able to handle the intent that
458 // we sent, so fallback to the default file upload control.
459 try {
Ben Murdoch51f6a2f2011-02-21 12:27:07 +0000460 mCaughtActivityNotFoundException = true;
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000461 mController.getActivity().startActivityForResult(createDefaultOpenableIntent(),
462 Controller.FILE_SELECTED);
463 } catch (ActivityNotFoundException e2) {
464 // Nothing can return us a file, so file upload is effectively disabled.
465 Toast.makeText(mController.getActivity(), R.string.uploads_disabled,
466 Toast.LENGTH_LONG).show();
467 }
468 }
469 }
470
471 private Intent createDefaultOpenableIntent() {
472 // Create and return a chooser with the default OPENABLE
473 // actions including the camera, camcorder and sound
474 // recorder where available.
Michael Kolb8233fac2010-10-26 16:08:53 -0700475 Intent i = new Intent(Intent.ACTION_GET_CONTENT);
476 i.addCategory(Intent.CATEGORY_OPENABLE);
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000477 i.setType("*/*");
Michael Kolb8233fac2010-10-26 16:08:53 -0700478
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000479 Intent chooser = createChooserIntent(createCameraIntent(), createCamcorderIntent(),
480 createSoundRecorderIntent());
481 chooser.putExtra(Intent.EXTRA_INTENT, i);
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700482
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000483 return chooser;
484 }
485
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700486
487 private void createUploadDialog(String openableMimeType, List<Intent> intentList) {
488
489 Intent openable = new Intent(Intent.ACTION_GET_CONTENT);
490 openable.addCategory(Intent.CATEGORY_OPENABLE);
491 openable.setType(openableMimeType);
492
493 if (openableMimeType.equals("*/*") && intentList == null) {
494 intentList = new ArrayList<Intent>();
495 intentList.add(createCameraIntent());
496 intentList.add(createCamcorderIntent());
497 intentList.add(createSoundRecorderIntent());
498 }
499
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700500 PackageManager pm = mController.getActivity().getPackageManager();
Axesh R. Ajmera025fed32014-09-04 11:18:47 -0700501 ArrayList<ResolveInfo> uploadApps = new ArrayList<ResolveInfo>();
502
503 //Step 1:- resolve all apps for IntentList passed
504 for (Intent i: intentList) {
505 List<ResolveInfo> intentAppsList = pm.queryIntentActivities(i,
506 PackageManager.MATCH_DEFAULT_ONLY);
507 // limit only to first activity
508 uploadApps.add(intentAppsList.get(0));
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700509 }
510
Axesh R. Ajmera025fed32014-09-04 11:18:47 -0700511 // Step 2:- get all openable apps list and create corresponding intents
512 List<ResolveInfo> openableAppsList = pm.queryIntentActivities(openable,
513 PackageManager.MATCH_DEFAULT_ONLY);
514 // limit only to first activity
515 ResolveInfo topOpenableApp = openableAppsList.get(0);
516 uploadApps.add(topOpenableApp);
517 ActivityInfo activityInfo = topOpenableApp.activityInfo;
518 ComponentName name = new ComponentName(activityInfo.applicationInfo.packageName,
519 activityInfo.name);
520 Intent i = new Intent(Intent.ACTION_GET_CONTENT);
521 i.setType(openableMimeType);
522 i.setComponent(name);
523 intentList.add(i);
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700524
Axesh R. Ajmera025fed32014-09-04 11:18:47 -0700525 // Step 3: Pass all the apps and their corresponding intents to uploaddialog
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700526 UploadDialog upDialog = new UploadDialog(mController.getActivity());
Axesh R. Ajmera025fed32014-09-04 11:18:47 -0700527 upDialog.getUploadableApps(uploadApps, intentList);
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700528 upDialog.loadView(this);
529 }
530
531 public void initiateActivity(Intent intent) {
532 startActivity(intent);
533 }
534
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000535 private Intent createChooserIntent(Intent... intents) {
536 Intent chooser = new Intent(Intent.ACTION_CHOOSER);
537 chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents);
538 chooser.putExtra(Intent.EXTRA_TITLE,
539 mController.getActivity().getResources()
540 .getString(R.string.choose_upload));
541 return chooser;
542 }
543
544 private Intent createOpenableIntent(String type) {
545 Intent i = new Intent(Intent.ACTION_GET_CONTENT);
546 i.addCategory(Intent.CATEGORY_OPENABLE);
547 i.setType(type);
548 return i;
549 }
550
551 private Intent createCameraIntent() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700552 Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
553 File externalDataDir = Environment.getExternalStoragePublicDirectory(
554 Environment.DIRECTORY_DCIM);
555 File cameraDataDir = new File(externalDataDir.getAbsolutePath() +
556 File.separator + "browser-photos");
557 cameraDataDir.mkdirs();
558 mCameraFilePath = cameraDataDir.getAbsolutePath() + File.separator +
559 System.currentTimeMillis() + ".jpg";
560 cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mCameraFilePath)));
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000561 return cameraIntent;
Michael Kolb8233fac2010-10-26 16:08:53 -0700562 }
563
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000564 private Intent createCamcorderIntent() {
565 return new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
566 }
567
568 private Intent createSoundRecorderIntent() {
569 return new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
Michael Kolb8233fac2010-10-26 16:08:53 -0700570 }
571
572}