i want to open a specific folder from menu drawer in android app but when i run the app it open recent files folder.
this is my code
if (id == R.id.action_downloaded) {
if (PermissionUtilities.isPermissionGranted(mActivity, PermissionUtilities.SD_READ_WRITE_PERMISSIONS, PermissionUtilities.REQUEST_READ_WRITE_STORAGE_DOWNLOAD)) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory() + "/" + myfolder + "/");
intent.setDataAndType(uri, "application/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(Intent.createChooser(intent, "Select Pdf"), 1000);
}
Put as extra INITIAL_URI on your intent an uri the user choosed before with ACTION_GET_CONTENT.
Related
I try to click on a menu item with the help of this method to open a specific folder that the app creates in internal memory when .txt file is recorded, but this is not possible even though the folder exists. Can you help me when I click the menu item to open MyFolder, please.
switch (item.getItemId()) {
case R.id.openFolder:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()
+ "/MyFolder/");
intent.setDataAndType(uri, "text/csv");
startActivity(Intent.createChooser(intent, "Open folder"));
break;
}
First of all, I would check if there is some file explorer on the system that would handle a request of opening directories this is an example.
Then your code should be modified to:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/MyFolder/");
intent.setDataAndType(uri, "*/*");
startActivity(Intent.createChooser(intent, "Open folder"));
also you may create the uri like this and I am not sure why this prefix is needed sometimes, maybe someone can explain to us:
Uri uri = Uri.parse("file://" + Environment.getExternalStorageDirectory().getPath()+ "/MyFolder/");
When I send user to open a link in a browser, can I force the user to select from their available browsers, without using their default browser?
Try this:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
String title = "Select a browser";
Intent chooser = Intent.createChooser(intent, title);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
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.
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())));
}
My goal is to upload a specific videofile to youtube from my app.
Here some code from my Method:
File videoToPlayFile = new File(mSharedPreferences.getString("output_file", ""));
Intent intent = new Intent();
intent.setDataAndType(Uri.fromFile(videoToPlayFile), "video/*");
Intent intent2 = YouTubeIntents.createUploadIntent(this,intent.getData());
startActivity(intent2);
I get the error that the Uri path from intent.getData needs to begin with content://media, but when I take Logs it allways showas a path like file://mnt/sdcard/blablabla.mp4