I am working on Android application in which I am taking picture from camera. I just want to set my camera orientation to be portrait. My code is given below from where I am sending request to OnActivityResult:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
ContentValues values = new ContentValues(3);
values.put(MediaStore.Images.Media.DISPLAY_NAME, "testing");
values.put(MediaStore.Images.Media.DESCRIPTION, "this is description");
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
imageFilePath = UserInfoActivity.this.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
startActivityForResult(intent, 0);
Add these lines in your code
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
startActivityForResult(intent,CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
Add these lines in your Manifest.XML
<activity
android:name="ActivityName"
android:screenOrientation="portrait"
android:configChanges="orientation" >
</activity>
Related
I am using camera intent for capturing selfie but by default it open back camera and I want front camera by default.
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, 101);
Add the following line:
cameraIntent.putExtra("android.intent.extras.CAMERA_FACING", 1)
Although, it doesn't seem to always work. But it's the best you can get using just intents.
I'm using this code to open camera intent :
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePicture.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
startActivityForResult(takePicture, 0);
And it works fine but only on Samsung devices (8\9) with android 8
after I take a picture the preview is all blurry ,
anyone got that weird behavior ?
( I also tried without the putExtra line )
Here are the screenshots :
]3
you have to give a photo path Uri as an extra in the camera intent as:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), mUserID + ".jpg");
Uri photoPath = getUriForFile(mContext, BuildConfig.APPLICATION_ID, file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoPath); //--> here
startActivityForResult(Intent.createChooser(intent, "Complete action using"), REQUEST_CODE_CAMERA);
then, you can get the captured image in that Uri itself in onActivityResult
I am trying to create my own wallpaper app and I can't figure out how to start this intent?
What is this intent? How do I pass image to device default wallpaper app?
Try following code snippet:
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);//add this if your targetVersion is more than Android 7.0+
intent.setDataAndType(uri, "image/jpeg");
intent.putExtra("mimeType", "image/jpeg");
this.startActivity(Intent.createChooser(intent, "Set as:"));
PS:uri should get from FileProvider in Android 7.0+ if your targetVersion is more than7.0+
You could try this:
private void startWallpaper(){
final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Intent chooser = Intent.createChooser(pickWallpaper,"set wallpaeper");
startActivity(chooser);
}
ref is here
In your manifest file:
<uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>
If you want to pass own img, could do like below:
WallpaperManager wpm = WallpaperManager.getInstance(context);
InputStream ins = new URL("absolute/path/of/image").openStream();
wpm.setStream(ins);
I am using the following code to set the wallpaper from an image in a drawable:
Intent setAsIntent = new Intent();
setAsIntent.setDataAndType(uri, "image/*");
setAsIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
setAsIntent.setAction("android.intent.action.ATTACH_DATA");
Intent chooserIntent = Intent.createChooser(
setAsIntent, "set as");
But when startActivity, it only shows a message:
No apps can perform this action
I did discover a workaround:
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setDataAndType(uri, "image/jpeg");
intent.putExtra("mimeType", "image/jpeg");
this.startActivity(Intent.createChooser(intent, "Set as:"));
or try to use
WallpaperManager
wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
mImageView.setImageURI(imagepath);
If you have image bitmap then use this
wallpaperManager.setBitmap(useThisBitmap);
In your manifest file:
<uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>
The following code allows me to take pictures, however it does not insert the image into the db. What am I missing?
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
ContentValues values = new ContentValues();
values.put(Media.TITLE, "Image");
values.put(Images.Media.BUCKET_ID, "292");
values.put(Images.Media.BUCKET_DISPLAY_NAME, "thename");
values.put(Images.Media.MIME_TYPE, "image/jpeg");
values.put(Media.DESCRIPTION, "Image capture by camera");
values.put("_data", IMG_FILE_PATH);
Uri uri = getContentResolver().insert( Media.EXTERNAL_CONTENT_URI , values);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri);
i.putExtra("return-data", true);
startActivityForResult(i,REQ_PHOTO);
Uri uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new ContentValues());
Intent imageIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(imageIntent, REQUEST_CODE_CAPTURE_IMAGE_ACTIVITY);
Try just using this code. It seems like you overwriting _data is causing issues when Android tries to store the image.