I'm developing an APP using Ionic V6 with Angular and Cordova, but I'm having a problem using the In App Browser, when I use the app on the computer (ionic serve) it works fine, but when I test it on the phone (ionic cordova run android) the button that should open the web page does not work, there is simply no action in the app, nor does it show an error in the console.
I'm following this documentation: https://ionicframework.com/docs/native/in-app-browser
I've already used In App Browser in other apps, but with the older ionic and using this documentation: https://ionicframework.com/docs/v3/native/in-app-browser/ (which doesn't work in my app with ionic v6)
Running the ionic info command, I have this data:
Ionic:
Ionic CLI : 6.16.3 (C:\Users\Gabri\AppData\Roaming\nvm\v14.17.0\node_modules\@ionic\cli)
Ionic Framework : @ionic/angular 6.1.0
@angular-devkit/build-angular : 13.2.6
@angular-devkit/schematics : 13.2.6
@angular/cli : 13.2.6
@ionic/angular-toolkit : 6.1.0
Cordova:
Cordova CLI : 10.0.0
Cordova Platforms : android 9.1.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 4 other plugins)
Utility:
cordova-res (update available: 0.15.4) : 0.15.3
native-run (update available: 1.6.0) : 1.4.0
System:
Android SDK Tools : 26.1.1 (C:\Android\android-sdk)
NodeJS : v14.17.0 (C:\Program Files\nodejs\node.exe)
npm : 6.14.13
OS : Windows 10
In the code I use the following import:
import { InAppBrowser } from '@awesome-cordova-plugins/in-app-browser/ngx';
The construtor:
constructor(private iab: InAppBrowser) {}
And the function that opens the browser:
abrirProvaOuGabarito(arquivo: string) {
this.iab.create(this.servidorCaminhoBase arquivo, '_system');
}
The generated link would be for example this: https://plataforma.aerosafeead.com.br/Uploads/simulados/prova-1653513297.pdf
I also tested with a google link, with HTTP and HTTPS, I also tried replacing _system
with _blank
or leaving nothing, I also tried opening the page with window.open()
and putting a simple link in the HTML (< a href=""></a>
), I tested it on two different phones, but the result is always the same.
In my package.json the imports are these:
"@awesome-cordova-plugins/core": "^5.41.0",
"@awesome-cordova-plugins/in-app-browser": "^5.43.0",
InAppBrowser is in my app.module.ts
providers
And in my config.xml I just added the <allow-navigation href="*" />
different from what comes by default, I don't know if it interferes, but I used it because I run youtube videos in my app.
I've looked in several places and no solution solved, I don't know what else to change.
EDIT:
I created a new APP to test, a clean app, using the same environment, and by default it comes with a link on the home page (blank app), after creating it, I ran the app with ionic serve
and the links worked normally, but if you run it on your cell phone with ionic cordova run android
, even though the app is completely empty, the error is the same
CodePudding user response:
You need to call the show()
method to actually show the browser with the page.
abrirProvaOuGabarito(arquivo: string) {
const browser = this.iab.create(this.servidorCaminhoBase arquivo, '_system');
browser.show();
}
CodePudding user response:
try
const browser = this.iab.create(this.servidorCaminhoBase arquivo, '_blank');