2016-07-24 73 views
-1

我需要显示位于URL PDF文件 我的代码很容易...显示URL(PDF)中的WebView - 安卓

var link_condiciones; 
var idioma = Left(Titanium.Locale.getCurrentLanguage().toLowerCase(),2); 
if(idioma == "es") { 
    link_condiciones = "http://micoachingapp.net/webpanel/archivos/viewTermsES.html"; 
} 
else{ 
    link_condiciones = "http://micoachingapp.net/webpanel/archivos/viewTermsEN.html"; 
} 
Ti.API.info("*** Link: " + link_condiciones); 
// Creamos la ventana 
var winCondiciones = Ti.UI.createWindow({ 
     backgroundColor: clr_aux4, 
     extendEdges:[Ti.UI.EXTEND_EDGE_TOP], 
     barColor: clr_primario_fuerte, 
     tintColor: clr_primario_suave, 
     title: " ", 
    titleControl: Ti.UI.createImageView({ image: 'images/tituloSuperior.png' }), 
     rightNavButton: Ti.UI.createImageView({ image: 'images/dummy.png', width: 35, height: 35, borderRadius: 5 }) 
}); 
// Construimos el visor Web 
var WebView = Ti.UI.createWebView({ 
    top: '30dp', 
    width: Ti.UI.FILL, 
    height: Ti.UI.FILL, 
    url: link_condiciones 
}) 
winCondiciones.add(WebView); 
var btnAceptar = Ti.UI.createButton({ 
    title: L("txt_acepto_terminos"), 
    borderRadius: radioArcoBoton, 
    backgroundColor: color_on, 
    color: 'white', 
    height: '7%', 
    bottom: 3, 
    width: '95%' 
}) 
btnAceptar.addEventListener("click", function(){ 
    RegistrarFecha(fecha, navWindow, winCondiciones, winAnt1, winAnt2); 
}); 
winCondiciones.add(btnAceptar);   
// Mostramos la ventana 
if(IsAndroid()) { 
    winCondiciones.open(); 
} 
else { 
    navWindow.openWindow(winCondiciones);  
    } 

,但我不能看PDF,仅误差修改的LOTE在控制台。

[INFO] : TiUIWebView: (main) [2621,15443] Detected com.htc.software.Sense feature com.htc.software.Sense7.0 
[INFO] : WebViewFactory: Loading com.google.android.webview version  51.0.2704.81 (code 270408100) 
[INFO] : cr_LibraryLoader: Time to load native libraries: 2 ms (timestamps  7860-7862) 
[INFO] : cr_LibraryLoader: Expected native library version number  "51.0.2704.81", actual native library version number "51.0.2704.81" 
[INFO] : cr_LibraryLoader: Expected native library version number  "51.0.2704.81", actual native library version number "51.0.2704.81" 
[INFO] : chromium: [INFO:library_loader_hooks.cc(143)] Chromium logging  enabled: level = 0, default verbosity = 0 
[INFO] : cr_BrowserStartup: Initializing chromium process,  singleProcess=true 
[ERROR] : ApkAssets: Error while loading asset assets/natives_blob_64.bin: 
... 

[INFO] : *** Lenguaje: es 
[INFO] : *** Valor : 2016-08-12 18:00:00 
[INFO] : *** Link:  http://micoachingapp.net/webpanel/archivos/viewTermsES.html 
[INFO] : TiUIWebView: (main) [48206,288996] Detected com.htc.software.Sense  feature com.htc.software.Sense7.0 
[WARN] : cr_AwContents: onDetachedFromWindow called when already detached.  Ignoring 
[INFO] : cr_Ime: ImeThread is not enabled. 
[ERROR] : SensorManager: uid = 10142 
[INFO] : SensorManager: registerListenerImpl: listener =  [email protected]ca6080, sensor = {Sensor name="BMA255 3-axis Accelerometer", vendor="Bosch", version=1, type=1, maxRange=39.24, resolution=0.15328126, power=0.2, minDelay=10000}, delay = 200000, handler = null 
[WARN] : cr_BindingManager: Cannot call determinedVisibility() - never saw a  connection for the pid: 21108 
[WARN] : cr_BindingManager: Cannot call determinedVisibility() - never saw a  connection for the pid: 21108 

这是问题的代码。 它只有一个窗口,一个pdf和一个按钮。

Appelerador,SDK 5.3.1 GA 的Android 5

回答

1

网页视图本身不能显示PDF文件。您可以尝试通过基于网络的PDF阅读器(如Google文档)加载网址,但是您不能只在Web视图中显示PDF。我不知道为什么你认为你可以,WebView显示网页,而不是PDF。

+0

井外部设备浏览器中打开它,它会的工作,这是后话,因为很久以前我做......我该怎么办,你有什么建议。 –

+0

不起作用!我的链接是:http://micoachingapp.net/webpanel/archivos/viewTermsES.html –

1

假设您的网址是:

http://www.appcelerator.com/wp-content/uploads/GettingStartedTitanium_Windows.pdf

1 - 无论是打开外部浏览器链接:

Ti.Platform.openURL('http://www.appcelerator.com/wp-content/uploads/GettingStartedTitanium_Windows.pdf'); 

2 - 假设你的URL直接显示PDF文件上面的网址,你可以使用Ti.Network.HTTPClient得到二进制数据,然后你可以像这样在webview中显示它:

var url = "http://www.appcelerator.com/wp-content/uploads/GettingStartedTitanium_Windows.pdf"; 

var client = Ti.Network.createHTTPClient({ 
    // function called when the response data is available 
    onload : function(e) { 
      var pdfData = this.responseData; // it contains the pdf blob data 

      // Construimos el visor Web 
      var WebView = Ti.UI.createWebView({ 
      top: '30dp', 
      width: Ti.UI.FILL, 
      height: Ti.UI.FILL, 
      data : pdfData  // instead of url, use pdfData blob object 
      }); 

      winCondiciones.add(WebView); 
    }, 

    onerror : function(e) { 
     Ti.API.error(e.error); 
     alert('error'); 
    } 
}); 

client.open("GET", url); 

client.send(); 

3 - 也试试这个,因为我还停留在一些奇怪的问题,一旦发现并没有任何帮助后,它的工作最后加入borderRadius属性:

// Construimos el visor Web 
var WebView = Ti.UI.createWebView({ 
    top: '30dp', 
    width: Ti.UI.FILL, 
    height: Ti.UI.FILL, 
    borderRadius : 2, 
    url: link_condiciones 
}); 
winCondiciones.add(WebView); 

如果它不工作了对于你来说,那么你可能会试图找出一些模块来显示远程PDF文件。祝你好运!!!

+0

工作... –

+0

该死! !不行..感谢反正 –

+0

请试试这个代码: // Construimos EL遮阳网 ** VAR的WebView = Ti.UI.createWebView({ 顶部: '30DP', 宽度:Ti.UI. FILL, height:Ti.UI.FILL, borderRadius:2, url:link_condiciones, }); winCondiciones.add(WebView); ** –

2

你可以试试这个。

webview.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf); 
+0

使用远程pdf的好方法。 –

+0

正在处理它... –

+0

不起作用.... –

1

当我试图运行代码,您所面临的问题可以通过将您在您的评论的一个提供什么完整的URL来解决。

把这个:的 http://micoachingapp.net/webpanel/archivos/viewTermsES.html 代替micoachingapp.net/webpanel/archivos/viewTermsES.html

现在,我看到了什么奇怪的是,如果我打开这个网址http://www.micoachingapp.net/webpanel/archivos/viewTermsES.html,我想知道为什么它需要我通过简单地加入www在其中。

仔细看我上面提到的所有网址,这里有这些:

  1. 此致 - micoachingapp.net/webpanel/archivos/viewTermsES。HTML
  2. 如果粘贴您的网址在任何浏览器,然后你会从地址栏中再次复制它,你就会得到这样的:http://micoachingapp.net/webpanel/archivos/viewTermsES.html
  3. 现在添加WWW - http://www.micoachingapp.net/webpanel/archivos/viewTermsES.html

在WebView中

  • URL 1 SH在你的问题中提到你提到的错误。
  • URL 2是由Chrome或Safari或任何桌面浏览器显示的实际URL。
  • URL 3需要一些其他的pdf ......这怎么可能?

所以你的解决方案在于这3个URL,也许这是一个域问题,或者不知道它是什么,因为我从来没有面对这样的问题。

但是可以肯定,如果你使用Ti.Platform.openURL

+0

嗨Prashant,正确的链接是:[链接](http://micoachingapp.net/webpanel/archivos/viewTermsES.html)我将www和我得到相同的PDF,我真的不知道最新发生的事情,我会粘贴所有错误的问题.. –

+0

我修改了我的问题,完整的代码和控制台输出。 –

+0

是的,我已经找到你刚刚提供的实际链接。但它似乎有什么错误的URL ...为什么没有任何www在该网址????? –