android: open a pdf from my app using the built in pdf viewer

前端 未结 9 1733
温柔的废话
温柔的废话 2020-11-29 04:46

This was my original question:

I want to be able to open a pdf file in my app using the android\'s built in pdf viewer app, but i dont know how to

9条回答
  •  失恋的感觉
    2020-11-29 05:17

    You can programmatically determine whether a suitable application exists on the user's device, without catching exceptions.

    Intent intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("path-to-document"));
    intent.setType("application/pdf");
    PackageManager pm = getPackageManager();
    List activities = pm.queryIntentActivities(intent, 0);
    if (activities.size() > 0) {
        startActivity(intent);
    } else {
        // Do something else here. Maybe pop up a Dialog or Toast
    }
    

提交回复
热议问题