Show PDF in Android

后端 未结 2 1407
灰色年华
灰色年华 2021-02-09 04:00

In my onCreate() I do this check:

//
// check if we have a PDF viewer, else bad things happen
//
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType(\         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-09 04:53

    Connect your phone to you PC, start Eclipse and open the LogCat. Then download a PDF file with the browser and open it. You should see a line such as (I used the HTC desire):

    09-14 17:45:58.152: INFO/ActivityManager(79): Starting activity: Intent { act=android.intent.action.VIEW dat=file:///sdcard/download/FILENAME.pdf typ=application/pdf flg=0x4000000 cmp=com.htc.pdfreader/.ActPDFReader }

    Have a go with an explicit intent using the component information. Docs say here:

    > component -- Specifies an explicit name of a component class to use for the intent. Normally this is determined by looking at the other information in the intent (the action, data/type, and categories) and matching that with a component that can handle it. If this attribute is set then none of the evaluation is performed, and this component is used exactly as is. By specifying this attribute, all of the other Intent attributes become optional.

    Downside is you will be bound to the htc reader. But you could try an implicit intent first and if that fails try the explicit intent as a fallback.

提交回复
热议问题