为什么这个意图无法正确显示jpeg?

时间:2019-03-14 22:49:41

标签: android android-intent

因此,我们有一些通过意图打开图像的代码。我们正在使用用户设备上已经安装的图像查看器。

它可以在多种设备上工作,但不能在像素C上正确显示图像。我安装了文件浏览器,它可以正确打开文件,因此.jpeg不会损坏。

这是我们用来打开新活动以显示图像的代码:

private void openExistingFile(@NonNull SalesMaterialFile file, @NonNull File target) {
   String extension = file.getExtension().toLowerCase();
   String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
   Uri uri= FileProvider.getUriForFile(getContext(), getString(R.string.provider_authority_fileprovider), target);

   Intent intent = new Intent(Intent.ACTION_VIEW);
   intent.setDataAndType(uri, mimeType);
   intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

   // check if intent can be handled with current installed apps, if not open play store with search for app that can open the type of file selected
   if (IntentUtils.checkIntent(intent, getView(), R.string.no_app_for_file, R.string.find_app, view -> searchPlayStore("open " + file.getExtension() + " file"))) {
       startActivity(intent);
   }
}

如果图像未显示在像素C上,我在做什么错?

0 个答案:

没有答案