now I am doing an Android application.I have to read a file from sdcard.I installed adobe reader in my emulater.And i used the following code to run the file from sdcard.
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("/sdcard/samp.pdf"), "application/pdf");
try{
startActivity(intent);
}
catch (ActivityNotFoundException e) {
System.out.println("5");
// No application to view, ask to download one
System.out.println("hai");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("No Application Found");
builder.setMessage("Download one from Android Market?");
builder.setPositiveButton("Yes, Please",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent marketIntent = new Intent(Intent.ACTION_VIEW);
marketIntent
.setData(Uri
.parse("market://details?id=com.adobe.reader"));
startActivity(marketIntent);
}
});
builder.setNegativeButton("No, Thanks", null);
builder.create().show();
}
I inserted a pdf named sample.pdf in sdcard.But when I am running my application I am getting "the file could not be opened". But i can open the pdf manually from the emulater.Please help me to find out a solution.
Hi friends I got the solution. I removed
intent.setDataAndType(Uri.parse("/sdcard/samp.pdf"), "application/pdf");
and add
File file = new File("/sdcard/sample.pdf");
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri, "application/pdf");
now its working. But now I put the sample.pdf folder in my assets folder and write the following code.
File file = new File("android.resource://com.pdftest/assets/sample");
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri, "application/pdf");
and I getting file path not valid message...