Selecting a csv file from storage in android - android

Hello I wish to upload a csv file in android but somehow this code segment doesn't work for csv file.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/csv");
startActivityForResult(intent, OPEN_REQUEST_CODE);

You should probably use ACTION_GET_CONTENT instead of ACTION_OPEN_DOCUMENT, and you'll need to add CATEGORY_OPENABLE to the Intent.
See the selected answer at Android Intent choose CSV for import

Related

How to create a file from intent uri in android 11

I am trying to pick a file like docs or pdf from my app and send the file to my server using okhttp. I am getting a uri from using an intent
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, FILE_PICKER_REQUEST_CODE);
I am unable to get the full path of the file for creating a file.
I need paths like this
/storage/emulated/0/document/admin.pdf
All I need is a file that I can send to the server by any means.Help please.

Error in creating a folder using Storage Access Framework

I am using Storage Access Framework and want to create a folder (location choosed by user through file picker) but instead it is creating a file without any extension.
I am using ACTION_CREATE_DOCUMENT for this, you can check the intent call below:
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.setType("application/vnd.google-apps.folder");
intent.putExtra(Intent.EXTRA_TITLE, "CCM-Tele ICU");
startActivityForResult(intent, MAKE_DIRECTORY_REQUEST_ID);
But instead of folder it is creating this:
I have tried creating files and it works fine but unfortunately, folder is not being created.
I solved the problem of directory creation so answering my own question maybe it will help someone in future.
The Mime type that I was using is incorrect. So change it to: DocumentsContract.Document.MIME_TYPE_DIR
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.setType(DocumentsContract.Document.MIME_TYPE_DIR);
intent.putExtra(Intent.EXTRA_TITLE, "CCM-Tele ICU");
startActivityForResult(intent, MAKE_DIRECTORY_REQUEST_ID);
But it's useless as I can't use it to store things afterwards using SAF. So it's better to use ACTION_OPEN_DOCUMENT_TREE instead

Create File Explorer for PDF, Text and Image in Android

I am new in android development and I just want to know how to do a customized file explorer that will only display pdf, text and image files.
I tried this example but I dont know how to filter the files that can be displayed :(
Android File Explore
Is there a way to display and select only the files mentioned above?
Take a look at #Smitted answer.
Create the intent:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
You can set the MIME types for the intent:
intent.SetType("application/pdf");
and add additional MIME types:
String[] mimetypes = {"image/*", "text/*"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
and start the activity:
StartActivityForResult(intent, FIND_FILE_REQUEST_CODE);
You can filter the files in the accept() of new FilenameFilter().

Android Custom FileChooser

In my app the user has the opportunity to import a file via an intent.
Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(new Helper(FunctionsActivity.this).getPathToAppFolder());
chooseFile.setDataAndType(uri, "*/*");
chooseFile.setType("*/*");
Intent intent = Intent.createChooser(chooseFile, getString(R.string.importDatei));
startActivityForResult(intent, REQUEST_CODE_IMPORT_FILE);
The valid files are files with the ending: .tr
These can undestood by my app.
The problem is, that the Intent shows all files in the folder:
After long searching I could not find a solution to show only .tr files. (Besides: For .xml or known file formats it is possible.)
So my idea is to write a small custom filechooser. When you click on "import", an activity opens that shows the names of all files with the extension .tr
So my question is:
Has anyone implemented something like this and can help me or does anyone has tips how to implement this the best?
I am grateful for everything that helps me further

How to open the My Files folder in Android Programatically (using Intent)?

I am using the below code which opens up the Gallery, Music Player, Dropbox and Contacts, i want the My Files folder to get open programatically, please let me know if there are any specific intent parameters i need to pass to get the File Manager open.
if it is not possible through intent then please give me a snippet or an hint to open the My Files folder programatically.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
Intent i = Intent.createChooser(intent, "View Default File Manager");
startActivityForResult(i, CHOOSE_FILE_REQUESTCODE);
Thanks.
You can use this code to file the files.
int PICKFILE_RESULT_CODE=1;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent,PICKFILE_RESULT_CODE);
this will help you to browse the files from your storage.
Its best that you include a library in your project which handles this scenario.
This worked for me:
This library shows the list of third-party apps. It also has its own file browser for selecting files.
Bad thing is, most Android distributions may or may not ship with a file manager, and even so, may be not with the one which handles CHOOSE_FILE_REQUESTCODE.
So, you are left to create your own file picker activity. Luckily there are many ready made ones available:
http://code.google.com/p/android-filechooser/
https://developers.inkfilepicker.com/docs/android/
If you want to open samsung My Files application try this below code.
Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
startActivityForResult(intent, CHOOSE_FILE_REQUESTCODE);
You have to specifically mention the package name of the explorer application. Please find the example below to open a specific folder in ES Explorer.
public void openfolderInexplorer(String path){
Intent intent = this.getPackageManager().getLaunchIntentForPackage("com.estrongs.android.pop");
if (intent != null) {
// If the application is avilable
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.parse(path);
intent.setDataAndType(uri, "resource/folder");
this.startActivity(intent);
} else {
// Play store to install app
intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("market://details?id=" +
"com.estrongs.android.pop"));
this.startActivity(intent);
}
try this below code. if any file manager available , then it will pop up in a form of menu to choose appropriate for the user.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, CHOOSE_FILE_REQUESTCODE);

Categories

Resources