blob: 655d642bfc121723649bbe5d798f8d92a5586ee6 [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 -070043import java.util.Vector;
44
45/**
46 * Handle the file upload callbacks from WebView here
47 */
48public class UploadHandler {
49
Vivek Sekharb54614f2014-05-01 19:03:37 -070050 private static final String TAG = "UploadHandler";
Michael Kolb8233fac2010-10-26 16:08:53 -070051 /*
52 * The Object used to inform the WebView of the file to upload.
53 */
54 private ValueCallback<Uri> mUploadMessage;
Vivek Sekharb54614f2014-05-01 19:03:37 -070055 private ValueCallback<String[]> mUploadFilePaths;
Michael Kolb8233fac2010-10-26 16:08:53 -070056 private String mCameraFilePath;
57
Ben Murdoch51f6a2f2011-02-21 12:27:07 +000058 private boolean mHandled;
59 private boolean mCaughtActivityNotFoundException;
60
Michael Kolb8233fac2010-10-26 16:08:53 -070061 private Controller mController;
62
63 public UploadHandler(Controller controller) {
64 mController = controller;
65 }
66
67 String getFilePath() {
68 return mCameraFilePath;
69 }
70
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -070071 protected boolean handled() {
Ben Murdoch51f6a2f2011-02-21 12:27:07 +000072 return mHandled;
73 }
74
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -070075 protected void setHandled(boolean handled) {
76 mHandled = handled;
77 mCaughtActivityNotFoundException = false;
78 if (!mHandled)
79 mUploadFilePaths.onReceiveValue(null);
80 }
Ben Murdoch51f6a2f2011-02-21 12:27:07 +000081
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -070082 void onResult(int resultCode, Intent intent) {
Ben Murdoch51f6a2f2011-02-21 12:27:07 +000083 if (resultCode == Activity.RESULT_CANCELED && mCaughtActivityNotFoundException) {
84 // Couldn't resolve an activity, we are going to try again so skip
85 // this result.
86 mCaughtActivityNotFoundException = false;
87 return;
88 }
89
Michael Kolb8233fac2010-10-26 16:08:53 -070090 Uri result = intent == null || resultCode != Activity.RESULT_OK ? null
91 : intent.getData();
92
93 // As we ask the camera to save the result of the user taking
94 // a picture, the camera application does not return anything other
95 // than RESULT_OK. So we need to check whether the file we expected
96 // was written to disk in the in the case that we
97 // did not get an intent returned but did get a RESULT_OK. If it was,
98 // we assume that this result has came back from the camera.
99 if (result == null && intent == null && resultCode == Activity.RESULT_OK) {
100 File cameraFile = new File(mCameraFilePath);
101 if (cameraFile.exists()) {
102 result = Uri.fromFile(cameraFile);
103 // Broadcast to the media scanner that we have a new photo
104 // so it will be added into the gallery for the user.
105 mController.getActivity().sendBroadcast(
106 new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, result));
107 }
108 }
109
Vivek Sekharb54614f2014-05-01 19:03:37 -0700110 // try to get local file path from uri
111 boolean hasGoodFilePath = false;
112 String filePath = null;
113 if (result != null) {
114 String scheme = result.getScheme();
115 if ("file".equals(scheme)) {
116 filePath = result.getPath();
117 hasGoodFilePath = filePath != null && !filePath.isEmpty();
118 } else if ("content".equals(scheme)) {
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700119 filePath = getFilePath(mController.getContext(), result);
120 hasGoodFilePath = filePath != null && !filePath.isEmpty();
Vivek Sekharb54614f2014-05-01 19:03:37 -0700121 }
122 }
123
124 // Add for carrier feature - prevent uploading DRM type files.
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700125 boolean drmUploadEnabled = mController.getContext().getResources().getBoolean(
126 R.bool.drm_uploads);
Vivek Sekharb54614f2014-05-01 19:03:37 -0700127 boolean isDRMFileType = false;
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700128 if (drmUploadEnabled && filePath != null
Vivek Sekharb54614f2014-05-01 19:03:37 -0700129 && (filePath.endsWith(".fl") || filePath.endsWith(".dm")
130 || filePath.endsWith(".dcf") || filePath.endsWith(".dr")
131 || filePath.endsWith(".dd"))) {
132 isDRMFileType = true;
133 Toast.makeText(mController.getContext(), R.string.drm_file_unsupported,
134 Toast.LENGTH_LONG).show();
135 }
136
137 if (mUploadMessage != null) {
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700138
Vivek Sekharb54614f2014-05-01 19:03:37 -0700139 if (!isDRMFileType) {
140 mUploadMessage.onReceiveValue(result);
141 } else {
142 mUploadMessage.onReceiveValue(null);
143 }
144 }
145
146 if (mUploadFilePaths != null) {
147 if (hasGoodFilePath && !isDRMFileType) {
148 Log.d(TAG, "upload file path:" + filePath);
149 mUploadFilePaths.onReceiveValue(new String[]{filePath});
150 } else {
151 mUploadFilePaths.onReceiveValue(null);
152 }
kaiyiz4b59d262013-07-30 10:41:38 +0800153 }
154
Ben Murdoch51f6a2f2011-02-21 12:27:07 +0000155 mHandled = true;
156 mCaughtActivityNotFoundException = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700157 }
158
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700159
160 public String getDocumentId(final Uri uri) {
161 String id = null;
162 try {
163 Object[] params = {(android.net.Uri)uri};
164 Class[] type = new Class[] {Class.forName("android.net.Uri") };
165 id = (String) ReflectHelper.invokeMethod(
166 "android.provider.DocumentsContract","getDocumentId",
167 type, params);
168
169 } catch(java.lang.ClassNotFoundException e) {
170
171 }
172 return id;
173 }
174
175
176 public String getFilePath(final Context context, final Uri uri) {
177 String id = getDocumentId(uri);
178
179 // DocumentProvider is new API exposed in Kitkat
180 // Its a way of exposing unified file explorer
181 if (id != null) {
182 // ExternalStorageProvider
183 if (isExternalStorageDocument(uri)) {
184 final String docId = id;
185 final String[] split = docId.split(":");
186 final String type = split[0];
187
188 if ("primary".equalsIgnoreCase(type)) {
189 return Environment.getExternalStorageDirectory() + "/" + split[1];
190 }
191 }
192 // DownloadsProvider
193 else if (isDownloadsDocument(uri)) {
194 final Uri contentUri = ContentUris.withAppendedId(
195 Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
196 return getDataColumn(context, contentUri, null, null);
197 }
198 // MediaProvider
199 else if (isMediaDocument(uri)) {
200 final String docId = id;
201 final String[] split = docId.split(":");
202 final String type = split[0];
203
204 Uri contentUri = null;
205 if ("image".equals(type)) {
206 contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
207 } else if ("video".equals(type)) {
208 contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
209 } else if ("audio".equals(type)) {
210 contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
211 }
212
213 final String selection = "_id=?";
214 final String[] selectionArgs = new String[] {
215 split[1]
216 };
217
218 return getDataColumn(context, contentUri, selection, selectionArgs);
219 }
220 }
221 // MediaStore (and general)
222 else if ("content".equalsIgnoreCase(uri.getScheme())) {
223 return getDataColumn(context, uri, null, null);
224 }
225
226 return null;
227 }
228
229 /**
230 * Get the value of the data column for this Uri. This is useful for
231 * MediaStore Uris, and other file-based ContentProviders.
232 * @return The value of the _data column, which is typically a file path.
233 */
234 private String getDataColumn(Context context, Uri uri, String selection,
235 String[] selectionArgs) {
236
237 Cursor cursor = null;
238 final String column = "_data";
239 final String[] projection = { column };
240
241 try {
242 cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
243 null);
244 if (cursor != null && cursor.moveToFirst()) {
245 final int column_index = cursor.getColumnIndexOrThrow(column);
246 return cursor.getString(column_index);
247 }
248 } finally {
249 if (cursor != null)
250 cursor.close();
251 }
252 return null;
253 }
254
255 /**
256 * @return Whether the Uri authority is ExternalStorageProvider.
257 */
258 private boolean isExternalStorageDocument(Uri uri) {
259 return "com.android.externalstorage.documents".equals(uri.getAuthority());
260 }
261
262 /**
263 * @return Whether the Uri authority is DownloadsProvider.
264 */
265 private boolean isDownloadsDocument(Uri uri) {
266 return "com.android.providers.downloads.documents".equals(uri.getAuthority());
267 }
268
269 /**
270 * @return Whether the Uri authority is MediaProvider.
271 */
272 public static boolean isMediaDocument(Uri uri) {
273 return "com.android.providers.media.documents".equals(uri.getAuthority());
274 }
275
276
Ben Murdoch8cad4132012-01-11 10:56:43 +0000277 void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700278
279 final String imageMimeType = "image/*";
280 final String videoMimeType = "video/*";
281 final String audioMimeType = "audio/*";
282 final String mediaSourceKey = "capture";
283 final String mediaSourceValueCamera = "camera";
284 final String mediaSourceValueFileSystem = "filesystem";
285 final String mediaSourceValueCamcorder = "camcorder";
286 final String mediaSourceValueMicrophone = "microphone";
287
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000288 // According to the spec, media source can be 'filesystem' or 'camera' or 'camcorder'
Ben Murdoch8cad4132012-01-11 10:56:43 +0000289 // or 'microphone' and the default value should be 'filesystem'.
290 String mediaSource = mediaSourceValueFileSystem;
Michael Kolb8233fac2010-10-26 16:08:53 -0700291
Michael Kolb8233fac2010-10-26 16:08:53 -0700292 if (mUploadMessage != null) {
293 // Already a file picker operation in progress.
294 return;
295 }
296
297 mUploadMessage = uploadMsg;
298
299 // Parse the accept type.
300 String params[] = acceptType.split(";");
301 String mimeType = params[0];
302
Ben Murdoch8cad4132012-01-11 10:56:43 +0000303 if (capture.length() > 0) {
304 mediaSource = capture;
305 }
306
307 if (capture.equals(mediaSourceValueFileSystem)) {
308 // To maintain backwards compatibility with the previous implementation
309 // of the media capture API, if the value of the 'capture' attribute is
310 // "filesystem", we should examine the accept-type for a MIME type that
311 // may specify a different capture value.
312 for (String p : params) {
313 String[] keyValue = p.split("=");
314 if (keyValue.length == 2) {
315 // Process key=value parameters.
316 if (mediaSourceKey.equals(keyValue[0])) {
317 mediaSource = keyValue[1];
318 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700319 }
320 }
321 }
322
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000323 //Ensure it is not still set from a previous upload.
324 mCameraFilePath = null;
325
326 if (mimeType.equals(imageMimeType)) {
327 if (mediaSource.equals(mediaSourceValueCamera)) {
328 // Specified 'image/*' and requested the camera, so go ahead and launch the
329 // camera directly.
330 startActivity(createCameraIntent());
331 return;
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000332 } else {
Ben Murdoch8cad4132012-01-11 10:56:43 +0000333 // Specified just 'image/*', capture=filesystem, or an invalid capture parameter.
334 // In all these cases we show a traditional picker filetered on accept type
335 // so launch an intent for both the Camera and image/* OPENABLE.
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000336 Intent chooser = createChooserIntent(createCameraIntent());
337 chooser.putExtra(Intent.EXTRA_INTENT, createOpenableIntent(imageMimeType));
338 startActivity(chooser);
339 return;
340 }
341 } else if (mimeType.equals(videoMimeType)) {
342 if (mediaSource.equals(mediaSourceValueCamcorder)) {
343 // Specified 'video/*' and requested the camcorder, so go ahead and launch the
344 // camcorder directly.
345 startActivity(createCamcorderIntent());
346 return;
Ben Murdoch8cad4132012-01-11 10:56:43 +0000347 } else {
348 // Specified just 'video/*', capture=filesystem or an invalid capture parameter.
349 // In all these cases we show an intent for the traditional file picker, filtered
350 // on accept type so launch an intent for both camcorder and video/* OPENABLE.
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000351 Intent chooser = createChooserIntent(createCamcorderIntent());
352 chooser.putExtra(Intent.EXTRA_INTENT, createOpenableIntent(videoMimeType));
353 startActivity(chooser);
354 return;
355 }
356 } else if (mimeType.equals(audioMimeType)) {
357 if (mediaSource.equals(mediaSourceValueMicrophone)) {
358 // Specified 'audio/*' and requested microphone, so go ahead and launch the sound
359 // recorder.
360 startActivity(createSoundRecorderIntent());
361 return;
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000362 } else {
Ben Murdoch8cad4132012-01-11 10:56:43 +0000363 // Specified just 'audio/*', capture=filesystem of an invalid capture parameter.
364 // In all these cases so go ahead and launch an intent for both the sound
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000365 // recorder and audio/* OPENABLE.
366 Intent chooser = createChooserIntent(createSoundRecorderIntent());
367 chooser.putExtra(Intent.EXTRA_INTENT, createOpenableIntent(audioMimeType));
368 startActivity(chooser);
369 return;
370 }
371 }
372
373 // No special handling based on the accept type was necessary, so trigger the default
374 // file upload chooser.
375 startActivity(createDefaultOpenableIntent());
376 }
377
Vivek Sekharb54614f2014-05-01 19:03:37 -0700378 void showFileChooser(ValueCallback<String[]> uploadFilePaths, String acceptTypes,
379 boolean capture) {
380
381 final String imageMimeType = "image/*";
382 final String videoMimeType = "video/*";
383 final String audioMimeType = "audio/*";
384
385 if (mUploadFilePaths != null) {
386 // Already a file picker operation in progress.
387 return;
388 }
389
390 mUploadFilePaths = uploadFilePaths;
391
392 // Parse the accept type.
393 String params[] = acceptTypes.split(";");
394 String mimeType = params[0];
395
396 // Ensure it is not still set from a previous upload.
397 mCameraFilePath = null;
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700398 List<Intent> intentList = new ArrayList<Intent>();
Vivek Sekharb54614f2014-05-01 19:03:37 -0700399
400 if (mimeType.equals(imageMimeType)) {
401 if (capture) {
402 // Specified 'image/*' and capture=true, so go ahead and launch the
403 // camera directly.
404 startActivity(createCameraIntent());
405 return;
406 } else {
407 // Specified just 'image/*', capture=false, or no capture value.
408 // In all these cases we show a traditional picker filetered on accept type
409 // so launch an intent for both the Camera and image/* OPENABLE.
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700410 intentList.add(createCameraIntent());
411 createUploadDialog(imageMimeType, intentList);
Vivek Sekharb54614f2014-05-01 19:03:37 -0700412 return;
413 }
414 } else if (mimeType.equals(videoMimeType)) {
415 if (capture) {
416 // Specified 'video/*' and capture=true, so go ahead and launch the
417 // camcorder directly.
418 startActivity(createCamcorderIntent());
419 return;
420 } else {
421 // Specified just 'video/*', capture=false, or no capture value.
422 // In all these cases we show an intent for the traditional file picker, filtered
423 // on accept type so launch an intent for both camcorder and video/* OPENABLE.
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700424 intentList.add(createCamcorderIntent());
425 createUploadDialog(videoMimeType, intentList);
Vivek Sekharb54614f2014-05-01 19:03:37 -0700426 return;
427 }
428 } else if (mimeType.equals(audioMimeType)) {
429 if (capture) {
430 // Specified 'audio/*' and capture=true, so go ahead and launch the sound
431 // recorder.
432 startActivity(createSoundRecorderIntent());
433 return;
434 } else {
435 // Specified just 'audio/*', capture=false, or no capture value.
436 // In all these cases so go ahead and launch an intent for both the sound
437 // recorder and audio/* OPENABLE.
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700438 intentList.add(createSoundRecorderIntent());
439 createUploadDialog(audioMimeType, intentList);
Vivek Sekharb54614f2014-05-01 19:03:37 -0700440 return;
441 }
442 }
443
444 // No special handling based on the accept type was necessary, so trigger the default
445 // file upload chooser.
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700446 createUploadDialog("*/*", null);
Vivek Sekharb54614f2014-05-01 19:03:37 -0700447 }
448
449
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000450 private void startActivity(Intent intent) {
451 try {
452 mController.getActivity().startActivityForResult(intent, Controller.FILE_SELECTED);
453 } catch (ActivityNotFoundException e) {
454 // No installed app was able to handle the intent that
455 // we sent, so fallback to the default file upload control.
456 try {
Ben Murdoch51f6a2f2011-02-21 12:27:07 +0000457 mCaughtActivityNotFoundException = true;
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000458 mController.getActivity().startActivityForResult(createDefaultOpenableIntent(),
459 Controller.FILE_SELECTED);
460 } catch (ActivityNotFoundException e2) {
461 // Nothing can return us a file, so file upload is effectively disabled.
462 Toast.makeText(mController.getActivity(), R.string.uploads_disabled,
463 Toast.LENGTH_LONG).show();
464 }
465 }
466 }
467
468 private Intent createDefaultOpenableIntent() {
469 // Create and return a chooser with the default OPENABLE
470 // actions including the camera, camcorder and sound
471 // recorder where available.
Michael Kolb8233fac2010-10-26 16:08:53 -0700472 Intent i = new Intent(Intent.ACTION_GET_CONTENT);
473 i.addCategory(Intent.CATEGORY_OPENABLE);
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000474 i.setType("*/*");
Michael Kolb8233fac2010-10-26 16:08:53 -0700475
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000476 Intent chooser = createChooserIntent(createCameraIntent(), createCamcorderIntent(),
477 createSoundRecorderIntent());
478 chooser.putExtra(Intent.EXTRA_INTENT, i);
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700479
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000480 return chooser;
481 }
482
Axesh R. Ajmera3aae1012014-07-03 16:37:53 -0700483
484 private void createUploadDialog(String openableMimeType, List<Intent> intentList) {
485
486 Intent openable = new Intent(Intent.ACTION_GET_CONTENT);
487 openable.addCategory(Intent.CATEGORY_OPENABLE);
488 openable.setType(openableMimeType);
489
490 if (openableMimeType.equals("*/*") && intentList == null) {
491 intentList = new ArrayList<Intent>();
492 intentList.add(createCameraIntent());
493 intentList.add(createCamcorderIntent());
494 intentList.add(createSoundRecorderIntent());
495 }
496
497 // get all openable apps list and create corresponading intents
498 PackageManager pm = mController.getActivity().getPackageManager();
499 List<ResolveInfo> openableAppsList = pm.queryIntentActivities(openable, 0);
500 for (int j = 0, n = openableAppsList.size(); j < n; j++ ) {
501 Intent i = new Intent(Intent.ACTION_GET_CONTENT);
502 i.setType(openableMimeType);
503 ActivityInfo activityInfo = openableAppsList.get(j).activityInfo;
504 ComponentName name = new ComponentName(activityInfo.applicationInfo.packageName,
505 activityInfo.name);
506 i.setComponent(name);
507 intentList.add(i);
508 }
509
510
511 UploadDialog upDialog = new UploadDialog(mController.getActivity());
512 upDialog.getUploadableApps(intentList);
513 upDialog.loadView(this);
514 }
515
516 public void initiateActivity(Intent intent) {
517 startActivity(intent);
518 }
519
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000520 private Intent createChooserIntent(Intent... intents) {
521 Intent chooser = new Intent(Intent.ACTION_CHOOSER);
522 chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents);
523 chooser.putExtra(Intent.EXTRA_TITLE,
524 mController.getActivity().getResources()
525 .getString(R.string.choose_upload));
526 return chooser;
527 }
528
529 private Intent createOpenableIntent(String type) {
530 Intent i = new Intent(Intent.ACTION_GET_CONTENT);
531 i.addCategory(Intent.CATEGORY_OPENABLE);
532 i.setType(type);
533 return i;
534 }
535
536 private Intent createCameraIntent() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700537 Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
538 File externalDataDir = Environment.getExternalStoragePublicDirectory(
539 Environment.DIRECTORY_DCIM);
540 File cameraDataDir = new File(externalDataDir.getAbsolutePath() +
541 File.separator + "browser-photos");
542 cameraDataDir.mkdirs();
543 mCameraFilePath = cameraDataDir.getAbsolutePath() + File.separator +
544 System.currentTimeMillis() + ".jpg";
545 cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mCameraFilePath)));
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000546 return cameraIntent;
Michael Kolb8233fac2010-10-26 16:08:53 -0700547 }
548
Ben Murdoche4c0cae2011-02-18 11:25:38 +0000549 private Intent createCamcorderIntent() {
550 return new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
551 }
552
553 private Intent createSoundRecorderIntent() {
554 return new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
Michael Kolb8233fac2010-10-26 16:08:53 -0700555 }
556
557}