Discussion Forums  >  Images, Documents, File Locations

Replies: 21    Views: 90

MaxxDaddy
Lost but trying
Profile
Posts: 24
Reg: Jan 09, 2013
West Allis, WI
6,090
01/27/13 05:17 PM (12 years ago)

open file after copied to sdcard

Hi all, This is acutally in response to a different post that I started and I have pared down my issue significantly. I need to open a pdf from buzztouch (not in buzztouch) and I just need a little help formatting the command, see I am a total hack and I have gotten this far by lots and lots of trial and error. Using the onClickListener for B7 i can copy a file from res/raw to the application directory on the sd card. that is past the read write barrier and i have been able to successfully open the file using ES file explorer which allows me to open it in a standard PDF viewer and click it all day long (sweet) Can someone who has the know how please let me know how to modify my copy command to include an open command to open this little bugger. if it's there and I am just missing it please let me know. Thanks BT Joe Button OpenPDF = (Button) findViewById(R.id.button7); OpenPDF.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //void createExternalStoragePrivateFile() { // Create a path where we will place our private file on external // storage. File file = new File(getExternalFilesDir(null), "fdai.pdf"); try { // Very simple code to copy a picture from the application's // resource into the external file. Note that this code does // no error checking, and assumes the picture is small (does not // try to copy it in chunks). Note that if external storage is // not currently mounted this will silently fail. InputStream is = getResources().openRawResource(R.raw.fdai); OutputStream os = new FileOutputStream(file); byte[] data = new byte[is.available()]; is.read(data); os.write(data); is.close(); os.close(); } catch (IOException e) { // Unable to create file, likely because external storage is // not currently mounted. Log.w("ExternalStorage", "Error writing " + file, e); } }
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
01/27/13 06:34 PM (12 years ago)
@MaxxDaddy, Why don't you just install a pdf reader on your emulator? LA
 
MaxxDaddy
Lost but trying
Profile
Posts: 24
Reg: Jan 09, 2013
West Allis, WI
6,090
like
01/27/13 06:39 PM (12 years ago)
that sounds easy...... how do i tell the file to open after i push that button....... im a total noob and struggling. I'm assuming it is tied into that onClickListener, but ?? I'm my logical head it is Copy Paste Open Can it all be done at once?
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
01/27/13 06:42 PM (12 years ago)
@MaxxDaddy, Yes do you know how to create a button and make it go to another screen? LA
 
MaxxDaddy
Lost but trying
Profile
Posts: 24
Reg: Jan 09, 2013
West Allis, WI
6,090
like
01/27/13 06:58 PM (12 years ago)
in eclipse and in buzztouch. I don't know how to do like an openfileoutput or getExternalFilesDir. Also I don't really know how to do two things from one onClickListener. Where's carrollton, btw?
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
01/27/13 07:04 PM (12 years ago)
In Illinois. You trying to learn to code or you just want to open a pdf in the emulator? LA
 
MaxxDaddy
Lost but trying
Profile
Posts: 24
Reg: Jan 09, 2013
West Allis, WI
6,090
like
01/27/13 07:09 PM (12 years ago)
the code. I'm almost all the way there. I have been copy and pasting all day from developer.android............. I can get it from computer to res to APK to the external storage of the device..... I just need a little help telling my app to open that doggone file from the external storage with the same click that moves it from res to the external storage.
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
01/27/13 07:16 PM (12 years ago)
Alright try this: Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(path, "application/pdf"); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); try { startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(OpenPdf.this, "No Application Available to View PDF", Toast.LENGTH_SHORT).show(); } LA
 
MaxxDaddy
Lost but trying
Profile
Posts: 24
Reg: Jan 09, 2013
West Allis, WI
6,090
like
01/27/13 07:37 PM (12 years ago)
would that go immediately after the os.close();
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
01/27/13 07:40 PM (12 years ago)
It can or you can rename the Intent to Intent 2 and try it within the onClick. LA
 
MaxxDaddy
Lost but trying
Profile
Posts: 24
Reg: Jan 09, 2013
West Allis, WI
6,090
like
01/27/13 08:10 PM (12 years ago)
path cannot be resolved to a variable openpdf cannot be resolved to a type. damn
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
01/27/13 08:18 PM (12 years ago)
Change that to your pdf file name like this: openmypdf; LA
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
01/27/13 08:48 PM (12 years ago)
Hey @MaxxDaddy, Why do you want to copy a pdf to emulator thru code when you can just put it in your BT_Docs folder and it's included in your App. LA
 
MaxxDaddy
Lost but trying
Profile
Posts: 24
Reg: Jan 09, 2013
West Allis, WI
6,090
like
01/27/13 09:03 PM (12 years ago)
Intent intent2 = new Intent(Intent.ACTION_VIEW); intent2.setDataAndType(path, "fdai/pdf"); intent2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); try { startActivity(intent2); } catch (ActivityNotFoundException e) { Toast.makeText(OpenPdf.this, "No Application Available to View PDF", Toast.LENGTH_SHORT).show(); }
 
MaxxDaddy
Lost but trying
Profile
Posts: 24
Reg: Jan 09, 2013
West Allis, WI
6,090
like
01/27/13 09:16 PM (12 years ago)
didnt work. thanks for trying. i'm gonna get this eventually.
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
01/28/13 06:30 AM (12 years ago)
@MaxxDaddy, Sorry it didn't work. When you get this, can you share it please? LA
 
MaxxDaddy
Lost but trying
Profile
Posts: 24
Reg: Jan 09, 2013
West Allis, WI
6,090
like
01/28/13 06:47 AM (12 years ago)
LA, good morning. I slept on it and had the following thoughts. my "ButtonOpenPDF" does not really have any intents in it. do you think I could package all that code up into a class and then call the class via an intent1 and then open the file via an intent2? that code, as it sits in my OP, will copy ANY file from the res/raw to the external storage (sdcard or not) and it puts it in a special folder just for your app, I just tested it on another device, in the following two lines: File file = new File(getExternalFilesDir(null), "fdai.pdf"); //change fdai.pdf to your file name in the res/raw folder. & InputStream is = getResources().openRawResource(R.raw.fdai); // //change fdai.pdf to your file name in the res/raw folder. note: you may need to add the writeable permission to the permission folder.
 
MaxxDaddy
Lost but trying
Profile
Posts: 24
Reg: Jan 09, 2013
West Allis, WI
6,090
like
01/28/13 06:49 AM (12 years ago)
also it should be noted, i am NOT testing this in buzztouch, this is just a basic android app in eclipse, once i get it working it should be easy enough to modify the code of my buzztouch buttons to do this same thing.
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
01/28/13 07:09 AM (12 years ago)
Hey @MaxxDaddy, You could bring up another page and have that class open the pdf. Do you have a pdf reader to open the pdf? LA
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
01/28/13 07:23 AM (12 years ago)
You want it to open in ES file explorer? LA
 
MaxxDaddy
Lost but trying
Profile
Posts: 24
Reg: Jan 09, 2013
West Allis, WI
6,090
like
01/28/13 08:03 AM (12 years ago)
Sadly right now there are probably eight PDF apps..... :) I am pretty sure that I saw somewhere on one of the forums that you can open two intents from one click. This is a greatly researched subject and it seems that when someone figures it out they don't "dumb it down for us common folk" I will put together something when I am done because being able to open a fillable PDF and then e-mail it in is only useful in around 100% of service related businesses. Heck, if there is someone that wanted to build a plug in and sell it here i will give you all my code. I am not trying to profit from this app (yet) but there HAS to be a way to do this. Android can do it, that means that buzztouch can do it.
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
01/28/13 09:43 AM (12 years ago)
@MaxxDaddy, Make sure your activities are in your Android Manifest and the permissions. LA
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.