【发布时间】:2021-06-23 07:29:10
【问题描述】:
在我的应用程序中,我有一个 pdf,可以通过选择设备中已安装的应用程序进行打印。当我尝试打开应用程序时,它会抛出“找不到处理 Intent 的活动”。我也在我的清单文件中添加了,但它没有帮助。我在用于打印 pdf 的模拟器中安装了 printshare。下面是我的代码。
handler.postDelayed(new Runnable() {
@Override
public void run() {
try {
Uri uri = FileProvider.getUriForFile(InventoryPDFCreate.this,getPackageName(), pdfFile);
Intent intent = ShareCompat.IntentBuilder.from(InventoryPDFCreate.this)
.setStream(uri) // uri from FileProvider
.getIntent()
.setAction(Intent.ACTION_VIEW) //Change if needed
.setDataAndType(uri, "pdf/*")
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
toastMsg.showToast(InventoryPDFCreate.this, "No Application match to Open Print File"+e);
}
}
}, 100);
清单文件
<queries>
<!-- WebView -->
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>
<!-- Camera -->
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
<!-- Gallery -->
<intent>
<action android:name="android.intent.action.GET_CONTENT" />
</intent>
</queries>
我得到以下异常:
No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://com.mobilesalesperson.controller/external/Android/AMSP/PrintReport/msp.pdf typ=pdf/* flg=0x80001 (has extras) }
【问题讨论】:
-
setDataAndType(uri, "application/pdf")? -
请将其作为答案发布。