Local notification plugin broken after cordova upgrade - android

I was using this plugin for cordova local notification.
Since cordova 5.0.0 with android#4.0.0 was released it does not work anymore.
I found the bug here.
Is there a way to temporarily solve it?
Thanks

Quick fix is to modify the block starting at LocalNotification:492 with the following:
webView.getView().post(new Runnable(){
public void run(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.sendJavascript(js);
} else {
webView.loadUrl("javascript:" + js);
}
}
});

i did a quick solution https://github.com/ivanhuay/cordova-plugin-local-notifications
try cordova plugin add https://github.com/ivanhuay/cordova-plugin-local-notifications#build_android_solution
i still have problems in some projects: UNEXPECTED TOP-LEVEL EXCEPTION
but it work for me in a new project

Related

How to configure a Android Multi Module APP to work with IBM Mobile Foudation Platfom 8.0's AppAuthenticity

We had a Android app that had work fine with IBM Mobile Foudation Platform 8.0' AppAuthenticity. So we had to split the app into multiple android modules, and AppAuthenticity has not work since.
When trying to login with AppAuthenticity enabled there is no response, ie the success or error callbacks are never fired.
https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/authentication-and-security/application-authenticity/
IBM MFP Server Version: 8.0.2019022810.
IBM MFP Android SDK Version: 8.0.+
Gradle build tool : 3.1.1
Gradle 4.4
The problem happens with debug and release apks.
Log.d("TAG", "loginMobileFirst init"); // This appears in logcat
String securityCheckName = CaixaSecurityCheckChallengeHandler.SECURITY_CHECK_NAME;
WLAuthorizationManager.getInstance()
.login(securityCheckName, this.getCredencial(),
new WLLoginResponseListener() {
#Override
public void onSuccess() {
Log.d(TAG, "loginMobileFirst Success"); // This never appears in logcat
setLogged(true);
callBack.onSuccess(null);
}
#Override
public void onFailure(WLFailResponse wlFailResponse) {
Log.d(TAG, "loginMobileFirst Failure"); // This never appears in logcat
Log.d(TAG, "Erro no login: " + wlFailResponse.getErrorMsg());
callBack.onError(context.getString(R.string.api_error_sistema_indisponivel));
}
});
}
MobileFirst does not yet support app modules of Android. Please create a single apk for your app until this is supported.
Please open a request for enhancement at https://www.ibm.com/developerworks/rfe/execute?use_case=changeRequestLanding&BRAND_ID=0&PROD_ID=702&x=17&y=6
The problem was solved deleting the directory app/src/main/jniLibs. I believe that directory was included in a old version of IBM MFP (7.1)
Thank you, Folks!

Custom plugin adding dependency beforeResolve from Android Studio

I have a custom Gradle plugin that uses the following code:
project.getGradle().addListener(new DependencyResolutionListener() {
#Override
void beforeResolve(ResolvableDependencies resolvableDependencies) {
depsToAdd.each { dep ->
compileConfig.getDependencies()
.add(project.getDependencies()
.create(dep)
}
}
#Override
void afterResolve(ResolvableDependencies resolvableDependencies) {
}
})
This seems to work fine from command line. However, if I refresh gradle from Android Studio, it barfs with Cannot change configuration :app:compile after it has been resolved
My guess is there is some sort of caching going on or Studio builds more variants (I just run the assemble for the variant I want from command line which works every time).
Does anyone know what might be going on and how best to resolve this?
I managed to figure this out. The way do this is to add a DependencyResolutionListener in which you add the dependencies and then remove the listener so it doesn't try to add them on later resolution steps.
compileDeps = project.getConfigurations().getByName("compile").getDependencies()
project.getGradle().addListener(new DependencyResolutionListener() {
#Override
void beforeResolve(ResolvableDependencies resolvableDependencies) {
compileDeps.add(project.getDependencies().create("org.foo:bar:$version"))
project.getGradle().removeListener(this)
}
#Override
void afterResolve(ResolvableDependencies resolvableDependencies) {}
})
I have a working example of a plugin that uses this here

Cordova android getViewTreeObserver with version 4.0.0 and older

I'm developing a Cordova plugin on Android, but with Cordova Android new version (v 4.0.0) some methods I'm using have changed.
In my plugin.java I am using (on cordova android <= 3.7.1) :
//Adding listener on scroll when my plugin is initiated
webView.getViewTreeObserver().addOnScrollChangedListener(this);
//Then later
#Override
public void onScrollChanged() {
//custom actions when scrolling
}
Seem that now with cordova-android V.4.0.0, the way to access webView has changed
"onScrollChanged" message removed. Use view.getViewTreeObserver().addOnScrollChangedListener(...) instead
So now I have to do it this way with cordova-android 4.0.0 :
webView.getView().getViewTreeObserver().addOnScrollChangedListener(this);
Since my plugin has to be compatible with cordova-android < 4.0.0 and cordova-android >= 4.0.0, I was looking for a simple way to check cordova-android current version in my plugin.java to do one or the other method, but so far I haven't found how to do it...
So is there a public method to access corodova-android from an android plugin ? Have I missed an already common method to all cordova-android version do to what I want ?
Thank you all
Solution found for this problem : use of Reflection

Getting the Android SDK directory within a gradle task

Recently the gradle plugin for android got updated (with android studio), after which the previous way of getting to the SDK directory ceased to work. The expression
${android.plugin.sdkDirectory}
which worked in an older version now returns the error
Error:(42, 0) No such property: sdkDirectory for class: com.android.build.gradle.LibraryPlugin
What would be the proper way of getting the android SDK directory being used, preferably independent of the user's configuration such as plugin and gradle version? The script needs to be shareable with several users.
Since all the previous answers depend on the environment or specific user intervention on top of normal configuration, I'll just post my technically messy fix.
if (android.hasProperty('plugin')) {
if (android.plugin.hasProperty('sdkHandler')) {
androidPath = android.plugin.sdkHandler.sdkFolder
} else {
androidPath = android.plugin.sdkDirectory
}
} else {
androidPath = android.sdkDirectory
}
Unlike all previous methods, this actually works, but it still looks hacky.
In gradle.properties set location sdkdir=/home/user/android-sdk and then in gradle you can use $sdkdir
I'm using Android gradle plugin v1.2.3 and this works fine:
${android.sdkDirectory}
You can use
$System.env.ANDROID_HOME
export ANDROID_HOME=/xxx/xxx/ in shell, then use it by System.env.ANDROID_HOME in gradle file.

cordova 1.6.1 android Uncaught TypeError: Cannot call method 'showWebPage' of undefined

i just upgraded phonegap 1.4.1 to 1.6.1 and also upgraded the child browser from https://github.com/libbybaldwin/phonegap-plugins/tree/master/Android/ChildBrowser
and i have added this line in plugins.xml file
<plugin name="ChildBrowser" value="com.phonegap.plugins.ChildBrowser.ChildBrowser"/>
but when i calling this
window.plugins.childBrowser.showWebPage( "http://google.com", {
showLocationBar: true
});
i am geting this error Uncaught TypeError: Cannot call method 'showWebPage' of undefined
Concerning the 1.4.1 vs 1.6.1:
Please be aware that my github repo of phonegap-plugins is what I "froze" in internet time to allow continued use of phonegap 1.4.1 with plugins from that era.
Moving forward to cordova 1.6.1+ you'll need to move on the the official unofficial plugins at
https://github.com/phonegap/phonegap-plugins
Note: These plugins may or may not be updated work with cordova 1.6.1. Please read their individual README's and the blog below from a phonegap engineer:
http://simonmacdonald.blogspot.com/2012/04/migrating-your-phonegap-plugins-to.html
Summary: moving from 1.4.1 to 1.6.1+ and using phonegap plugins will require some vigilance as there were many changes internally between those two versions.
I was able to solve this error by using this code:
try {
var cb = new ChildBrowser();
console.log(cb);
cb.showWebPage('http://www.google.com');
}catch (err){
console.log(err);
}
Although this caused another error:
PhoneGap Build + Cordova + ChildBrowser Error
If you don't get any errors and this solution works - please let me know!
Have been fighting this same error for some days now and found that you can not call the childBrowser right away from your index.html, likely because the initialization of the childBrowser plugin takes some time to complete.
This solution works:
setTimeout(function() {
window.console.log('Opening Childbrowser...');
window.plugins.childBrowser.showWebPage("http://www.google.com", { showLocationBar: true });
}, 3500);
In other words: you have to wait for the childBrowser object to become available, there are more elegant solutions thinkable of course.
DISCLAIMER: tested with the current 1.7.0rc1 Cordaova release, not sure if this works for 1.6.1 as well.

Categories

Resources