Device: Android
Target Version: 25
Cordova version: 7.0.1
I'm using cordova-plugin-geolocation https://www.npmjs.com/package/cordova-plugin-geolocation but with some devices doesn't work. I tried the application
with these devices:
Huawei P9 Lite VNS-L31 Android 7.0 ---> work
Huawei P9 Lite VNS-L21 Android 7.0---> work only if i disallow the battery optimization of the application.
Huawei P9 Android 7.0--> doesn't work
One Plus 3 Android 7.1.1 --> work
Samsung S8 Android 7.0 --> work
CODE:
navigator.geolocation.getCurrentPosition(onSuccessPoint, onErrorPoint,{ timeout:10000 });
var onSuccessPoint = function (position) {
///SUCCESS CODE
}
function onErrorPoint(error) {
//ERROR CODE
}
You app must run in background mode , if your app not white listed under battery optimization your app won't run. use this cordova plugin to white list your app from battery optimization,
Install
cordova plugin add https://github.com/thomas550i/cordova-plugin-doze-Optimize
Javascript code
cordova.plugins.DozeOptimize.IsIgnoringBatteryOptimizations(function (responce){
console.log("IsIgnoringBatteryOptimizations: "+responce);
if(responce=="false")
{
cordova.plugins.DozeOptimize.RequestOptimizations(function (responce){
console.log(responce);
}, function (error){
console.error("BatteryOptimizations Request Error"+error);
});
}
else
{
console.log("Application already Ignoring Battery Optimizations");
}
}, function (error){
console.error("IsIgnoringBatteryOptimizations Error"+error);
});
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 developed an application that uses DJI SDK. When installed as an system application it crashes on Launch because its not able to load the libraries. It works fine when installed as normal application.
Steps followed to make system application
1)Rooted the device
2)Copied the .apk file to system/app directory
3)Rebooted the device
4)App was installed as default application but crashed on Launch
After commenting out the following line related to DJI SDK and followed the same steps as above. It worked fine as system app.
Helper.install(context);
The implementation of Helper class which is in DJI SDK is as below:
public static void install(Application app) {
Object var1 = null;
try {
System.loadLibrary("DexHelper_sdk");
if (PPATH != null) {
System.load(PPATH);
}
} catch (Error var3) {
;
}
String app_dataDir = app.getApplicationInfo().dataDir;
DexInstall.install(app, new File(app_dataDir + "/.cache_sdk/sdkclasses.jar"));
}
As far as my understanding the crash is because the system is failing to load the libraries.
My gradle looks similar as in the following link:
https://github.com/dji-sdk/Mobile-SDK-Android/blob/master/Sample%20Code/app/build.gradle
this issue has been fixed since 4.6 version of Android MSDK, pls try to update to the later version, right now the 4.7.1 has been released.
I have written an android app using Ionic. The app uses $cordovaDatePicker from the ngCordova website, and this works fine when I do ionic run android and install the app onto my phone.
The problem is if I run ionic build android, then install the apk from a website to test it in the real world, the datepicker doesn't show at all. The function it's in is being called fine, and if I console.log $cordovaDatePicker then I can see an object is output as I'd expect.
The function I am calling looks like this:
var options = {
date: new Date(),
mode: 'date'
};
$cordovaDatePicker.show(options).then(function(date) {
$timeout(function() {
scope.selectedDateTime = date;
}, 50);
}, function(err) {
alert(err);
});
I've tried adding every permission from this page and that still didn't help. Because the datepicker window is never shown, neither the success or error callbacks are reached. Does anyone have any ideas?
Thanks for any help.
Got this working in the end by:
Upgrading Ionic to the latest version via npm
Removing the datepicker plugin (v0.8.1)
Installing it again with the latest version (v 0.8.9)
Not sure what changed but it's working OK now!
I'm having an issue with some android devices when changing the font-size display setting through configuration.
In web browser my app is simple ignoring this. This is true for some other mobiles too.
But with some specific mobiles (like Motorola G or X) changing this config also affects my Phonegap app.
I don't know how to avoid this to make the app look consistent
I've found a solution using this cordova plugin: com.phonegap.plugin.mobile-accessibility
You have to follow installation instructions for the plugin, and then you can use it inside Ionic app. You only have to ensure to call its functions after Cordova 'deviceready' callback (accesed by $ionicPlatform.ready in the example below):
angular.module('app').controller('IndexController', function ($ionicPlatform, $window) {
$ionicPlatform.ready(function(){
if($window.MobileAccessibility){
$window.MobileAccessibility.usePreferredTextZoom(false);
}
});
});
For anyone using Ionic. Documentation is here.
Install
$ ionic cordova plugin add phonegap-plugin-mobile-accessibility
$ npm install --save #ionic-native/mobile-accessibility
Add to module, i.e. app.module.ts
import { MobileAccessibility } from 'ionic-native';
#NgModule({
providers:[MobileAccessibility]
});
In app.component.ts
constructor( mobileAccessibility: MobileAccessibility, platform: Platform) {
platform
.ready()
.then(()=>{
mobileAccessibility.usePreferredTextZoom(false);
});
}
The navigator.notification.prompt is not working on android v2.3.3 (tested on motorola droid2 global). The code runs without throwing an error, but the prompt does not appear on the screen. The same app code runs fine on v4.1.2 (tested on samsung sch-1200). Any thoughts what could be preventing the prompt under v2.3.3?
I have checked cordova.apache.org docs and there is no mention of being version specific. I've also tried the other notification methods without luck.
Here is my code:
console.log('before notification prompt');
try {
navigator.notification.prompt(
'Enter the new Category', // message
onNewCategory, // callback
'Categories', // title
['Save', 'Cancel'], // buttons
'' // default text
);
}
catch (e) {
console.error(e.message);
}
console.log('after notification prompt');
The console output shows that it ran normally with no error.
'Cordova plugin ls' shows the plugin is successfully installed.
Thanks for your help.
This noted issue with the dialogs plugin has now been fixed and merged on to the dialogs repository. Hopefully this should be available in the next release of the plugin.
A possible workaround until this is released would be to replace the contents of Notification.java in platforms\android\src\org\apache\cordova\dialogs\ with this commit contents.