I am writting a program in which user can select one of the text files in the sdcard.
I am using this code to give the user access to sdcard:
in oncreate method:
Intent intent = new Intent();
intent.setType("*/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "getFile"),
22);
But, I can not access the sdcard. can anybody please help me?
p.s i don't want to use any external library like fileChooser or etc.
You need add a READ_EXTERNAL_STORAGE permission in your AndroidManifest.xml file:
http://developer.android.com/reference/android/Manifest.permission.html#READ_EXTERNAL_STORAGE
Related
I am facing an issue while opening the File Manager from Android apps.
I want to see only particular file only which I have specific but I am able to see other file also but it is not highlight it is been grey out but how to hide that also so only particular specific file I can see no other file.
Below code which I have used:
Intent intent = new Intent(Intent.Action_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_MIME_TYPES,"application/pdf");
startActivityForResult(intent, FILE_REQUESTED);
What can I do to fix this?
I want to see only particular file only
Sorry, that is not an option with ACTION_OPEN_DOCUMENT.
I am confused, both parameters, "EXTERNAL_CONTENT_URI" and "INTERNAL_CONTENT_URI", access and display images from "Photos" and "Camera". Shouldn't only the second parameter access them?
Furthermore, I did not ask for any permission to read image files from these places and yet I can read and display them in my application. Shouldn't the OS prevent it happening?
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
//android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(intent, 0);
How to open default file manager app that let you choose a file but only with extension .epub or .pdf programatically via Intent?
The code shown is the declaration of the intent that you have to start for opening the default file manager app that let you choose a file but only with extension .epub or .pdf, I hope it will be useful.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("application/epub+zip");
String[] mimetypes = {"application/epub+zip", "application/pdf"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(intent,PICKFILE_RESULT_CODE);
It is a mix of solutions I found that work so maybe it is redundant. Let me know what you think!
I have some images saved on the phone internal storage in a filepath that looks like this:
/storage/emulated/0/myApp/FILENAME.jpg
I want to open an intent so that the user can set the phone wallpaper with his app of choice. Every code I tried doesn't work at all or only works with some apps. Thanks.
You can set any image in sdcard or phone by opening this intent:
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivity(Intent.createChooser(intent, "Select Wallpaper"));
kindly add permission too:
<uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>
for more options check this answer
P.S: You need to add permission for SET_WALLPAPER for android 6+
Update:
You can also open set wallpaper as dialog using :
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(imageUri, "image/*");
intent.putExtra("jpg", "image/*");
startActivityForResult(Intent.createChooser(intent,
getString(R.string.set_as)), REQUEST_ID_SET_AS_WALLPAPER);
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