Push Plugin for Cordova Android App

0 votes

Hello Vishnu,

 
Hope you are doing well. I want to integrate Push plugin in my cordova app for Android. Could you please provide me the plugin as well any kind of tutorial. Help would be appreciated.
Thanks.
 
Regards,
Prabhjas Singh
asked Oct 31, 2015 in App42 Cloud API-BaaS by prabhjassinghbajwa (25 points)
I am trying to build push services in my existing cordova app. Gone through your tutorial:
 blogs.shephertz.com/2013/12/04/integrating-push-notification-in-phonegap-android-application/

But unable to register : Sending you my logs

11-01 09:41:59.302: I/App42PushNotification(1305): Registration not found.
11-01 09:41:59.415: D/OpenGLRenderer(1305): Render dirty regions requested: false
11-01 09:41:59.491: D/Atlas(1305): Validating map...
11-01 09:41:59.663: I/OpenGLRenderer(1305): Initialized EGL, version 1.4
11-01 09:41:59.716: D/OpenGLRenderer(1305): Enabling debug mode 0
11-01 09:41:59.731: I/qdutils(1305): PartialUpdate status: Disabled
11-01 09:41:59.731: I/qdutils(1305): Left Align: 0
11-01 09:41:59.731: I/qdutils(1305): Width Align: 0
11-01 09:41:59.731: I/qdutils(1305): Top Align: 0
11-01 09:41:59.731: I/qdutils(1305): Height Align: 0
11-01 09:41:59.731: I/qdutils(1305): Min ROI Width: 0
11-01 09:41:59.731: I/qdutils(1305): Min ROI Height: 0
11-01 09:41:59.731: I/qdutils(1305): Needs ROI Merge: 0
11-01 09:41:59.731: I/qdutils(1305): Dynamic Fps: Disabled
11-01 09:41:59.731: I/qdutils(1305): Min Panel fps: 0
11-01 09:41:59.731: I/qdutils(1305): Max Panel fps: 0
11-01 09:41:59.990: I/System.out(1305): com.shephertz.app42.push.plugin.App42GCMService
11-01 09:42:05.111: I/chromium(1305): [INFO:CONSOLE(1)] "Uncaught ReferenceError: registerForPush is not defined", source:  (1)
11-01 09:42:05.119: W/cr.BindingManager(1305): Cannot call determinedVisibility() - never saw a connection for the pid: 1305
11-01 09:42:05.308: I/Timeline(1305): Timeline: Activity_idle id: android.os.BinderProxy@1ac13de8 time:53254644
11-01 09:42:06.572: D/JsMessageQueue(1305): Set native->JS mode to OnlineEventsBridgeMode
11-01 09:42:06.663: I/chromium(1305): [INFO:CONSOLE(8)] "Uncaught ReferenceError: newsService is not defined", source: file:///android_asset/www/scripts/news/home.service.js (8)
I have gone through your several answers regarding the same issue. As i checked stackoverflow questions as well your github repository. And i mentioned everything in my index.html .

1 Answer

0 votes

Hi Prabhjas,

If you are trying to integrate it in your current project then please go through with index.html file that will contains registerForPush function. This function is called from native android side to send device device Id generated from GCM.

Similarly when Push Notification received on Android Native side pushMessageAlert function is called that is defined in index.html file.If you go with index.html or PhoneGapActivity on Android Native side then you will find how the communication will happen between js and Android Native.

If you want to integrate in your own just define function in your main html file that are avialable in index.html file.

Let me know if more queries are concern.

Thanks & Regards

Vishnu Garg

 

answered Nov 1, 2015 by Vishnu Garg (674 points) 1 flag
Hello Vishnu!

Thanks for your reply. I just want to mention that the steps which you have provided to me already implemented in my project. But i am unable to recognize mistake. I read online lot of tutorials regarding the same. Gone through stackoverflow answers as well. Watched your tutorial as well of phonegap. But couldn't find the way.
I am providing you my project's screenshot. Please go through it.
https://www.dropbox.com/s/gd7nyy021teumhw/app42.png?dl=0
Help would be appreciated
Thanks!

Regards,
Prabhjas Singh
Can you please also share the native class of Android from which these API are calling. As I see you are using deprecated version of GCM please attach of use Google Play Service for that. Also you did not need App42 Android SDK you need only App42 js SDK that will do the same for all platform.
Please check screenshots.
https://www.dropbox.com/sh/azhpsp5l40oyjp3/AAAJONjcDfmJeGX_VwH6Qo1la?dl=0

After checking these screenshots. Please mention steps where i need to make changes. And i really appreciate your help. Last time as well you helped me a lot  and i am able to implement these push services into my app. Once again Thanks a lot.
Please provide the MainActivity.java file only. And one more thing are you able to register user on App42 or not with the same.
No i am not able to register the user for push services.
https://www.dropbox.com/sh/azhpsp5l40oyjp3/AAAJONjcDfmJeGX_VwH6Qo1la?dl=0

Uploaded those files please check.
what is the launch URl you you are providing in MainActivity.java file
like I have done in Sample file:///android_asset/app42/index.html
launch URI = index.html
Yes! The same thing.
I have successfully register my device using your Id its working fine, able to register my device for Push as well receiving Push message on device. Please do testing on device as google play services are not available on simulator.Also change the exact path in your MainActivity file like
super.loadUrl("file:///android_asset/app42/index.html");
I got your point but i want to mention that i have tested on my mobile only.
Just tell me do i need to keep you js file which is having app42.js and cordova.js . And just please make it more clear by mentioning which jar files i should remove from my project. And than once again will give a try for my project and hope it works.
Thanks!
You need not require GCM.jar and AndroidSDK.jar in your project and also index.html need app42.js file as well. If you are using eclipse Ide then you can debug the code as well or you can share the project so that i will do the same where exactly you are facing the problem.
One more important thing please make sure you have make necessary changes in AndroidManifest.xml file that require some permissions to do all GCM related stuffs.
I think its better to share project with you. Because from last 2 days i am banging my head but unable to implement push services. Uploading project on the same link. There are 2 zip folders after importing MainActivity and CordovaLib to eclipse you need to provide cordovalib as a library to MainActivity. And once again Thanks.
Please check the same link uploaded.
Its the case in case of angular js function is unable to call from Java side.When you run simple Html its called from Native.
So, How should i implement this thing in my project? Actually i have been using your push services and i dont want to change my push services to any other API.
Any solution please.
I am looking into it why JS function is unable to call. I can provide the alternate solution for this to do the same from Android Native side. but have to find out why this is happening. Once I will find the solution I will update for the same.
Yeah! No problem. That means i too used your code in right way but as i am not a hard - coder so unable to solve this problem. Really appreciate your help. Once again Thanks a lot!
Hye Vishnu,

Hope you are doing well. Are you able to find that bug or problem. Actually, I need to launch this app as soon as possible. Looking for positive reply.

Regards,
Prabhjas Singh
So meanwhile you can try the alternate solution that I am talking about.. use Android SDK.jar Meanwhile I am providing code snippet for device registration.That will help you for Push registration on our server from which you can send the messages.
Fine i can go with alternate solution till that and whenever you are able to get a solution please let me know. Please provide me that code also mention the steps in which way i should go. or else just add that thing in the project which you are having and provide me zip file. Thanks.
Sorry just now checked my mail and got your attachement would be adding that code into my mainactivity. Hope it gonna work for me. Once again thanks.
Yeah! Thanks device is getting registered. Could you please tell me the function to show that push at user end.
The function that show Push on Notification is written in App42GCMService.java file
So, where should i put a alert(msg); So that user can see that push.
The message is already shown in Notification Bar, Notification bar UI is available in App42GCMService.java file.
Yeah! I got that thing but on clicking that message app gets open but no message appears so i need a function which i can call in my app.js file.. And i can put alert in that function so that user can see that message when it clicks on notification.
The main problem is Java in unable to communicate with JS in case of angular. For message you can save message in a file in asset folder and read it from there. Or you can save it in device preferences and retrieve the same using Cordova plugin from preferences.
I am able to solve this problem. but need your help to place .apk at google play store. I tried but google play is not accepting it gives this error.
This app uses software that contains security vulnerabilities for users.

Below is the list of vulnerabilities and the corresponding APK versions that were detected in your recent submission. Please upgrade your app(s) as soon as possible and increment the version number of the upgraded APK.
Have you change the application version in AndroidManifest.xml which you want to update
Yes i have udated that version it gets uploaded their but after checking by google play within a hour i received a mail with explaining error.

Vulnerability    APK Version(s)
Apache Cordova
The vulnerabilities were fixed in Apache Cordova v.3.5.1. For more information about the vulnerabilities, and for guidance on upgrading Apache Cordova, please see https://cordova.apache.org/announcements/2014/08/04/android-351.html. For other technical questions about Apache Cordova, please post to https://www.stackoverflow.com/questions and use the tags "android-security" and "cordova."

20300
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...