0

I'd like to open files such as photos, documents, music and video in my application. I've seen a lot of applications that open up the files in the device's default program for that filetype.

Is there a way to somehow view the files in my application without opening another application?

tshepang
  • 12,111
  • 21
  • 91
  • 136
benkdev
  • 673
  • 2
  • 16
  • 32
  • Do you mean your app is the default app for those files, or do you want to, within your app, read files from the sdcard? – Samuel Apr 02 '12 at 19:15
  • I'd like to read files from the sdcard and display them within my app. – benkdev Apr 02 '12 at 19:16

2 Answers2

1

Reading files in Android is just as simple as any other Java application. Depending on what type of file you want to read and display, you will do different things, this question tells you how to read a text file. The principle for other types is about the same. For images, you can simply use BitmapFactory.decodeFile(). I don't have experience with video or audio, but MediaPlayer looks like a promising first step.

Community
  • 1
  • 1
Samuel
  • 16,923
  • 6
  • 62
  • 75
1

You can do it, but only by writing your own Activity that can handle that type of media. So it can be a lot of work, depending on what you want to do. HTML, images, video, and audio are relatively easy, but if you want to do something like view PDF or office documents, you're setting yourself up for a tremendous amount of coding. Probably better just to launch someone else's viewer to view the relevant content; that's how almost everyone does it on Android.

Tom Meyer
  • 141
  • 3