Trying open a specific folder in android using intent


Trying open a specific folder in android using intent



I am trying to open a specific folder in android ?Is it possible to open a specific folder ???? this is the code i m using


config=(Button)findViewById(R.id.btn_cf);

config.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{

Intent intent = new Intent("Intent.ACTION_GET_CONTENT");
Uri uri = Uri.parse("mnt/sdcard/myfiles/allfiles/download");
intent.setDataAndType(uri, "*/*");
startActivity(Intent.createChooser(intent, "download"));


}
});





have you tried this link stackoverflow.com/questions/17165972/…
– deniz
Feb 4 '14 at 5:09





possible duplicate of Android: Sending an Intent to Browser to open specific URL
– karthik
Feb 4 '14 at 5:26





possible duplicate of How can I open a URL in Android's web browser from my application?
– flx
Feb 27 '14 at 2:24




5 Answers
5


public void 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"));
}



An other MIME type like "*/*" is also possible.


"*/*"





i used the code above and it says u need to use drop box app????? i just need to open a specific folder in android
– user3269466
Feb 4 '14 at 5:19





@user3269466 You can't do it in Android API version below 19 (KITKAT) without installed file manager. Since API >= 19 you can use Intent.ACTION_OPEN_DOCUMENT (or API >= 21 - Intent.ACTION_OPEN_DOCUMENT_TREE).
– Ruslan Berozov
Sep 19 '16 at 9:50


Intent.ACTION_OPEN_DOCUMENT


Intent.ACTION_OPEN_DOCUMENT_TREE



try to replace your code with this line


btn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{

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"));


}
});





i did the same bt it says u login in drop box app and the sign up
– user3269466
Feb 4 '14 at 5:17





i just want to open a specific folder on my sd card
– user3269466
Feb 4 '14 at 5:17





did you try my code.,its working in my application
– rajshree
Feb 4 '14 at 5:21





i did the same it says install dropbox first ?????
– user3269466
Feb 4 '14 at 5:22





can u help???? please iotzz important
– user3269466
Feb 4 '14 at 5:33



It works:


Uri selectedUri = Uri.parse(Environment.getExternalStorageDirectory() + "/myFolder/");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(selectedUri, "resource/folder");
startActivity(intent);



Have a nice codding :)





Error: No Activity found to handle PATH, Type="resource/folder"
– Alauddin Ansari
Dec 12 '14 at 12:41





Alauddin Ansari, maybe because you don't have any file manager app installed on your device. Please, check it.
– Sa Qada
Dec 15 '14 at 10:35






I've "Root Explorer" installed on my device. Also there is default file manager. But still getting error.
– Alauddin Ansari
Dec 16 '14 at 11:27





this code is only work if you have ES file explorer. need to change the setDataType
– Faisal Shaikh
Oct 29 '16 at 15:10



setDataType



Pick root:


Intent selectFile = new Intent();
selectFile.setAction("com.sec.android.app.myfiles.PICK_DATA_MULTIPLE");
selectFile.putExtra("CONTENT_TYPE", "*/*");
selectFile.addCategory(Intent.CATEGORY_DEFAULT);
startActivity(selectFile);





I want to set URI For this can you please help me ?
– PriyankaChauhan
Jul 27 '17 at 6:30



I found a solution in this GitHub repo



The code :



If you want open & browse file: FileBrowser.class


Intent intent = new Intent(activity, FileBrowser::class.java)
intent.putExtra(Constants.INITIAL_DIRECTORY, File(storageDirPath).absolutePath)
intent.putExtra(Constants.ALLOWED_FILE_EXTENSIONS,"*")

startActivityForResult(intent, CODE_INTENT )



If you want to get user chosen file's URI: FileChooser.class


Intent intent = new Intent(activity, FileChooser::class.java)
intent.putExtra(Constants.INITIAL_DIRECTORY, File(storageDirPath).absolutePath)
startActivityForResult(intent, CODE_INTENT )






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to add background colour in existing image using Swift?

Moria Casán

How to make file upload 'Required' in Contact Form 7?