无法访问Android应用程序中的adobe应用程序共享pdf文件 [英] Unable to access the adobe application shared pdf file in android application
本文介绍了无法访问Android应用程序中的adobe应用程序共享pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用android应用程序开发过程,我正在从Adobe app分享pdf文件到我的android应用程序。我得到的共享pdf文件URI如下
I am working android application development process and I am sharing pdf file from Adobe app to my android application. I am getting shared pdf file URI as follows
Android.Net.Uri fileuri =
(Android.Net.Uri)Intent.GetParcelableExtra(Intent.ExtraStream);
fileuri i am getting as {content://com.adobe.reader.fileprovider/root_external/
data/data/com.adobe.reader/files/Downloads/sample.pdf}
string filePath = fileuri.Path;
filePath I am gettings as root_external/data/data/com.adobe.reader/files/Download/sample.pdf
File.Exist(filePath)--> returns false
我不知道究竟是什么原因无法访问pdf文件
请帮助我访问Adobe在我的Android应用程序中共享一个文件
我尝试过:
从Adobe应用程序获取的文件URI无法在我的应用程序中访问
I don't what exactly the reason behind not accessing the pdf file
please help me to access the Adobe shared a file in my android application
What I have tried:
file URI which is getting from Adobe application is not able to access in my application
推荐答案
通过以下代码,我可以获得adobe应用程序共享pdf文件作为流并保存到Android应用程序路径
By the following code, I am able to get adobe application shared pdf file as a stream and saving into android application path
using (var stream = ContentResolver.OpenInputStream(fileuri))
{
byte[] fileByteArray = ToByteArray(stream); //only once you can read bytes from stream second time onwards it has zero bytes
string fileDestinationPath ="<path of your destination> "
convertByteArrayToPDF(fileByteArray, fileDestinationPath);//here pdf copied to your destination path
}
public static byte[] ToByteArray(Stream stream)
{
var bytes = new List<byte>();
int b;
while ((b = stream.ReadByte()) != -1)
bytes.Add((byte)b);
return bytes.ToArray();
}
public static string convertByteArrayToPDF(byte[] pdfByteArray, string filePath)
{
try
{
Java.IO.File data = new Java.IO.File(filePath);
Java.IO.OutputStream outPut = new Java.IO.FileOutputStream(data);
outPut.Write(pdfByteArray);
return data.AbsolutePath;
}
catch (System.Exception ex)
{
return string.Empty;
}
}
这篇关于无法访问Android应用程序中的adobe应用程序共享pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文