I would like to import files from Installed Google Drive App to my app using the Intent.ACTION_GET_CONTENT
and the mimetype of the intent set to "*/*".
I am able to do this with other installed app like Dropbox,Onedrive and box, but not with Google Drive.
Here is my code :
Intent action = new Intent(Intent.ACTION_GET_CONTENT);
action.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(Intent.createChooser(action, "Upload file from..."),Constants.FILE_CHOOSER_REQUEST_CODE );
Thanks.
Very late answer but you need to remove action.putExtra(Intent.EXTRA_LOCAL_ONLY, true); in order to see Google Drive option in the picker.
Related
I am trying to open a directory for user to choose an excel document from it.
However, my file picker opens in the "recent" location.
Is there a way to start it from a specific directory using new versions of Android?
This is my code:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.DIRECTORY_DOCUMENTS);
intent.setDataAndType(uri, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
startActivity(Intent.createChooser(intent, "Open folder"));
You need to set EXTRA_INITIAL_URI:
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri)
Unfortunately, the Intent.ACTION_GET_CONTENT does not support opening in a specific location. The only way to choose a specific location is by using a third-party file picker library, such as FilePicker, aFileChooser, etc.
You can use these libraries to create a custom file picker that opens in a specific location and allows the user to choose a file. Then, you can call the custom file picker in your code instead of using Intent.ACTION_GET_CONTENT.
Note: all type of files
I used default Gallery Intent to show to storage but it shows the Goggle Drive Option along with local Storage
I tried the following referals but nothing works for me.
Ref:
How to let user select only local files using Intent in Android?
2 .https://stackoverflow.com/questions/27762377/android-why-intent-extra-local-only-shows-google-photos
Is it possible to hide google drive while using Intent.ACTION_GET_CONTENT in android?
Used another library, to show the only local storage, it works fine
but Requirement is, Need to show only local storage and its all file types along with file size which is not available in this library.
Kindly suggest some other library like below with showing file size
Ref:
https://github.com/codekidX/storage-chooser
https://androidexample365.com/lets-user-choose-files-in-internal-or-external-storage-with-just-few-lines-of-code/
Use the below code that will help you achieve the desired results:
val selectedUri =
Uri.parse(Environment.getExternalStorageDirectory().toString() + "/Pictures")
val intent = Intent(Intent.ACTION_PICK)
intent.data = selectedUri
intent.type = "image/*"
if (intent.resolveActivityInfo(context!!.packageManager, 0) != null) {
startActivityForResult(
intent,
101
)
} else {
// if you reach this place, it means there is no any file
// explorer app installed on your device
}
I tried picking a file from the internal or external storage with the code below:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, 1);
Of course it has onActivityResult method, and it's not the problem. It works fine in the modern phones or phones that have file manager installed. But the old one with no file manager throws
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT typ=file/* }
I tried switching to ACTION_PICK but no luck. I also tried intent.setType("*/*");, it didn't crash but the popup ask for action (videos, contacts,...) which is not true. I just want to pick any file not just a specified type.
I don't want to use any other file manager just to pick a file. Is there anyway I can get through this?
I believe that having the error explained, makes the solution much easier. So let me explain it to you:
You're starting an implicit intent. That means it's an intent that you know what you want to happen (use select a file) and you don't care which application will do it.
The error you're encountering is simply the system telling you (the developer), that there's no application installed that is capable of doing it (neither system nor 3rd party). There's simply no one capable of handling the action you want.
So you have two options from what I can see:
try-catch the error
.
try {
startActivityForResult(intent, 1);
} catch (ActivityNotFoundException e) {
// maybe you should show a toast to the user here?
Toast.makeText(context, "You need to install a file picker", Toast.LENGTH_SHORT).show();
// or maybe redirect to a 3rd party app that you know works
startIntent(new Intent(Uri.parse("https://play.google.com/... some app
}
you can find a library or code to pick the file from inside your own app: http://bit.ly/1N1fZbO
Below code section should work for you!
Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
chooseFile.setType("*/*");
Intent intent = Intent.createChooser(chooseFile, "Choose a file");
startActivityForResult(intent, ACTIVITY_CHOOSE_FILE);
What's your Android version? Some android maybe not released with such activity.
I am developing in Android , and I want to implement a text file select.
I have install es file manager App in my Android phone.
I add the permission :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> , and I try the following code:
Intent intent = new Intent( Intent.ACTION_PICK );
intent.setType( "text/*" );
Intent destIntent = Intent.createChooser( intent, "Select File" );
startActivityForResult( destIntent, 0 );
But it didn't open the file manager and list the file let me choose.
Did I missing something ?
Thanks in advance.
Android Default file manager cant handle this Intent Intent.ACTION_GET_CONTENT. You have to install es file explorer or similar file manager apps form app store in your device to open that intent.
I'm trying to use PackageManager to detect if Google navigation installed on a phone. If I use "URI = google.navigation" it doesn't find it.
What is the proper name for this package?
Also, I found sample on how to call google navigation with intent but I didn't find how to format full address with Address/city/state/zip. Any samples around?
For the US this works ...
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("google.navigation:q=housenumber+street+city+state+zip+country");
Spaces are ok between the + symbol