Set orientation when picking a file from gallery - java

Currently I'm picking a file (Video) from the Gallery by doing:
private void selectVideo() {
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Video"), REQUEST_TAKE_GALLERY_VIDEO);
}
The above will open the Gallery and let the user select a file, this works perfect.
My question:
Is there a way to set a fixed orientation of the Gallery when the user selects a file? I can't find any information about this, is this even possible?

Related

How to pass a Uri of a recorded video which is stored in mobile device to another activity

I am trying to pass the Uri of a recorded video from my android mobile device to SecondActivity, but not able to get the uri.
Please suggest.
MainActivity.java
viewModel.filePaths = new ArrayList<>();
viewModel.filePaths.add(uri);
customDialogBuilder.showLoadingDialog();
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("file_content", viewModel.filePaths);
startActivity(intent);
MainViewModel.java
public List<Uri> filePaths = new ArrayList<>();
SecondActivity.java
viewModel.filePaths = (ArrayList<Uri>) getIntent().getSerializableExtra("file_content");
SecondViewModel.java
public List<Uri> filePaths;
Edit :
Actually the Url is for a Video file which I have recorded from camera and store to my device. I want to pass this recorded video path to SecondActivity, but it's showing blank screen on UI and null values in 2nd Activity

Open multiple images in gallery intent

I need to open multiple images in gallery to view by sliding...
I know how to open 1 image..
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");
startActivity(intent);
How can i view multiple images to view them all by sliding in a single intent.?
I have the path of the images... And i need to view them in gallery.
The EXTRA_ALLOW_MULTIPLE option is set on the intent through the Intent.putExtra() method to select multiple images
Multiple Image selection available only for above API 18
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
Full intent code is here:
Intent intent = new Intent(); intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"),1);
You can straight away show multiple images by accessing into your device's default gallery app.
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
There are 2 ways to implement multi-selection of images in gallery:
1.Intent for getting multiple images
2.Define custom gallery with fetching and loading photos from native gallery.
Intent for getting multiple images:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);
For implementation of gallery see this link: http://www.technotalkative.com/android-select-multiple-photos-from-gallery/
it fetches multiple images and shows them in a gridview
No you cant do that.... You need to create a new view activity

issue to select a PDF file from my mobile

i need to choose a pdf file on my mobile and upload the pdf file on a server, but i get this:" no application can perform this action"..why?
this is my code when i click on "select pdf file":
private void showFileChooser() {
Intent intent = new Intent();
intent.setType("application/pdf");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Pdf"), PICK_PDF_REQUEST);
}
You need to install some file explorers on your device first.

Error loading image from presistent Uri

The program flow is that the user selects an image from the gallery and it is displayed in an image view. This works fine. At the same time, the Uri is written to a database.
Later, when the program is run again or that activity is displayed again, the Uri is retrieved from the database and the image is displayed again. This second showing of the image is what causes the exception:
requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
I added the permission to the manifest and the exception still occurs.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
The same procedure attempts to display both images, and it works when it comes from the picker, but fails when it comes from the presistent Uri from the database.
Picker Intent
try {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent, "Select Picture"),
PICK_IMAGE);
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"Error",
Toast.LENGTH_LONG).show();
Log.e(e.getClass().getName(), e.getMessage(), e);
}
With the result from the picker intent I use
Uri selectedImageUri = data.getData();
With the database read I use. localImage is a String.
Uri.parse(localImage)
I read this bug report https://issues.apache.org/jira/browse/CB-5398, but I'm not sure how to use it to resolve this situation. The code below from another thread seems to attempt to resolve a similar issue with permissions and the photo picker, but in my case I'm not picking again, I just need to display the image from the Uri.
I guess it is a matter of resetting permissions. I'm not really sure. I have the permissions in the manifest. Perhaps I need different code to display an image from a Uri not obtained from the picker? Maybe I need to target a different API? My build.gradle says targetSdkVersion 21, minSdkVersion 15. These were the defaults. I'm in Android Studio 1.0.2.
I'm stumped. Any help is appreciated.
public static final String KITKAT_VALUE = 1002;
Intent intent;
if (Build.VERSION.SDK_INT < 19){
intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, KITKAT_VALUE);
} else {
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, KITKAT_VALUE);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == KITKAT_VALUE ) {
if (resultCode == Activity.RESULT_OK) {
// do something here
}
}
}
At the same time, the Uri is written to a database.
That's not going to work prior to API Level 19, and then only if you are using the Storage Access Framework (ACTION_OPEN_DOCUMENT) and take the offered persistent permissions. Given your existing code, the temporary permissions that you are granted for that Uri will expire, at the latest when your process is terminated.
I added the permission to the manifest and the exception still occurs.
You cannot hold MANAGE_DOCUMENTS, unless you are signed by the signing key that signed the firmware.

Android gallery not updated after ACTION_IMAGE_CAPTURE

I'm using MediaStore.ACTION_IMAGE_CAPTURE to take a picture with MediaStore.EXTRA_OUTPUT to point to the Uri for the DCIM/Camera directory where all the other photo/video files are stored.
The photo file is successfully taken and I can see it using ES File Explorer and can view it inside my app. However it is not shown in the gallery when I use Intent.ACTION_PICK
Intent selectPictureIntent = new Intent(Intent.ACTION_PICK);
selectPictureIntent.setType("image/*");
I've read the other topics on updating the Gallery after the picture comes back using
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
and also
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, _outputMediaUri);
LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(intent);
What's going on here :(
why did you use LocalBroadcastManager? LocalBroadcastManager can only send broadcast data inside of your app. Try to use
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, _outputMediaUri);
sendBroadcast(intent);
Gallery always listens to URI change. After file event broadcast to Gallery, the data stored in Gallery will be updated.
it also can problem with KITKAT build version.. for sure you can use this code:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Intent mediaScanIntent = new Intent(
Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.fromFile(out); \\out is your output file
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
} else {
sendBroadcast(new Intent(
Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));
}

Categories

Resources