Software Archive
Read-only legacy content
17061 Discussions

Problem with Standard Cordova Plugin InAppBrowser on Android

And_P_
Beginner
4,121 Views

In my App I transfer file and picture from my database on external server a save them locally on smartphone with FileTransfer Plugin. Then to view the downloaded file I use InAppBrowser plugin (V. 0.5.4).  This is my code:


if (intel.xdk.device.platform == 'Android' || intel.xdk.device.platform == 'android')
 var path = strUrl;
 window.open(path, '_system', 'location=no');
}
else {
 var url = strUrl;
 window.open(url, '_blank', 'location=no');
}


Everything worked well and, for example, I can view a pdf file with default reader on device then i can close them and return to my app.
suddenly while all running fine on ios, on Android devices can no longer go back to my app. In fact there is no button "done" or no way to close the viewer pdf or jpg, for example, and return to my app. If I click the back button on device the application will also close my app and I must log again.
Is use InAppbrowser because it is the only way to view pdf files with the player by default on Android devices. So i don't know why that plugin suddendly show that problem.
Any help and advice is appreciated
Thanks

0 Kudos
14 Replies
John_H_Intel2
Employee
4,121 Views

Are you targeting a specific version of the plugin? If you are not, and the author of the plugin changed something recently and published a new version, your build will be using the newest version unless you target a specific version when you add the plugin to your project.

0 Kudos
And_P_
Beginner
4,121 Views

I use the standard version of Intel XDK i.e 0.5.4

0 Kudos
John_H_Intel2
Employee
4,121 Views

That plugin has not changed in quite some time.

Did you update your device recently?

What happens if you include the pdf in your app and launch it locally with the inAppBrowser? Does it render correctly?

 

0 Kudos
And_P_
Beginner
4,121 Views

no recent changes...

as I said in my first post i download file pdf correctly and my app lauch it with inAppBrowser and render it correctly..This in not the problem..the problem is I can't close pdfviewer and I can't back to my app..if I touch back button of device it close the viewer and also the app...

in IOS all is ok

0 Kudos
Pamela_H_Intel
Moderator
4,121 Views

Are you using Android's native webview or are you using Crosswalk (did you choose Crosswalk for Android in your build settings)?

0 Kudos
Swati_S_Intel1
Employee
4,121 Views

Use target as '_blank' for Android as well.  

window.open(url, '_blank', 'location=no');

In your code you are using '_system'. When you use '_system', the app opens an instance of system browser and the control gets transferred to the browser instance. When you use '_blank', an inAppBrowser instance gets created within your app and the back button is displayed as part of that instance and pressing back button brings the control back to the app.

 

 

0 Kudos
And_P_
Beginner
4,121 Views

I use _system because is the only way i can view pdf file.....if i use _blank I can't view them on android...

with _system a time ago it was all ok!

0 Kudos
And_P_
Beginner
4,121 Views

i use Android not Crosswalk for Android in my builds

0 Kudos
Swati_S_Intel1
Employee
4,121 Views

InAppBrowser plugin does not support pdf viewing on Android. The system browser does, but then as I said it will not give control back to your app. Since you are downloading the pdf on your device, I would recommend you use a file opener plugin to view the pdf. 

https://github.com/don/FileOpener (Android only) or

https://github.com/pwlin/cordova-plugin-file-opener2 (Android and iOS)

Another option is, if your file is served from your own server then you can set up pdf.js library (https://mozilla.github.io/pdf.js/) on your server and directly point inAppBrowser to the pdf.js location with your pdf filename.

window.open('http://YOUR_DOMAIN/pdfjs/web/viewer.html?file=YOUR_PDF_URL', '_blank', 'location=no');

Hope this helps.

 

0 Kudos
And_P_
Beginner
4,121 Views

thanks for your explanation very useful ...i already tried with fileopener but i can't open file...i try with pfd.js....but in any case I do not understand why using the following code for a while everything was working fine on Android

if (intel.xdk.device.platform == 'Android' || intel.xdk.device.platform == 'android')
 var path = strUrl;
 window.open(path, '_system', 'location=no');
}
else {
 var url = strUrl;
 window.open(url, '_blank', 'location=no');
}

thanks so much

0 Kudos
And_P_
Beginner
4,121 Views

i try with my app's release of may 2015 and all work very well...but with release of now not...maybe new version of xdk has some problem...

0 Kudos
Swati_S_Intel1
Employee
4,121 Views

I have seen back button work on some devices when you use '_system' but may not work on all devices. If you are using the same device and if it worked for you earlier, check these few things.

1) You are missing opening curly bracket '{' for your if statement in the code snippet you provided. Correct that, if that's in your actual code.

2) In your code you are usig  Intel XDK device plugin to check for Android platform, make sure you check the Intel XDK device plugin checkbox on the right side of plugins section

3) Make sure you have set the whitelisting in Projects > Build Settings  properly. Put * in the Access List box and select internal whitelist. 

 

0 Kudos
And_P_
Beginner
4,121 Views

on same device old release work ..newest not!

if i miss some bracket when i launch emulator it must to check it!

I have check device plugin

I put * in the Access List box and select internal whitelist

 

0 Kudos
And_P_
Beginner
4,121 Views

I find the problem:

my app use nfc plugin too and I need to modify Android Manifest to add an intent to open my app where read nfc tag.

I Use this code:

<?xml version="1.0" encoding="utf-8"?>

<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="com.sicursell.wwsrsicursell" version="1.0.0">

<name>Intent NFC</name>

<description>Modify AndroidManifest.xml</description>

<license>MIT</license>

<keywords>android, WebIntent, Intent, Activity, NFC</keywords>

<engines>

<engine name="cordova" version=">=3.0.0" />

</engines>

<!-- android -->

<platform name="android">

<config-file target="AndroidManifest.xml" parent="/manifest/application">

<activity android:label="@string/app_name" android:name="CordovaApp" android:noHistory="true" >

<intent-filter>

<action android:name="android.nfc.action.TAG_DISCOVERED" />

<category android:name="android.intent.category.DEFAULT" />

</intent-filter>

</activity>

</config-file>

</platform>

</plugin>

if I delete android:noHistory="true" all work well and I can view file (image or pdf) then return to my app without problem

Thanks to all

 

0 Kudos
Reply