List of usage examples for android.provider MediaStore ACTION_IMAGE_CAPTURE
String ACTION_IMAGE_CAPTURE
To view the source code for android.provider MediaStore ACTION_IMAGE_CAPTURE.
Click Source Link
From source file:com.cloverstudio.spika.CameraCropActivity.java
public void startCamera() { // Check if camera exists if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) { Toast.makeText(this, "No camera on device", Toast.LENGTH_LONG).show(); finish();// ww w. j a va 2 s. c o m } else { try { long date = System.currentTimeMillis(); String filename = DateFormat.format("yyyy-MM-dd_kk.mm.ss", date).toString() + ".jpg"; _path = this.getExternalCacheDir() + "/" + filename; File file = new File(_path); // File file = new File(getFileDir(getBaseContext()), filename); Uri outputFileUri = Uri.fromFile(file); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); startActivityForResult(intent, CAMERA); } catch (Exception ex) { Toast.makeText(this, "No camera on device", Toast.LENGTH_LONG).show(); finish(); } } }
From source file:com.mk4droid.IMC_Activities.Fragment_NewIssueA.java
/** * OnCreateView //w w w . j a v a 2 s. c om */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { flagStarter = true; FActivity_TabHost.IndexGroup = 2; vfrag_nIssueA = inflater.inflate(R.layout.fragment_newissue_a, container, false); mfrag_nIssueA = this; ctx = this.getActivity(); //-------- tvUnauth ---- llUnauth = (LinearLayout) vfrag_nIssueA.findViewById(R.id.llUnauth); Button gotoSetup = (Button) llUnauth.findViewById(R.id.bt_nia_gosetup); gotoSetup.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { getActivity().finish(); // Check if Activity Splash Already open if (Activity_Splash_Login.et_username == null) { Log.e("NIA", "SPLASH WAS NULL"); startActivity(new Intent(ctx, Activity_Splash_Login.class)); } getActivity().finish(); } }); //---- Spinner ----- ArrayList<Category> mCatL_Sorted = SortCategList(Service_Data.mCategL); SpinnerArrString = initSpinner(mCatL_Sorted); sp = (Spinner) vfrag_nIssueA.findViewById(R.id.spinnerCateg); adapterSP = new SpinnerAdapter_NewIssueCateg(getActivity(), //--- Set spinner adapter -- android.R.layout.simple_spinner_item, mCatL_Sorted); sp.setAdapter(adapterSP); sp.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View arg1, int arg2, long arg3) { if (flagStarter) { flagStarter = false; } else { spPosition = arg2; } } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); //--------- Title ----- et_title = (EditText) vfrag_nIssueA.findViewById(R.id.etTitle_ni); if (et_title != null) if (et_title.getText().toString().length() > 0) titleData_STR = et_title.getText().toString(); if (titleData_STR.length() > 0) et_title.setText(titleData_STR); //------ Description ---- et_descr = (EditText) vfrag_nIssueA.findViewById(R.id.etDescription); if (et_descr != null) if (et_descr.getText().toString().length() > 0) descriptionData_STR = et_descr.getText().toString(); //------- Bt Attach image --- btAttachImage = (ImageButton) vfrag_nIssueA.findViewById(R.id.btAttach_image); //-------- Bt Proceed ----- btProceed = (Button) vfrag_nIssueA.findViewById(R.id.btProceed_ni_B); mshPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); resources = SetResources(); //--------- Layout ------- llnewissue_a = (LinearLayout) vfrag_nIssueA.findViewById(R.id.llnewissue_a); llnewissue_a.setVisibility(View.VISIBLE); //-------- Take Image button ------- if (flagPictureTaken && Image_BMP != null) { btAttachImage.setScaleType(ScaleType.CENTER_CROP); try { btAttachImage.setImageBitmap(Image_BMP); } catch (Exception e) { // if the btAttachImage was null set Image with some delay btAttachImage.postDelayed(new Runnable() { @Override public void run() { btAttachImage.setImageBitmap(Image_BMP); } }, 1000); } ; } else { btAttachImage.setScaleType(ScaleType.CENTER_INSIDE); btAttachImage.setImageResource(R.drawable.bt_custom_camera_round); //R.drawable.pattern_camera_repeater)); } btAttachImage.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(FActivity_TabHost.resources.getString(R.string.Attachanimage)); builder.setIcon(android.R.drawable.ic_menu_gallery); // 1 select builder.setPositiveButton(FActivity_TabHost.resources.getString(R.string.Gallery), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); Intent intent = new Intent(); intent.setType("image/jpeg"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE); } }); // 2 Shoot builder.setNeutralButton(FActivity_TabHost.resources.getString(R.string.Camera), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); // 2 shoot fimg = new File(image_path_source_temp); Uri uri = Uri.fromFile(fimg); Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri); startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); } }); // 3 clear builder.setNegativeButton(FActivity_TabHost.resources.getString(R.string.Clear), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //dialog.cancel(); flagPictureTaken = false; File imagef = new File(image_path_source_temp); imagef.delete(); dialog.dismiss(); //btAttachImage.setCompoundDrawablesWithIntrinsicBounds( 0, R.drawable.bt_custom_camera_round, 0, 0); btAttachImage.setScaleType(ScaleType.CENTER_INSIDE); btAttachImage.setImageResource(R.drawable.bt_custom_camera_round); // btAttachImage.setPadding(0, 40, 0, 0); } }); builder.create(); builder.show(); } }); //------------- button Proceed ---------- btProceed.setOnClickListener(new OnClickListener() { @Override public void onClick(View vBt) { // Check if title is long enough and sent if (et_title.getText().toString().length() > 2 && spPosition != -1 && et_descr.getText().toString().length() > 2) { // RRR titleData_STR = et_title.getText().toString(); if (et_descr.getText().toString().length() > 0) descriptionData_STR = et_descr.getText().toString(); // Close Keyboard InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Service.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(et_title.getWindowToken(), 0); imm.hideSoftInputFromWindow(et_descr.getWindowToken(), 0); // Instantiate a new fragment. mfrag_nIssueB = new Fragment_NewIssueB(); Bundle args = new Bundle(); args.putInt("IndexSpinner", sp.getSelectedItemPosition()); mfrag_nIssueB.setArguments(args); // Add the fragment to the activity, pushing this transaction // on to the back stack. FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); ft.add(mfrag_nIssueA.getId(), mfrag_nIssueB, "FTAG_NEW_ISSUE_B"); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.addToBackStack(null); ft.commit(); } else if (spPosition == -1) { Toast.makeText(getActivity(), resources.getString(R.string.SelectaCategory), tlv).show(); } else if (et_title.getText().toString().length() <= 2) { Toast.makeText(getActivity(), resources.getString(R.string.LongerTitle), tlv).show(); } else if (et_descr.getText().toString().length() <= 2) { Toast.makeText(getActivity(), resources.getString(R.string.LongerDescription), tlv).show(); } } }); return vfrag_nIssueA; }
From source file:com.zlkj.dingdangwuyou.activity.CompanyInfoActivity.java
/** * ?/* w w w . j a v a2 s .c om*/ */ private void showAvatarOption() { AlertDialog.Builder builder = new AlertDialog.Builder(this); String[] items = new String[] { "?", "" }; builder.setTitle("").setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(); switch (which) { case 0: // ? if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { String curTime = AppTool.dateFormat(System.currentTimeMillis(), "yyyyMMddHHmmss"); // ??? File imagePath = new File(Environment.getExternalStorageDirectory() + Const.APP_IMAGE_PATH); if (!imagePath.exists()) { imagePath.mkdirs(); } cameraFile = new File(imagePath.getPath(), curTime + ".jpg"); intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraFile)); startActivityForResult(intent, Const.REQUEST_CODE_CAMERA); } else { Toast.makeText(context, "???", Toast.LENGTH_SHORT) .show(); } break; case 1: // intent.setAction(Intent.ACTION_PICK); intent.setType("image/*"); startActivityForResult(intent, Const.REQUEST_CODE_GALLERY); break; default: break; } } }); builder.show(); }
From source file:com.insthub.O2OMobile.Activity.F9_SettingActivity.java
private void showDialog() { LayoutInflater inflater = LayoutInflater.from(this); View view = inflater.inflate(R.layout.photo_dialog, null); mDialog = new Dialog(this, R.style.dialog); mDialog.setContentView(view);/* w w w. j a v a2 s .c o m*/ mDialog.setCanceledOnTouchOutside(true); mDialog.show(); LinearLayout requsetCameraLayout = (LinearLayout) view.findViewById(R.id.register_camera); LinearLayout requestPhotoLayout = (LinearLayout) view.findViewById(R.id.register_photo); requsetCameraLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub mDialog.dismiss(); if (mFileDir == null) { mFileDir = new File(O2OMobileAppConst.FILEPATH + "img/"); if (!mFileDir.exists()) { mFileDir.mkdirs(); } } mFileName = O2OMobileAppConst.FILEPATH + "img/" + "temp.jpg"; mFile = new File(mFileName); Uri imageuri = Uri.fromFile(mFile); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, imageuri); intent.putExtra("return-data", false); startActivityForResult(intent, REQUEST_CAMERA); } }); requestPhotoLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub mDialog.dismiss(); Intent picture = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(picture, REQUEST_PHOTO); } }); }
From source file:com.bwash.bwashcar.activities.CompanyActivity.java
private void takePhoto() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN // Permission was added in API Level 16 && ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { requestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, getString(R.string.permission_write_storage_rationale), REQUEST_STORAGE_WRITE_ACCESS_PERMISSION); } else {//from www . j a v a2 s .c om mSelectPicturePopupWindow.dismissPopupWindow(); Intent takeIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //???? takeIntent.putExtra(MediaStore.EXTRA_OUTPUT, sourceUri); startActivityForResult(takeIntent, CAMERA_REQUEST_CODE); } }
From source file:de.bahnhoefe.deutschlands.bahnhofsfotos.DetailsActivity.java
public void takePicture() { if (!canSetPhoto()) { return;//w w w .ja va 2 s .com } if (isMyDataIncomplete()) { checkMyData(); } else { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File file = getCameraMediaFile(); if (file != null) { Uri photoURI = FileProvider.getUriForFile(this, "de.bahnhoefe.deutschlands.bahnhofsfotos.fileprovider", file); intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); intent.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, getResources().getString(R.string.app_name)); intent.putExtra(MediaStore.EXTRA_MEDIA_TITLE, bahnhof.getTitle()); intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivityForResult(intent, REQUEST_TAKE_PICTURE); } else { Toast.makeText(this, R.string.unable_to_create_folder_structure, Toast.LENGTH_LONG).show(); } } }
From source file:com.ranglerz.tlc.tlc.com.ranglerz.tlc.tlc.ReportAccident.ReportAccidentForm.java
private void cameraIntent() { // Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // startActivityForResult(intent, REQUEST_CAMERA); ///* www.j a va 2 s .c o m*/ ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, "New Picture"); values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera"); imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); startActivityForResult(intent, REQUEST_CAMERA); }
From source file:net.bluehack.ui.WallpapersActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle(LocaleController.getString("ChatBackground", R.string.ChatBackground)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override//ww w . ja v a2s. c o m public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { boolean done; TLRPC.WallPaper wallPaper = wallpappersByIds.get(selectedBackground); if (wallPaper != null && wallPaper.id != 1000001 && wallPaper instanceof TLRPC.TL_wallPaper) { int width = AndroidUtilities.displaySize.x; int height = AndroidUtilities.displaySize.y; if (width > height) { int temp = width; width = height; height = temp; } TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, Math.min(width, height)); String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg"; File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName); File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg"); try { done = AndroidUtilities.copyFile(f, toFile); } catch (Exception e) { done = false; FileLog.e("tmessages", e); } } else { if (selectedBackground == -1) { File fromFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper-temp.jpg"); File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg"); done = fromFile.renameTo(toFile); } else { done = true; } } if (done) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("selectedBackground", selectedBackground); editor.putInt("selectedColor", selectedColor); editor.commit(); ApplicationLoader.reloadWallpaper(); } finishFragment(); } } }); ActionBarMenu menu = actionBar.createMenu(); doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56)); FrameLayout frameLayout = new FrameLayout(context); fragmentView = frameLayout; backgroundImage = new ImageView(context); backgroundImage.setScaleType(ImageView.ScaleType.CENTER_CROP); frameLayout.addView(backgroundImage, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); backgroundImage.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); progressView = new FrameLayout(context); progressView.setVisibility(View.INVISIBLE); frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 52)); progressViewBackground = new View(context); progressViewBackground.setBackgroundResource(R.drawable.system_loader); progressView.addView(progressViewBackground, LayoutHelper.createFrame(36, 36, Gravity.CENTER)); ProgressBar progressBar = new ProgressBar(context); try { progressBar.setIndeterminateDrawable(context.getResources().getDrawable(R.drawable.loading_animation)); } catch (Exception e) { //don't promt } progressBar.setIndeterminate(true); AndroidUtilities.setProgressBarAnimationDuration(progressBar, 1500); progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER)); RecyclerListView listView = new RecyclerListView(context); listView.setClipToPadding(false); listView.setTag(8); listView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), 0); LinearLayoutManager layoutManager = new LinearLayoutManager(context); layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); listView.setLayoutManager(layoutManager); listView.setDisallowInterceptTouchEvents(true); listView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER); listView.setAdapter(listAdapter = new ListAdapter(context)); frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 102, Gravity.LEFT | Gravity.BOTTOM)); listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (position == 0) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("Cancel", R.string.Cancel) }; builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { try { if (i == 0) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File image = AndroidUtilities.generatePicturePath(); if (image != null) { if (Build.VERSION.SDK_INT >= 24) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", image)); takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image)); } currentPicturePath = image.getAbsolutePath(); } startActivityForResult(takePictureIntent, 10); } else if (i == 1) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, 11); } } catch (Exception e) { FileLog.e("tmessages", e); } } }); showDialog(builder.create()); } else { if (position - 1 < 0 || position - 1 >= wallPapers.size()) { return; } TLRPC.WallPaper wallPaper = wallPapers.get(position - 1); selectedBackground = wallPaper.id; listAdapter.notifyDataSetChanged(); processSelectedBackground(); } } }); processSelectedBackground(); return fragmentView; }
From source file:com.IntimateCarCare.MainActivity.java
private void choseHeadImageFromCameraCapture() { Intent intentFromCapture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // ???/*from w w w. ja v a 2s. c om*/ if (hasSdcard()) { intentFromCapture.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), IMAGE_FILE_NAME))); } startActivityForResult(intentFromCapture, CODE_CAMERA_REQUEST); }
From source file:cn.edu.nuc.seeworld.fg.ColorFragment.java
private void getpicfromcamera() { Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(camera, CAMERA); }