List of usage examples for android.provider MediaStore EXTRA_OUTPUT
String EXTRA_OUTPUT
To view the source code for android.provider MediaStore EXTRA_OUTPUT.
Click Source Link
From source file:com.zhihuigu.sosoOffice.RegisterThirdActivity.java
@Override public void onClick(View v) { if (v == backBtn) { Intent intent = new Intent(this, LoginActivity.class); startActivity(intent);//from w w w .j a v a 2s . co m finish(); } else if (v == submitBtn) { if (textValidate()) { new Thread(runnable).start(); } } else if (v == linearGetImage) { int height = MyApplication.getInstance(this).getScreenHeight(); if (photo_tag) { shareBtn3.setVisibility(View.VISIBLE); if (height == 1280) { chazhi = 670; } else if (height == 800) { chazhi = 340; } else if (height == 960) { chazhi = 500; } else if (height == 854) { chazhi = 400; } else if (height == 480) { chazhi = 175; } } else { shareBtn3.setVisibility(View.GONE); if (height == 1280) { chazhi = 800; } else if (height == 800) { chazhi = 440; } else if (height == 960) { chazhi = 600; } else if (height == 854) { chazhi = 492; } else if (height == 480) { chazhi = 240; } } CommonUtils.hideSoftKeyboard(this);// new Thread(runnableForShowDialog).start(); } else if (v == shareBtn1) { dismiss(); Intent openCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); fileName = CommonUtils.getFileName(); MyApplication.getInstance(this).setFileName(fileName); File file = new File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD); if (!file.exists()) { file.mkdirs(); } if (CommonUtils.isHasSdcard()) { openCamera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD, fileName))); } startActivityForResult(openCamera, REQUEST_CODE_TAKE_PICTURE); } else if (v == shareBtn2) { dismiss(); Intent getAlbum = new Intent(Intent.ACTION_GET_CONTENT); getAlbum.setType(IMAGE_TYPE); startActivityForResult(getAlbum, IMAGE_CODE); } else if (v == shareBtn3) { dismiss(); // Intent intent = new Intent(this,ImagePreViewActivity.class); // intent.putExtra("path", path); // startActivityForResult(intent, 6); ArrayList<String> al = new ArrayList<String>(); al.clear(); al.add(path); Intent it = new Intent(this, ImageSwitcher.class); it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); it.putStringArrayListExtra("pathes", al); it.putExtra("index", 0); startActivity(it); } else if (v == cancleBtn) { dismiss(); } super.onClick(v); }
From source file:com.bloc.blocparty.TimelineFragment.java
public void startCamera() { // give the image a name so we can store it in the phone's default // location// w w w . j a v a 2s . c om String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, "IMG_" + timeStamp + ".jpg"); File f = getOutputMediaFile(MEDIA_TYPE_IMAGE); fileUri = Uri.fromFile(f); mCurrentPhotoPath = f.getAbsolutePath(); Log.d("photo path is ", mCurrentPhotoPath.toString()); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra("return-data", true); getActivity().setResult(RESULT_OK, intent); intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // start the image capture Intent startActivityForResult(intent, CAMERA_TAKE_PHOTO_REQUEST_CODE); }
From source file:com.ushahidi.android.app.ui.phone.AddCheckinActivity.java
/** * Create various dialog/*from w w w .j a v a2 s . c om*/ */ @Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_ERROR_NETWORK: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.network_error)); dialog.setMessage(getString(R.string.network_error_msg)); dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } case DIALOG_ERROR_SAVING: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.network_error)); dialog.setMessage(getString(R.string.file_system_error_msg)); dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } case DIALOG_CHOOSE_IMAGE_METHOD: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.choose_method)); dialog.setMessage(getString(R.string.how_to_select_pic)); dialog.setButton(getString(R.string.gallery_option), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_PICK); intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, REQUEST_CODE_IMAGE); dialog.dismiss(); } }); dialog.setButton2(getString(R.string.cancel), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setButton3(getString(R.string.camera_option), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, PhotoUtils.getPhotoUri(photoName, AddCheckinActivity.this)); startActivityForResult(intent, REQUEST_CODE_CAMERA); dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } case DIALOG_SHOW_MESSAGE: AlertDialog.Builder messageBuilder = new AlertDialog.Builder(this); messageBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog showDialog = messageBuilder.create(); showDialog.show(); break; case DIALOG_SHOW_REQUIRED: AlertDialog.Builder requiredBuilder = new AlertDialog.Builder(this); requiredBuilder.setTitle(R.string.required_fields); requiredBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog showRequiredDialog = requiredBuilder.create(); showRequiredDialog.show(); break; // prompt for unsaved changes case DIALOG_SHOW_PROMPT: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.unsaved_changes)); dialog.setMessage(getString(R.string.want_to_cancel)); dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } // prompt for report deletion case DIALOG_SHOW_DELETE_PROMPT: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.delete_report)); dialog.setMessage(getString(R.string.want_to_delete)); dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // delete checkin deleteCheckins(); dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } } return null; }
From source file:com.pizidea.imagepicker.AndroidImagePicker.java
/** * take picture/* ww w.j a va 2 s . c o m*/ */ public void takePicture(Context ctx, int requestCode) throws IOException { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(ctx.getPackageManager()) != null) { // Create the File where the photo should go //File photoFile = createImageFile(); File photoFile = createImageSaveFile(ctx); // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } } if (ctx instanceof Activity) { ((Activity) ctx).startActivityForResult(takePictureIntent, requestCode); } }
From source file:net.bluecarrot.lite.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setup the sharedPreferences savedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // if the app is being launched for the first time if (savedPreferences.getBoolean("first_run", true)) { //todo presentation // save the fact that the app has been started at least once savedPreferences.edit().putBoolean("first_run", false).apply(); }// w ww . j a v a 2s. c o m setContentView(R.layout.activity_main);//load the layout //**MOBFOX***// banner = (Banner) findViewById(R.id.banner); final Activity self = this; banner.setListener(new BannerListener() { @Override public void onBannerError(View view, Exception e) { //Toast.makeText(self, e.getMessage(), Toast.LENGTH_SHORT).show(); } @Override public void onBannerLoaded(View view) { //Toast.makeText(self, "banner loaded", Toast.LENGTH_SHORT).show(); } @Override public void onBannerClosed(View view) { //Toast.makeText(self, "banner closed", Toast.LENGTH_SHORT).show(); } @Override public void onBannerFinished(View view) { // Toast.makeText(self, "banner finished", Toast.LENGTH_SHORT).show(); } @Override public void onBannerClicked(View view) { //Toast.makeText(self, "banner clicked", Toast.LENGTH_SHORT).show(); } @Override public boolean onCustomEvent(JSONArray jsonArray) { return false; } }); banner.setInventoryHash(appHash); banner.load(); // setup the refresh layout swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container); swipeRefreshLayout.setColorSchemeResources(R.color.officialBlueFacebook, R.color.darkBlueSlimFacebookTheme);// set the colors swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refreshPage();//reload the page swipeRefresh = true; } }); /** get a subject and text and check if this is a link trying to be shared */ String sharedSubject = getIntent().getStringExtra(Intent.EXTRA_SUBJECT); String sharedUrl = getIntent().getStringExtra(Intent.EXTRA_TEXT); // if we have a valid URL that was shared by us, open the sharer if (sharedUrl != null) { if (!sharedUrl.equals("")) { // check if the URL being shared is a proper web URL if (!sharedUrl.startsWith("http://") || !sharedUrl.startsWith("https://")) { // if it's not, let's see if it includes an URL in it (prefixed with a message) int startUrlIndex = sharedUrl.indexOf("http:"); if (startUrlIndex > 0) { // seems like it's prefixed with a message, let's trim the start and get the URL only sharedUrl = sharedUrl.substring(startUrlIndex); } } // final step, set the proper Sharer... urlSharer = String.format("https://m.facebook.com/sharer.php?u=%s&t=%s", sharedUrl, sharedSubject); // ... and parse it just in case urlSharer = Uri.parse(urlSharer).toString(); isSharer = true; } } // setup the webView webViewFacebook = (WebView) findViewById(R.id.webView); setUpWebViewDefaults(webViewFacebook); //fits images to screen if (isSharer) {//if is a share request webViewFacebook.loadUrl(urlSharer);//load the sharer url isSharer = false; } else goHome();//load homepage // webViewFacebook.setOnTouchListener(new OnSwipeTouchListener(getApplicationContext()) { // public void onSwipeLeft() { // webViewFacebook.loadUrl("javascript:try{document.querySelector('#messages_jewel > a').click();}catch(e){window.location.href='" + // getString(R.string.urlFacebookMobile) + "messages/';}"); // } // // }); //WebViewClient that is the client callback. webViewFacebook.setWebViewClient(new WebViewClient() {//advanced set up // when there isn't a connetion public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { String summary = "<h1 style='text-align:center; padding-top:15%; font-size:70px;'>" + getString(R.string.titleNoConnection) + "</h1> <h3 " + "style='text-align:center; padding-top:1%; font-style: italic;font-size:50px;'>" + getString(R.string.descriptionNoConnection) + "</h3> <h5 style='font-size:30px; text-align:center; padding-top:80%; " + "opacity: 0.3;'>" + getString(R.string.awards) + "</h5>"; webViewFacebook.loadData(summary, "text/html; charset=utf-8", "utf-8");//load a custom html page noConnectionError = true; swipeRefreshLayout.setRefreshing(false); //when the page is loaded, stop the refreshing } // when I click in a external link public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url == null || Uri.parse(url).getHost().endsWith("facebook.com") || Uri.parse(url).getHost().endsWith("m.facebook.com") || url.contains(".gif")) { //url is ok return false; } else { if (Uri.parse(url).getHost().endsWith("fbcdn.net")) { //TODO add the possibility to download and share directly Toast.makeText(getApplicationContext(), getString(R.string.downloadOrShareWithBrowser), Toast.LENGTH_LONG).show(); //TODO get bitmap from url Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); return true; } //if the link doesn't contain 'facebook.com', open it using the browser startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } //https://www.facebook.com/dialog/return/close?#_=_ } //START management of loading @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { //TODO when I push on messages, open messanger // if(url!=null){ // if (url.contains("soft=messages") || url.contains("facebook.com/messages")) { // Toast.makeText(getApplicationContext(),"Open Messanger", // Toast.LENGTH_SHORT).show(); // startActivity(new Intent(getPackageManager().getLaunchIntentForPackage("com.facebook.orca")));//messanger // } // } // show you progress image if (!swipeRefresh) { if (optionsMenu != null) {//TODO fix this. Sometimes it is null and I don't know why final MenuItem refreshItem = optionsMenu.findItem(R.id.refresh); refreshItem.setActionView(R.layout.circular_progress_bar); } } swipeRefresh = false; super.onPageStarted(view, url, favicon); } @Override public void onPageFinished(WebView view, String url) { if (optionsMenu != null) {//TODO fix this. Sometimes it is null and I don't know why final MenuItem refreshItem = optionsMenu.findItem(R.id.refresh); refreshItem.setActionView(null); } //load the css customizations String css = ""; if (savedPreferences.getBoolean("pref_blackTheme", false)) { css += getString(R.string.blackCss); } if (savedPreferences.getBoolean("pref_fixedBar", true)) { css += getString(R.string.fixedBar);//get the first part int navbar = 0;//default value int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");//get id if (resourceId > 0) {//if there is navbar = getResources().getDimensionPixelSize(resourceId);//get the dimension } float density = getResources().getDisplayMetrics().density; int barHeight = (int) ((getResources().getDisplayMetrics().heightPixels - navbar - 44) / density); css += ".flyout { max-height:" + barHeight + "px; overflow-y:scroll; }";//without this doen-t scroll } if (savedPreferences.getBoolean("pref_hideSponsoredPosts", false)) { css += getString(R.string.hideSponsoredPost); } //apply the customizations webViewFacebook.loadUrl( "javascript:function addStyleString(str) { var node = document.createElement('style'); node.innerHTML = " + "str; document.body.appendChild(node); } addStyleString('" + css + "');"); //finish the load super.onPageFinished(view, url); //when the page is loaded, stop the refreshing swipeRefreshLayout.setRefreshing(false); } //END management of loading }); //WebChromeClient for handling all chrome functions. webViewFacebook.setWebChromeClient(new WebChromeClient() { //to the Geolocation public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { callback.invoke(origin, true, false); //todo notify when the gps is used } //to upload files //!!!!!!!!!!! thanks to FaceSlim !!!!!!!!!!!!!!! // for >= Lollipop, all in one public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { /** Request permission for external storage access. * If granted it's awesome and go on, * otherwise just stop here and leave the method. */ if (mFilePathCallback != null) { mFilePathCallback.onReceiveValue(null); } mFilePathCallback = filePathCallback; Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // create the file where the photo should go File photoFile = null; try { photoFile = createImageFile(); takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); } catch (IOException ex) { // Error occurred while creating the File Toast.makeText(getApplicationContext(), "Error occurred while creating the File", Toast.LENGTH_LONG).show(); } // continue only if the file was successfully created if (photoFile != null) { mCameraPhotoPath = "file:" + photoFile.getAbsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } else { takePictureIntent = null; } } Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); contentSelectionIntent.setType("image/*"); Intent[] intentArray; if (takePictureIntent != null) { intentArray = new Intent[] { takePictureIntent }; } else { intentArray = new Intent[0]; } Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); chooserIntent.putExtra(Intent.EXTRA_TITLE, getString(R.string.chooseAnImage)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE); return true; } // creating image files (Lollipop only) private File createImageFile() throws IOException { String appDirectoryName = getString(R.string.app_name).replace(" ", ""); File imageStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), appDirectoryName); if (!imageStorageDir.exists()) { //noinspection ResultOfMethodCallIgnored imageStorageDir.mkdirs(); } // create an image file name imageStorageDir = new File(imageStorageDir + File.separator + "IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg"); return imageStorageDir; } // openFileChooser for Android 3.0+ public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { String appDirectoryName = getString(R.string.app_name).replace(" ", ""); mUploadMessage = uploadMsg; try { File imageStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), appDirectoryName); if (!imageStorageDir.exists()) { //noinspection ResultOfMethodCallIgnored imageStorageDir.mkdirs(); } File file = new File(imageStorageDir + File.separator + "IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg"); mCapturedImageURI = Uri.fromFile(file); // save to the private variable final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI); //captureIntent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); Intent chooserIntent = Intent.createChooser(i, getString(R.string.chooseAnImage)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Parcelable[] { captureIntent }); startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE); } catch (Exception e) { Toast.makeText(getApplicationContext(), ("Camera Exception"), Toast.LENGTH_LONG).show(); } } // openFileChooser for other Android versions /** * may not work on KitKat due to lack of implementation of openFileChooser() or onShowFileChooser() * https://code.google.com/p/android/issues/detail?id=62220 * however newer versions of KitKat fixed it on some devices */ public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { openFileChooser(uploadMsg, acceptType); } }); // OnLongClickListener for detecting long clicks on links and images // !!!!!!!!!!! thanks to FaceSlim !!!!!!!!!!!!!!! webViewFacebook.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { // activate long clicks on links and image links according to settings if (true) { WebView.HitTestResult result = webViewFacebook.getHitTestResult(); if (result.getType() == WebView.HitTestResult.SRC_ANCHOR_TYPE || result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) { Message msg = linkHandler.obtainMessage(); webViewFacebook.requestFocusNodeHref(msg); return true; } } return false; } }); // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); }
From source file:li.barter.fragments.EditProfileFragment.java
@Override public void onDialogClick(final DialogInterface dialog, final int which) { if ((mChoosePictureDialogFragment != null) && mChoosePictureDialogFragment.getDialog().equals(dialog)) { if (which == 0) { // Pick from camera final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraImageCaptureUri); try { startActivityForResult(Intent.createChooser(intent, getString(R.string.complete_action_using)), PICK_FROM_CAMERA); } catch (final ActivityNotFoundException e) { e.printStackTrace();/* w w w . java 2s . c om*/ } } else if (which == 1) { // pick from file final Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, getString(R.string.complete_action_using)), PICK_FROM_FILE); } } else { super.onDialogClick(dialog, which); } }
From source file:chinanurse.cn.nurse.Fragment_Nurse_job.IdentityFragment_ACTIVITY.java
protected void ShowPickDialog() { new AlertDialog.Builder(activity, AlertDialog.THEME_HOLO_LIGHT) .setNegativeButton("", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss();// w ww . jav a 2 s . c om Intent intentFromGallery = new Intent(); intentFromGallery.setType("image/*"); // intentFromGallery.setAction(Intent.ACTION_PICK); startActivityForResult(intentFromGallery, PHOTO_REQUEST_ALBUM); } }).setPositiveButton("?", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); Intent intentFromCapture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // ???? String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_MOUNTED)) { File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); File file = new File(path, "newpic.jpg"); intentFromCapture.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); } startActivityForResult(intentFromCapture, PHOTO_REQUEST_CAMERA); } }).show(); }
From source file:net.jongrakko.zipsuri.activity.PostReviseActivity.java
private void takeImage() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); takeFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Zisuri_tmp_" + System.currentTimeMillis() + ".jpg"); Uri saveUri = Uri.fromFile(takeFile); intent.putExtra(MediaStore.EXTRA_OUTPUT, saveUri); // set the image file name startActivityForResult(intent, TAKE_PHOTO_FOR_AVATAR); }
From source file:com.cm.android.beercellar.ui.ImageGridFragment.java
/** * @author anshu//from w w w . ja v a 2 s. co m */ public void takePhoto() throws IOException { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) { File photoFile = null; try { photoFile = Utils.createImageFile(getActivity()); } catch (IOException ex) { // Error occurred while creating the File Log.e("takePhoto", ex.toString()); } // Continue only if the File was successfully created if (photoFile != null) { getActivity().getSharedPreferences(Utils.SHARED_PREF_NAME, Context.MODE_PRIVATE).edit() .putString("IMAGE_NAME", photoFile.getName()).commit(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); } } }
From source file:foam.littlej.android.app.ui.phone.AddCheckinActivity.java
/** * Create various dialog/*from w w w . j a v a 2 s. c o m*/ */ @Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_ERROR_NETWORK: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.network_error)); dialog.setMessage(getString(R.string.network_error_msg)); dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } case DIALOG_ERROR_SAVING: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.network_error)); dialog.setMessage(getString(R.string.file_system_error_msg)); dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } case DIALOG_CHOOSE_IMAGE_METHOD: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.choose_method)); dialog.setMessage(getString(R.string.how_to_select_pic)); dialog.setButton(getString(R.string.gallery_option), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { deleteExistingPhoto(); Intent intent = new Intent(); intent.setAction(Intent.ACTION_PICK); intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, REQUEST_CODE_IMAGE); dialog.dismiss(); } }); dialog.setButton2(getString(R.string.cancel), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setButton3(getString(R.string.camera_option), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { deleteExistingPhoto(); Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, PhotoUtils.getPhotoUri(photoName, AddCheckinActivity.this)); startActivityForResult(intent, REQUEST_CODE_CAMERA); dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } case DIALOG_SHOW_MESSAGE: AlertDialog.Builder messageBuilder = new AlertDialog.Builder(this); messageBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog showDialog = messageBuilder.create(); showDialog.show(); break; case DIALOG_SHOW_REQUIRED: AlertDialog.Builder requiredBuilder = new AlertDialog.Builder(this); requiredBuilder.setTitle(R.string.required_fields); requiredBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog showRequiredDialog = requiredBuilder.create(); showRequiredDialog.show(); break; // prompt for unsaved changes case DIALOG_SHOW_PROMPT: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.unsaved_changes)); dialog.setMessage(getString(R.string.want_to_cancel)); dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // delete any existing photo in the pending folder new DiscardTask(AddCheckinActivity.this).execute((String) null); finish(); dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } // prompt for report deletion case DIALOG_SHOW_DELETE_PROMPT: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.delete_report)); dialog.setMessage(getString(R.string.want_to_delete)); dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // delete checkin deleteCheckins(); dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } } return null; }