- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我进行了很多研究,但仍然没有找到在 Adobe 阅读器中打开下载的 pdf 的正确解决方案。通过使用下面的代码,pdf 可以使用 google doc 应用程序而不是 adobe 打开。
从Url下载pdf
URL url = new URL(f_url[0]);
try {
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.connect();
InputStream inputStream = urlConnection.getInputStream();
FileOutputStream fileOutputStream = new FileOutputStream(Environment.getExternalStorageDirectory() + "/" + getFileName());
byte[] buffer = new byte[AccessibilityNodeInfoCompat.ACTION_DISMISS];
while (true) {
int bufferLength = inputStream.read(buffer);
if (bufferLength <= 0) {
break;
}
fileOutputStream.write(buffer, 0, bufferLength);
}
fileOutputStream.close();
} catch (Exception e) {
FileLog.e("PDF Save", e);
}
查看保存的 PDF
File file = new File(Environment.getExternalStorageDirectory() + "/" + getFileName());
try {
if (file.exists()) {
Uri fileUri = Uri.fromFile(file);
if (Utilities.isAboveNougat()) {
Uri contentUri = FileProvider.getUriForFile(mContext, "myPackage.fileprovider", file);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(contentUri, "application/pdf");
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_CLEAR_TOP);
mContext.startActivity(intent);
} else {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(fileUri, "application/pdf");
mContext.startActivity(intent);
}
} else {
Toast.makeText(mContext, "Not able to find downloaded file", Toast.LENGTH_LONG).show();
}
} catch (ActivityNotFoundException ae) {
Toast.makeText(mContext, "No activity found to open this attachment.", Toast.LENGTH_LONG).show();
}
public static boolean isAboveNougat() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return true;
}
return false;
}
list .xml;
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="myPackage.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
provider_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path path="." name="external_storage_root" />
</paths>
我也试过以下方式打开pdf;
Intent intent = ShareCompat.IntentBuilder.from((Activity) mContext)
.setStream(contentUri)
.setType("application/pdf")
.getIntent()
.setAction(Intent.ACTION_VIEW)
.setDataAndType(contentUri, "application/pdf") .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_CLEAR_TOP);
mContext.startActivity(intent);
但还是无法解决问题。在使用 adobe 打开 pdf 时显示 toast 消息;
File could not be access please check location or network connection.
最佳答案
终于知道错在哪里了。从 Url 下载 pdf 时,它以字节为单位进行存储,而 adobe 无法读取该字节格式的文件。因此,在保存下载的文件时,我们需要提供 .pdf 扩展名,我在存储它时没有提供。大多数文档查看应用程序都能够读取字节格式的文件,例如谷歌的文档应用程序。
我更改了 getFileName 函数;
private String getFileName() {
String tempFileName = urlString.substring(urlString.length() - 10);
String[] arrFilenames = tempFileName.split("\\.");
return Utilities.getString(arrFilenames[0]+".pdf");
}
关于android - 无法在 Nougat 中使用 Adobe 打开 PDF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46074702/
我的应用程序显示通知以指示下载进度。但是自从重新设计通知(Android 7.0+)以来,只要标题文本较长,就不会显示描述文本,它会显示从 xyz MB 下载了多少数据。所以这对我的用户来说很重要。加
我想为 android nougat 创建一个应用程序,当我单击一个按钮时,我会在同一时刻在同一屏幕上启动两个应用程序。我想使用Android 7的这个新功能,可以吗? 最佳答案 您可以使用 Acce
有人试过为应用程序设置最小高度以在牛轧糖多窗口模式下使用吗? 试过了, 我的引用是这样的:https://developer.android.com/guide/topics/ui/mu
我的应用程序在 5+ 和 6+ 上完美运行,但在 7 上却不行。当应用程序尝试登录服务器时抛出此异常: 09-01 09:52:53.821 2654-2718/com.pipodi.italians
我正在开发带有后台服务的 Android 应用程序。服务在自己的进程中运行(如 com.example.app:extProccess)。创建 WebSockets 连接的服务。但在服务启动后不到 1
我有一个名为 ProApplication 的自定义应用程序,我在 list 中定义它,如下所示: 我在 Canvas 上创建了一个圆形剪辑路径,并且有一列数字在 Canvas 上进行了动画处理,因此我看到数字在剪辑部分中进行动画处理并进行动画处理。这是裁剪代码: mClipPath.addCirc
在 Android(目标 25)中,我有一个后台服务,在 onCreate 函数中我已经初始化了一个电话状态监听器。它在 Nougat 之前的 Android 版本上运行良好,但在 Nougat 中它
我在 Android 7.x 中将通知小图标设置为黄色时遇到问题 我在构建通知对象时使用 notification.setColor(Color.YELLOW);。它显示橄榄色(有点)而不是黄色。 还
这list of changes对于 Android Marshmallow 非常有用。牛轧糖有类似的 list 吗?如果是,如何找到它? 最佳答案 目前Android N还处于预览状态,所以它的文档
从一年开始,我一直在研究 IOT 产品,并且附加的应用程序运行良好。现在我无法在更高版本的android中以编程方式接受调用。功能对产品来说非常重要。非常感谢任何帮助。 在安全补丁更新 2016 年
自 Android N 开发者预览版第一次发布以来,我在尝试列出根目录或其他系统目录时收到“权限被拒绝”错误。这些目录的权限似乎没有改变(据我所知)。 问题: Android N 中的哪些更改导致了这
我已将手机更新为 android nougat,裁剪功能突然无法使用。在 Marshmallow 中工作得很好。这是我的build.gradle apply plugin: 'com.andr
我像这样开始工作: JobScheduler scheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE); if(sc
我正在自定义日期和时间选择器。当我在 android Nougat 上尝试时,OK 和 Cancel 按钮显示为半透明灰色。见附图。在 android 6 中——它看起来很好……有任何想法吗?谢谢
我正在我的服务的 onStartCommand 中注册我的 PhoneStateListener。它在以下 android N 设备中运行良好。但有时它在 android N 设备中没有响应。它与打瞌
Android 7.0 Nougat 带来了新的内联通知 - 能够在通知中回复消息。我想知道如何更改内联回复背景和突出显示颜色。 玩了一下,我发现背景颜色取决于您的 colorPrimary。然后从原
尝试使用以下方法更改 Nougat 中的应用程序语言,但失败了。 config.setLocales(new LocaleList(locale)); getBaseContext().createC
我想知道我的应用程序在后台时是否被杀死。我正在使用 android nougat 设备进行测试。但是当我通过滑动杀死我的应用程序时,我的服务的 onTaskRemoved() 没有调用。 有什么方法可
我有一个登录屏幕,它有两个 EditText,一切正常,但是当我在 android nougat 7.0.1 中运行应用程序时,登录屏幕的光标显示在中心。我也尝试过此处提供的解决方案......但不适
我是一名优秀的程序员,十分优秀!