Reputation: 1861
In my application am having a pdf which is to be printed by selecting the installed apps in the device. When I tried to open the application it throws "No Activity found to handle Intent". I have also added in my manifest file but it's not helping. I have installed printshare in my emulator which used to print the pdf. Below is my code.
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);
Manifest file
<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>
Am getting the below exception:
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) }
Upvotes: 1
Views: 8126
Reputation: 2981
The probem was that the OP was using an incorrect mime-type as the parameter. Android does not support all types of mimes but this can be checked by using MimeTypeMap.
Return the MIME type for the given extension if supported, null otherwise.
final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension("pdf");
Upvotes: 1