I'm trying to create a pdf opener on my android emulator (2.3.3), however it is returning an Activitynotfound exception every time i run it. I've checked the package name and the class name and it is correct. I am also quite new in Android development. Here are the codes!
public class PdfViewerActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = new TextView(this);
File file = new File("mnt/sdcard/proposal.pdf");
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri path2 = Uri.fromFile(file);
intent.setDataAndType(path2, "application/pdf");
try
{
startActivity(intent);
}
catch(ActivityNotFoundException e )
{
tv.setText("What the hell is going on O_O" +开发者_运维问答 "\n" + e);
setContentView(tv);
}
}
}
==========
Manifest
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".PdfViewerActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Thereis no PDF viewer application installed on your phone. That's why the start activity code here is failing. What exactly do you mean by a PDF opener?
When you launch the intent for ACTION_VIEW, do you have an activity that "catches" it?
You are using emulator for read PDf and the way you are reading PDF is Intent.ACTION_VIEW
for that you need one Pdf reading application install in your emulator.
If you want to read Pdf there is some other way you can read
Android - Load PDF / PDF Viewer
Also you can make your own PDF Viewer
精彩评论