I am trying to call a REST API from Ionic code. The REST API is also developed in my local system. The IP address of my Windows system is say abc.def.gh.i. The GET request API has this URL: http://abc.def.gh.i:8088/check-price/code-001
Problem
I am able call the REST API when I build/run the app using command ionic lab (as this opens up the app on browser). This also works when Ionic code runs on an emulator using the command ionic cordova run android --e78ab88d, as this opens the emulator in same system.
This fails when I run the code on actual Android device by using command ionic cordova run android --device.
Any idea what the issue is?
Here is the provider class that is invoked when an item is passed from the text input:
#Injectable()
export class ServiceProvider {
private urlGetStudentTest: string = "http://abc.def.gh.i:8088/check-price";
callCheckPrice(item) {
console.log("------*****-----" + this.urlcheckprice + '/' + item);
console.log("-----------" + item);
return this.http.get(this.urlcheckprice + '/' + item) .map(res => res.json())
}
}
I can see the two console outputs, after this application stops.
Related
I have a simple capacitor plugin with the cli generated echo method.
While I can access the arguments supplied from webview in the Java code, I can't seem to return values from the plugin back to webview.
// Java Plugin method
#PluginMethod()
public void echo(PluginCall call) {
String value = call.getString("value");
JSObject ret = new JSObject();
value = implementation.echo(value);
ret.put("value", value);
Logger.debug("MyPlugin.echo - ret: " + ret.toString());
call.resolve(ret);
}
// Ionic app code
MyPlugin.echo({ value: "Hello world!" })
.then(res => {
console.log('MyPlugin.echo success, res:', res);
}).catch(err => {
console.log('MyPlugin.echo error:', err);
});
Capacitor module versions:
"#capacitor/android": "^3.0.0-rc.0",
"#capacitor/core": "^3.0.0-rc.0",
What am I missing?
TIA.
Well, I found the root cause.
The issue is with Android Emulator with API 25. With this version of Android, capacitor plugin API call's response values do not seem to be marshalled to the caller.
I then tried emulators with API 26 & API 27. Same problem.
Lastly I tried an emulator with the latest API, level 30. This works fine.
Seems like Capacitor Android native plugin interface has issues with older API levels. May be this is a known issue.
EDIT: Further investigations have shown that this is not an issue with the Capacitor interface per se. Instead it has to with console.log messages not being captured by Android Studio log window (or adb logger). If you use Chrome developer tools to inspect the device, you do get the console.log messages as expected.
I have successfully taken build using ionic cordova build android. After installing the app in my mobile, for checking the enquiry. The post method method is not saved in the DB. So I taken the browser build for checking the error, but the browser is working fine.
Homepage.component.ts
onSubmit(form) {
let addurl;
addurl = this._https.enquiry(this.homecontents);
addurl.subscribe(success => {
form.form.markAsPristine();
form.resetForm();
});
}
Http.service.ts
enquiry(senddata){
return this.http.post(this.url_api+"enquiry",senddata);
}
Browser:
In browser the post method is working fine.
Android:
In the ionic after taking the build and check the post method its not working
My app is under Ionic 4 for android and I have to open/run/launch external app (for exemple com.google.android.youtube or com.sygic.truck) -> for instance, any installed app.
I tested many options without any success :
InAppBrowserModule (using application://my.package.name).
Cordova plugin lampaa (I didn't find any ways to use it under angular/ts app type).
I tried also webIntent using package option and action option calling the main Activity.
For InAppBrowserModule, i'm stuck with the http:// protocole appended before my app url.
For Lampaa, i'm stuck with the undefined startApp (even after following other threads suggestions).
And for webIntent, I don't think that it's relevent for my issue.
Any suggestions ?
Thanks in advance !
[EDIT]
I finally make it works !
You can use one of those 2 lines :
this.iab.create('android-app://com.google.android.youtube',"_system");
window.open('android-app://com.google.android.youtube',"_system");
You can replace com.google.android.youtube by any application package name !
You can check if the user is on Android, have the app installed and later open it as follow:
constructor(
private platform: Platform, // from 'ionic-angular'
private appAvailability: AppAvailability, // from '#ionic-native/app-availability'
private iab: InAppBrowser, // from '#ionic-native/in-app-browser'
) {}
openYoutube() {
const package = "com.google.android.youtube"
if(this.platform.is('android')) {
this.appAvailability.check(package)
.then(()=> {
this.iab.create('android-app://'+package, '_system', 'location=yes')
})
.catch(()=> {
// not installed
)
} else {
// not on Android
}
}
For ionic 4 we can use
ionic cordova plugin add cordova-plugin-app-launcher
npm install #ionic-native/app-launcher
You can use the following cordova plugin to check if other apps are installed and launch them.
ionic cordova plugin add cordova-plugin-app-launcher
npm install #ionic-native/app-launcher
Simple Cordova plugin to see if other apps are installed and launch them.
I'm building an ionic 3 app, and I'm using PouchDB and CouchDB for synchronization.
To create the remote databases, I used the db.info() command as recommended in the official documentation:
note: The remote database will not be created until you do an API call, e.g.: db.info(). The reason behind that is that the PouchDB constructor is completely synchronous, for ease of error handling (i.e. no asynchronous errors).
Here is the code I used in my app:
let remotex = new PouchDB('https://' + auth + '#' + 'xxx.xx:6984/' + xx + '_xx');
return remotex
.info()
.then((res) => {
console.log(res);
return res;
})
.catch(function(err) {
console.log('error : ', err);
return err;
});
This is working fine; the remote databases are created and the sync is working great only when I build my app in the debugging mode:
ionic cordova build android --prod --buildConfig
But, the the remote databases are not created when in the release version:
ionic cordova build android --prod --release --buildConfig
The .info() method is returning:
{"status":0, "name":"unknown"}
Does the command ".info()" work only in debug mode ?
Is there any other method to create the remote databases and make the sync working ?
Thank you.
It turns out that it was a problem related to the SSL certificate that I configured on the CouchDB server. The certificate was self-signed, so when the app is in the debug mode, the cordova build process make it ignoring errors generated by invalid certificates. But this is not the case for release mode.
So I modified the way the app is built in release mode to allow it making "insecure" requests. As I'm building the app for Android, I changed the file
SystemWebViewClient.java located in project/platforms/android/CordovaLib/src/org/apache/cordova/engine/ this way:
if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
// debug = true
handler.proceed();
return;
} else {
// debug = false => comment this
//super.onReceivedSslError(view, handler, error); => comment this
handler.proceed(); // added this
return;
}
This is just a work around and should not be used in production mode.
I found this solution here.
I can't run Xamarin.UITests on any Android simulator/emulator. Any suggestions? I get the following errors when I try:
Google Emulator:
SetUp: System.Exception: Unable to run on a physical device without activation.
The full version is available for Xamarin Test Cloud customers, for more information contact sales#xamarin.com
If you are already a Xamarin Test Cloud customer, you can provide your api in one of the following ways:
* Adding it ConfigureApp using the ApiKey method
* Setting the XTC_API_KEY environment variable
* Adding the following attribute to your Properties/AssemblyInfo.cs file: [assembly: Xamarin.UITest.TestCloudApiKey(YOUR_API_KEY)]
* Place an xtc_api-key file containing your api key in an upstream directory from the test assembly
Xamarin Android Player:
SetUp: System.Exception: No devices connected
GenyMotion:
SetUp : System.Exception : Failed to execute: /users/erikandersen/Library/Developer/Xamarin/android-sdk-macosx/platform-tools/adb devices - exit code: 1
cannot bind 'tcp:5037'
ADB server didn't ACK
* failed to start daemon *
error:
adb server is out of date. Killing…
After updated GenyMotion to 2.3.1, I now get the following error:
SetUp: System.Exception: App Installation failed with output: 12050 KB/s (11199602 bytes in 0.907s)
pkg: /data/local/tmp/final-xxxxxx.apk
Failure [INSTALL_FAILED_CPU_ABI_INCOMPATIBLE]
NUnit Code
AndroidApp _app;
public string PathToAPK { get; set; }
[TestFixtureSetUp]
public void BeforeAll ()
{
var path = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
var info = new FileInfo(path);
var directory = info.Directory.Parent.Parent.Parent.FullName;
PathToAPK = Path.Combine(directory, "Android", "bin", "Debug", "Demo.Android.apk");
}
[SetUp]
public void BeforeEach ()
{
_app = ConfigureApp.Android.ApkFile (PathToAPK).StartApp ();
}
[Test]
public void TestInvalidEmail ()
{
_app.EnterText (c => c.Class ("UITextField"), "");
}
TestInvalidEmail() is never called because NUnit fails on
_app = ConfigureApp.Android.ApkFile (PathToAPK).StartApp ();
Background:
I'm using Xamarin.UITests for an iOS/Android application I'm developing and we're having issues with the Android side of things. iOS works fine. I've written each test twice, once in C# and once in Ruby using calabash, in order to isolate the issue. Calabash works fine, but any C# NUnit Test Project fails to connect to any emulator I try launching.
What I've tried:
Making sure an emulator is already running before I run the tests
Making sure only 1 emulator is running
Restarting the adb server
Trying multiple types of emulators (i.e. Xamarin Android Player, Gennymotion, and the Google Emulator)
So, after several hours of working on this, this fixed it:
Upgrade GennyMotion to 2.3.1
Delete my old GenyMotion Simulator (Nexus 4) and create a new one
Add support for all ABIs in my Android Build settings
Android Project > Options > Android Build > Advanced Tab > Supported ABIs > Check "armeabi, armeabi-v7a, x86" > OK
Generate a new .apk file via the terminal (while inside the Android project directory)
/usr/bin/xbuild /t:Package /p:Configuration=Release .csproj
Resigned the .apk via calabash-android
calabash-android resign ./bin/Release/.apk
In Xamarin Studio, set my Startup Project as the my UITest project
Launch GenyMotion simulator
Ran the tests under the Debug configuration with only the GenyMotion simulator active
And it worked! I still can't run UI tests with the Google Emulator or the Xamarin Android Player. Funny thing is, I also can't debug my Android project using GenyMotion. It's only good for UITests. SO here's my current setup:
Xamarin Android Player - Normal debug
GenyMotion - UITests
I had the same problem and fixed by setting the ApiKey when setting ConfigureApp.
[SetUp]
public void SetUp()
{
_app = ConfigureApp.iOS.AppBundle(PathToIPA).ApiKey("YOUR_API_KEY_HERE").StartApp();
}
As in here. Just put your ApiKey there.
Note: I didn't have this problem with Xamarin Android Player. I didn't have this problem with AVD running an Android 5.0 emulator. I only had this problem with AVD running an Android 4.0.3 emulator.