我已經建立了一個 PDF 閱讀器,我想從手機 Ex 的任何地方打開 pdf。Whatsapp,檔案管理器。
當我從谷歌檔案管理器打開 pdf 時它正在作業,當我從默認檔案管理器打開它時它崩潰了
顯示此錯誤
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.os.Bundle.get(java.lang.String)' on a null object reference
應用清單檔案
<activity
android:name=".PDF_Viewer"
android:exported="true">
<intent-filter>
<action
android:name="android.intent.action.VIEW" />
<category
android:name="android.intent.category.DEFAULT" />
<data
android:mimeType="application/pdf" />
</intent-filter>
<intent-filter>
<action
android:name="android.intent.action.VIEW" />
<category
android:name="android.intent.category.DEFAULT" />
<data
android:scheme="file"
android:host="*"
android:pathPattern=".*\.pdf" />
</intent-filter>
<intent-filter>
<action
android:name="android.intent.action.VIEW" />
<category
android:name="android.intent.category.DEFAULT" />
<category
android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="http"
android:host="*"
android:pathPattern=".*\.pdf" />
<data
android:scheme="https"
android:host="*"
android:pathPattern=".*\.pdf" />
</intent-filter>
</activity>
我在 PDF 查看器活動中收到這樣的意圖:
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
Uri pdf = (Uri) bundle.get(Intent.EXTRA_STREAM);
uj5u.com熱心網友回復:
你的三個<intent-filters>都是為了ACTION_VIEW。的檔案ACTION_VIEW有:
輸入:
getData()是從中檢索資料的 URI。
因此,考慮到這一點,將您的 Java 代碼替換為:
Intent intent = getIntent();
Uri pdf = intent.getData();
您可能會考慮檢查現有的 PDF 查看器應用程式以了解它們的作業原理。有關于F-Droid的上市很多開源的人,例如。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/311205.html
