How can i load my pdf file from sd card - android

I have a simple code in which i am reading a pdf filefrom sd card.
Here is my code
In the activity CcActivity: I have given path of the file name,at line number 25:
String filename = "/mnt/sdcard/sample3.pdf";
The pdf is looking fine in emulator. But now i want to set one button and on click event of that button i want to see all the pdf file stored in sd card. I don't have any idea about it,can some one please help me out to solve this problem.

1 Firstly you have to search all pdf files present in sdcard and store it into an array .
To find pdf files in sdcard go through link search pdf's.
2 Then show all pdf's from array on any layout you are feasible onclick of button event. After that handle the specific pdf to display in pdfviewer.

Related

How to write files on SD Card from Android API 24+

I have a big problem. I want to save some files that I download from internet with my application, into my SD card fallowing this path:
/storage/9016-4EF8/Android/data/com.my.application/files
But I don't want to hardcode this string inside my code. So how can I do it programmatically?
I have already ask permission to write on external storage.
Currently inside my code there is this piece of code below:
File sdcard = new File(context.getExternalFilesDir(null).getAbsolutePath() + "/Video scaricati/");
But with it, my application saves the files inside:
/storage/emulated/0/Android/data/com.my.application/files/Video scaricati
that it isn't in my SD card.
How can I do it?
Take the second item returned by
File dirs[] =getExternalFilesDirs();
Check if the array contains more then one element before use. Not everybody puts a micro SD card in.
Try changing to Environment.getExternalStorageDirectory() like this
new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Video scaricati/");

About Libgdx.How to show my picture from device.(I have the picture path now)

I want to show my camera take picture on screen.
I have the picture path that is
"/storage/emulated/0/DCIM/Camera/IMG_20180501_155027.jpg"
But I can't show it useimage = new Texture(Gdx.files.external("badlogic.jpg""/storage/emulated/0/DCIM/Camera/IMG_20180501_155027.jpg"));
I know image = new Texture(Gdx.files.internal("badlogic.jpg"));can show the image from assets folder.How can I show picture from my device.
please help me,and give me some suggests thank.
You need to use absolute type of FileHandle if you use fully qualified paths like "/storage/emulated/0/DCIM/Camera/IMG_20180501_155027.jpg".
If you need to read file from SD card you can use external type of FileHandle but in this case path should be relative from SD card root:
Gdx.files.external("/DCIM/Camera/IMG_20180501_155027.jpg");
Read more about GDX file types here

To show multimedia content(e.g audio,video,jpeg) from custom folder to a Dialog as file explorer.

I am creating an android app, in which i have created a custom location in external storage ,for example /storage/emulated/0/myfolder/. And it contains my app files which are video,audio and pictures(.mp4,.3gpp,.jpeg).
Is there any way to show the contents of myfolder to a popup or some dialog in list manner.Which will behave like explorer and upon clicking any item in the list ,it will run in appropriate application(e.g video player,audio player or picture viewer).Any help would be appreciated.
File dir = new File(
Environment
.getExternalStoragePublicDirectory(File.separator),
"custom folder name");
String[] files = null;
if (dir.exists()) {
files = dir.list();
}
Now with this files array i extraceted each element and checked its extension to get the mime type and showed accordingly.It worked for me.Most simple code for what i want to achieve.

Make picture available only for my Android application

I have an application which has loads of pictures. The total picture is saved in an SD card due to large number of picture. The main problem is that the pictures are available in gallery. I want a way to hide the picture from the gallery but must be available for my application.
I did put " . " in front of the file name to make it hidden
but the images were not displayed in may application also!
Anyone.. help.. please
thanks..
Gallery handles all media files it knows about, so if you want it to stay away of your assets you got two solutions. First, add .nomedia file to the folder with your images, and Gallery should skip it (most image viewers would honor .nomedia, yet there's no guarantee). Other solution is to use some own, proprietary file format, so Gallery or other tools won't be able to process it. I'd recomment .nomedia if that's sufficient solution.
Add .nomedia file into the image folder. The important thing is that, the folder should be empty, when you add .nomedia file. If the folder contains some images before adding '.nomedia' file, the gallery will not hide those images, and it will hide the images added after '.nomedia' file. So The first file added to the image folder should be '.nomedia'.
Hope dis will help you
Thankx,
This line of code can add the .nomedia file in your directory and makes your images hidden from the gallery
String NOMEDIA=" .nomedia";
File Folder = new File(Environment.getExternalStorageDirectory() + "/mydir");
if(Folder.mkdir()) {
nomediaFile = new File(Environment.getExternalStorageDirectory() + "/mydir/"+ NOMEDIA);
if(!nomediaFile.exists()){
nomediaFile.createNewFile();
}
}
i think the place where you save the images matter, try to save them into application cache directory, or files directory.
you can get access to cache directory using : getCacheDir() in your activity.
and your files directory: getFilesDir()
these two directories must not be visible or accessible to any other applications expect your application,
I used assets to accomplish this in my app.

which android list component to use?

I've developed an app that records audio and saves sample on sd card. i'd like to add a bit more functionality for example at the moment it save the sample automatically, whereas i'd like the user to be able to specify a filename and then that sample is saved under that name on the sd card. also when playing a sample i'd like the user to be able to choose a sample from a list generated from the available samples on the sd card. this is my problem, i'm not sure which android components to use to generate a list from the samples on the sd card. can anyone point me in the right direction?
thanks
Use a ListView.
With the ListView you will create a list of your SDcard´s media.
ListView Example
UPDATE ::
yes Turtleboy you will save your media files inside a directory
"/sdcard/mymediafiles/"
then extract the file´s name to be displayed in your ListView!
File sdCardRoot = Environment.getExternalStorageDirectory();
File myDirectory = new File(sdCardRoot, "/mymediafiles/");
for (File f : myDirectory.listFiles()) {
if (f.isFile())
Log.i("Jorgesys","*** Media File :: " + f.getName());
}
#Jorgesys suggestion of ListView is fine (+1), but you really need to think about what functionality you want to offer.
A listview would be fine if you just want to list file names.
If you have your files stroed in directories, then maybe a treeview, where you can expand and collapse the nodes (list windows explorer).
If you want to show multiple data about each sound sample (e.g file name, duration, artist, genre, etc) then use a stringgrid

Categories

Resources