Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用webview控件从移动应用程序打印?_Android_Asp.net_Eclipse_Pdf_Webview - Fatal编程技术网

Android 如何使用webview控件从移动应用程序打印?

Android 如何使用webview控件从移动应用程序打印?,android,asp.net,eclipse,pdf,webview,Android,Asp.net,Eclipse,Pdf,Webview,抱歉,因为它可能是一个重复的线程。但我尝试了这么多,我也找到了一些解决方案,但我无法用那个解决方案达到我的目标 我尝试创建一个简单的android移动应用程序。使用Eclips,我只需使用WebView控件,并将该控件定位到一个移动网页(通过使用loadUrl),即asp.net网页(移动web表单)。但我无法从网页调用print方法 然后我尝试创建一个pdf文件并尝试打开/下载。我成功地创建了pdf文件。但无法在单独的窗口(adobe reader)中打开该文件,而且我无法在设备中下载该文件

抱歉,因为它可能是一个重复的线程。但我尝试了这么多,我也找到了一些解决方案,但我无法用那个解决方案达到我的目标

我尝试创建一个简单的android移动应用程序。使用Eclips,我只需使用WebView控件,并将该控件定位到一个移动网页(通过使用loadUrl),即asp.net网页(移动web表单)。但我无法从网页调用print方法

然后我尝试创建一个pdf文件并尝试打开/下载。我成功地创建了pdf文件。但无法在单独的窗口(adobe reader)中打开该文件,而且我无法在设备中下载该文件

请给出一些解决方案,在单独的窗口中打开pdf(在移动应用程序外部)或将pdf文件从服务器下载到本地设备

提前谢谢

我尝试过的:

//On my mobile app I use: 
WebView wv1=(WebView)findViewById(R.id.webView1);
wv1.setWebViewClient(new MyBrowser()); String url = "http://example.com/testprint.aspx"; 
wv1.loadUrl(url);

//On testprint.aspx I use: 
<html xmlns="w3.org/1999/xhtml"; > <body> 
<mobile:Form id="Form1" runat="server"> 
<mobile:Command ID="Command1" Runat="server" OnClick="Command1_Click">Command</mobile:Command> 
</mobile:Form> </body> </html>

//On testprint.aspx.cs I use: 
string FilePath = Request.PhysicalApplicationPath + "\\MyPDF\\test.pdf";
//I write a method here to create pdf file 
/*.......*/ 
//After that I write this code for open that file (which I create above)
Response.ContentType = "application/pdf"; 
Response.AppendHeader("Content-Disposition", "attachment; filename=test.pdf"); 
Response.TransmitFile(FilePath); 
Response.End();


//I also try to use below method also to download the file
string FilePath = Request.PhysicalApplicationPath + "\\MyPDF\\test.pdf";
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(_Path));

const int _bufferLength = 10000;
byte[] _buffer = new Byte[_bufferLength];
int _length = 0;
Stream _download = null;
try
{
    _download = new FileStream(_Path, FileMode.Open, FileAccess.Read);
    do
    {
        if (Response.IsClientConnected)
        {
            _length = _download.Read(_buffer, 0, _bufferLength);
            Response.OutputStream.Write(_buffer, 0, _length);
            _buffer = new Byte[_bufferLength];
        }
        else
        {
            _length = -1;
        }
    }
    while (_length > 0);
    Response.Flush();
    Response.End();
}
finally
{
    if (_download != null) _download.Close();
}
//在我的移动应用程序上使用:
WebView wv1=(WebView)findviewbyd(R.id.webView1);
wv1.setWebViewClient(新的MyBrowser());字符串url=”http://example.com/testprint.aspx"; 
wv1.loadUrl(url);
//在testprint.aspx上,我使用:
命令
//在testprint.aspx.cs上,我使用:
字符串FilePath=Request.PhysicalApplicationPath+“\\MyPDF\\test.pdf”;
//我在这里写了一个创建pdf文件的方法
/*.......*/ 
//之后,我编写了打开该文件的代码(我在上面创建了该文件)
Response.ContentType=“application/pdf”;
AppendHeader(“内容处置”、“附件;文件名=test.pdf”);
响应.传输文件(文件路径);
Response.End();
//我也试着用下面的方法来下载文件
字符串FilePath=Request.PhysicalApplicationPath+“\\MyPDF\\test.pdf”;
Response.ContentType=“应用程序/八位字节流”;
Response.AppendHeader(“内容处置”、“附件;文件名=“+Path.GetFileName(_Path));
const int_bufferLength=10000;
字节[]_buffer=新字节[_bufferLength];
int _长度=0;
流_download=null;
尝试
{
_下载=新文件流(_路径,FileMode.Open,FileAccess.Read);
做
{
if(Response.IsClientConnected)
{
_length=\u download.Read(\u buffer,0,\u bufferLength);
Response.OutputStream.Write(_buffer,0,_length);
_buffer=新字节[_bufferLength];
}
其他的
{
_长度=-1;
}
}
而(_长度>0);
Response.Flush();
Response.End();
}
最后
{
如果(_download!=null)_download.Close();
}

感谢@Bernoulli Gate对标题的修改。如果没有直接打印方法,请给出一些想法,在客户端的pdf查看器应用程序(adobe reader或其他)中打开不在我的应用程序中的pdf文件,或从服务器下载pdf文件到客户端的移动设备。不清楚。链接PDF。用户可以选择直接打开或下载。谢谢回复。我使用网页上的一个按钮(这是移动应用程序webview的url上的目标),以及我使用上述两种方法(交替)打开/下载pdf文件的onclick事件。但什么也没发生。但当我在浏览器中打开该网页时,它工作正常。
使用网页上的一个按钮(这是移动应用程序webview的url上的目标),以及我使用上述两种方法(交替)打开/下载pdf文件的onclick event。
听起来很糟糕。你应该将手机指向远程URL,而不是相反。是的,我这样做了(我想我无法表达我做了什么和我想要什么)。我将我的应用指向远程url。在该网页上有一个按钮,我使用上面的代码(有两种方法,我逐个尝试)打开该文件。当我使用我的应用程序并点击按钮时,什么也没发生,但当我在浏览器上键入url时,它就工作了(下载该文件)。感谢@Bernoulli Gate修改标题。如果没有直接打印方法,请给出一些想法,在客户端的pdf查看器应用程序(adobe reader或其他)中打开不在我的应用程序中的pdf文件,或从服务器下载pdf文件到客户端的移动设备。不清楚。链接PDF。用户可以选择直接打开或下载。谢谢回复。我使用网页上的一个按钮(这是移动应用程序webview的url上的目标),以及我使用上述两种方法(交替)打开/下载pdf文件的onclick事件。但什么也没发生。但当我在浏览器中打开该网页时,它工作正常。
使用网页上的一个按钮(这是移动应用程序webview的url上的目标),以及我使用上述两种方法(交替)打开/下载pdf文件的onclick event。
听起来很糟糕。你应该将手机指向远程URL,而不是相反。是的,我这样做了(我想我无法表达我做了什么和我想要什么)。我将我的应用指向远程url。在该网页上有一个按钮,我使用上面的代码(有两种方法,我逐个尝试)打开该文件。当我使用我的应用程序并单击按钮时,什么也没发生,但当我在浏览器上键入url时,它就工作了(下载该文件)。