In my application I will receive a byte stream and convert it to a pdf file in the phone memory. How do I render that to a pdf? And show it on an activity?
+7
A:
Some phones (like the Nexus One) come with a version of Quickoffice pre-installed so it may be as easy as sending the appropriate Intent once you've saved the file to the SD card.
public class OpenPdf extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.OpenPdfButton);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
File file = new File("/sdcard/example.pdf");
if (file.exists()) {
Uri path = Uri.fromFile(file);
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();
}
}
}
});
}
}
Tim Kryger
2010-05-21 21:35:28
hmm ill try this tomorrow. so from byte streams i will get i need to save them as a file and then try doing that code .
mikedroid
2010-05-23 10:46:11
hmm how about if i do not have QuickOffice installed in my Android?
mikedroid
2010-05-24 08:17:28
+1
A:
What tkryger posted works great! How would you start the pdf and also search it all at once. For example you were looking for the keywords "chocolate" and so when example.pdf was opened it would go to the first instance of "chocolate" it could find. If this is not possible could you set it to start on a certain page?
Nate
2010-05-23 18:22:13
You should post this as a new question, not as an answer to another question.
Mayra
2010-05-23 18:35:47