I am unable to add user for push notification in my android app

+1 vote

I am unable to add user for push notification in my android app:

Below is the snippet of code that was provided in tutorial for Android pus notification

 

                                                                !!!!----code---!!!

String Api_key = "40d69f76415ab92de0a85d9eb5fbd667eb79bd9b7d1b37fc8af56fc2352f002d";
String Secret_key =  "4a990f005383bad9550d1fec202ccde93e6db1257d9cdf5dd1186a55bd3a6a0a";
 
 
@Override
public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
       ((TextView) findViewById(R.id.page_header)).setText("Main Activty");
       App42API.initialize(this,Api_key,Secret_key);
       App42API.setLoggedInUser("hitesh.vinod.jain111@accenture.com") ;
       Util.registerWithApp42("starry-app-723");
       
}
 
                                              !!!-- code ends here --- !!!
 
Where m i going wrong please help...
Was asked to pass on the 4 parameters, API key, Secretkey, LggedInAsUser and Goog project Id
closed with the note: Problem resolved
asked Oct 6, 2014 in App42 Cloud API-BaaS by Hitesh Jain (16 points)
closed Oct 27, 2014 by sushil
Hello Hitesh,
 
Please replace your Google Project name with Google Project number in the below function: Util.registerWithApp42("starry-app-723"); and run your project again.

Also put  App42Log.setDebug(true); before Util.registerWithApp42("starry-app-723"); and share the logs details if your device is not registered on App42.

 
Thanks.
Himanshu Sharma
Hello Hitesh,

Please copy your project number instead of Project id as shown in the below picture and let us know if it helps:
http://cdn.shephertz.com/repository/files/7a6b25fc1d82dc1e1d614466a1c549a6e24f4a6b9c32fbded52c0ea224b9cbc4/3e4564eea9e2db1835f9e8c83803b5f2f2b3c503/project_number.png

Thanks,
Himanshu Sharma
Himanshu,

Thanks a lot for the quick reply, it did helped :)

After making that change, I was able to register the device and can see the registered device on App42 Cloud.
But when i send push notification from there, it show that the notification was send successfully, but m not getting that on the device.

No error but notification dint came from the server.
I m trying the example that was given in the basic tutorial here


http://api.shephertz.com/tutorial/Push-Notification-Android/

Here i was asked to change only the 4 parameters in mainactivity, (keys, project id and logged in user)

Anything else needs to be changed?

Please help
I changed the GCM keys for "android" again, and it worked :) :)

Thanks a lot!!!!!!!!!! :) :) :)
Hello Hitesh,

Great to hear that you are receiving push messages. Please close this thread if you do not have more queries related to this question.

Thanks,
Himanshu Sharma
Hi, I get error on this line : Util.registerWithApp42("angular-axle-712");

It says : The method registerWithApp42 is undefined for the type Util.

Can you please help ?
Hey, Sample project itself contains Util class and there is a definition of "registerWithApp42" method. So you need to import right Util class in your project, import should be :

"com.example.app42sample.Util"

Thanks
Vishnu
I hope your query has been resolved. Let us know if you need further assistance regarding this.
not really , I am still not able to get a user to register and be visible on App42 dashboard

i followed the steps exactly and the on Create code is as below :

public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.gradelist);      
            
            App42API.initialize(this,"5ee5a4157f44875f3cbaeb51f8ae0b5e8f137f5b9aa9355ad7e96eb4a640dbe5",
                    "22942ed15105338886ed5ab617a7f2c44c100f890cb4079a788fdb0dd7838d51");
            
            App42API.setLoggedInUser("CheriX") ;  
            Util.registerWithApp42("36772734895");


no  errors, no messages to determine where i could be wrong ...
Hey Jingahr, have you followed all the mentioned in ReadME file of sample project.
Will you please share logs of logcat, so I will help you in a better manner.
log says :


12-01 00:14:23.104: I/dalvikvm(696): Could not find method com.shephertz.app42.paas.sdk.android.App42API.initialize, referenced from method com.example.app42sample.MainActivity.onCreate
12-01 00:14:23.114: W/dalvikvm(696): VFY: unable to resolve static method 6195: Lcom/shephertz/app42/paas/sdk/android/App42API;.initialize (Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)V
12-01 00:14:23.114: D/dalvikvm(696): VFY: replacing opcode 0x71 at 0x001b
12-01 00:14:23.114: D/dalvikvm(696): VFY: dead code 0x001e-0028 in Lcom/example/app42sample/MainActivity;.onCreate (Landroid/os/Bundle;)V
12-01 00:14:23.194: D/AndroidRuntime(696): Shutting down VM
12-01 00:14:23.194: W/dalvikvm(696): threadid=1: thread exiting with uncaught exception (group=0x40015560)
12-01 00:14:23.214: E/AndroidRuntime(696): FATAL EXCEPTION: main
12-01 00:14:23.214: E/AndroidRuntime(696): java.lang.NoClassDefFoundError: com.shephertz.app42.paas.sdk.android.App42API
12-01 00:14:23.214: E/AndroidRuntime(696):     at com.example.app42sample.MainActivity.onCreate(MainActivity.java:23)
12-01 00:14:23.214: E/AndroidRuntime(696):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-01 00:14:23.214: E/AndroidRuntime(696):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-01 00:14:23.214: E/AndroidRuntime(696):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-01 00:14:23.214: E/AndroidRuntime(696):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-01 00:14:23.214: E/AndroidRuntime(696):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-01 00:14:23.214: E/AndroidRuntime(696):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-01 00:14:23.214: E/AndroidRuntime(696):     at android.os.Looper.loop(Looper.java:123)
12-01 00:14:23.214: E/AndroidRuntime(696):     at android.app.ActivityThread.main(ActivityThread.java:3683)
12-01 00:14:23.214: E/AndroidRuntime(696):     at java.lang.reflect.Method.invokeNative(Native Method)
12-01 00:14:23.214: E/AndroidRuntime(696):     at java.lang.reflect.Method.invoke(Method.java:507)
12-01 00:14:23.214: E/AndroidRuntime(696):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-01 00:14:23.214: E/AndroidRuntime(696):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-01 00:14:23.214: E/AndroidRuntime(696):     at dalvik.system.NativeStart.main(Native Method)



1111111111111111111111111111111111111111111111111111111111111111111111

am trying the sample downloaded and trying to run it now ...
now it crashes with above error.

something wrong with Initialize line in MainActivity :

import com.shephertz.app42.paas.sdk.android.App42API;

public class MainActivity extends Activity {


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ((TextView) findViewById(R.id.page_header)).setText("Main Activty");
         App42API.initialize(
                    this,
                    "5ee5a4157f44875f3cbaeb51f8ae0b5e8f137f5b9aa9355ad7e96eb4a640dbe5",
                    "22942ed15105338886ed5ab617a7f2c44c100f890cb4079a788fdb0dd7838d51");
            App42API.setLoggedInUser("someusername") ;
            Util.registerWithApp42("319644419117");
Hey, Have you checked Android Private library and Android dependencies option in your project properties>java build path > order and export section.
As your project logs are indicating error " java.lang.NoClassDefFoundError: com.shephertz.app42.paas.sdk.android.App42API"

Thanks
Vishnu
Thanks , The sample App now works fine and I can see the user registered and am able to send a PUSH ...

but my own custom app does not work , when i tried to integrate the PUSH ,,, can u pls check ? see log below :

12-01 11:49:08.852: D/CHECK(496): .. Registeration Check ..
12-01 11:49:08.922: V/GCMRegistrar(496): Registering receiver
12-01 11:49:08.932: D/GCMRegistrar(496): resetting backoff for jinga.edu.schoolrapidlearnerpad
12-01 11:49:08.942: V/GCMRegistrar(496): Registering app jinga.edu.schoolrapidlearnerpad of senders 319644419117
12-01 11:49:09.132: D/dalvikvm(496): GC_EXTERNAL_ALLOC freed 124K, 50% free 2758K/5511K, external 1662K/2137K, paused 87ms
12-01 11:49:09.882: I/dalvikvm(496): Could not find method android.app.AlertDialog$Builder.<init>, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.a
12-01 11:49:09.892: W/dalvikvm(496): VFY: unable to resolve direct method 147: Landroid/app/AlertDialog$Builder;.<init> (Landroid/content/Context;I)V
12-01 11:49:09.892: D/dalvikvm(496): VFY: replacing opcode 0x70 at 0x0037
12-01 11:49:09.942: D/dalvikvm(496): DexOpt: couldn't find field Landroid/content/res/Configuration;.smallestScreenWidthDp
12-01 11:49:09.952: W/dalvikvm(496): VFY: unable to resolve instance field 75
12-01 11:49:09.952: D/dalvikvm(496): VFY: replacing opcode 0x52 at 0x0012
12-01 11:49:09.952: D/dalvikvm(496): VFY: dead code 0x0014-0018 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b (Landroid/content/res/Resources;)Z
12-01 11:49:10.012: I/dalvikvm(496): Could not find method android.app.Activity.getFragmentManager, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.showErrorDialogFragment
12-01 11:49:10.012: W/dalvikvm(496): VFY: unable to resolve virtual method 94: Landroid/app/Activity;.getFragmentManager ()Landroid/app/FragmentManager;
12-01 11:49:10.012: D/dalvikvm(496): VFY: replacing opcode 0x6e at 0x0023
12-01 11:49:10.022: D/dalvikvm(496): VFY: dead code 0x0026-0030 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.showErrorDialogFragment (ILandroid/app/Activity;Landroid/support/v4/app/Fragment;ILandroid/content/DialogInterface$OnCancelListener;)Z
12-01 11:49:10.042: E/dalvikvm(496): Could not find class 'android.app.Notification$Builder', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.showErrorNotification
12-01 11:49:10.042: W/dalvikvm(496): VFY: unable to resolve new-instance 44 (Landroid/app/Notification$Builder;) in Lcom/google/android/gms/common/GooglePlayServicesUtil;
12-01 11:49:10.054: D/dalvikvm(496): VFY: replacing opcode 0x22 at 0x0030
12-01 11:49:10.062: D/dalvikvm(496): VFY: dead code 0x0032-0077 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.showErrorNotification (ILandroid/content/Context;)V
12-01 11:49:10.072: W/GooglePlayServicesUtil(496): Google Play services is missing.
12-01 11:49:10.102: I/dalvikvm(496): Could not find method android.content.Context.registerComponentCallbacks, referenced from method com.google.android.gms.internal.u.Z
12-01 11:49:10.102: W/dalvikvm(496): VFY: unable to resolve virtual method 422: Landroid/content/Context;.registerComponentCallbacks (Landroid/content/ComponentCallbacks;)V
12-01 11:49:10.112: D/dalvikvm(496): VFY: replacing opcode 0x6e at 0x0016
12-01 11:49:10.152: I/dalvikvm(496): Could not find method android.content.Context.unregisterComponentCallbacks, referenced from method com.google.android.gms.internal.u.aa
12-01 11:49:10.152: W/dalvikvm(496): VFY: unable to resolve virtual method 434: Landroid/content/Context;.unregisterComponentCallbacks (Landroid/content/ComponentCallbacks;)V
12-01 11:49:10.152: D/dalvikvm(496): VFY: replacing opcode 0x6e at 0x0016
12-01 11:49:10.292: I/dalvikvm(496): Failed resolving Lcom/google/android/gms/internal/am; interface 29 'Landroid/app/Application$ActivityLifecycleCallbacks;'
12-01 11:49:10.292: W/dalvikvm(496): Link of class 'Lcom/google/android/gms/internal/am;' failed
12-01 11:49:10.312: I/dalvikvm(496): Failed resolving Lcom/google/android/gms/internal/am; interface 29 'Landroid/app/Application$ActivityLifecycleCallbacks;'
12-01 11:49:10.312: W/dalvikvm(496): Link of class 'Lcom/google/android/gms/internal/am;' failed
12-01 11:49:10.322: I/dalvikvm(496): Failed resolving Lcom/google/android/gms/internal/am; interface 29 'Landroid/app/Application$ActivityLifecycleCallbacks;'
12-01 11:49:10.322: W/dalvikvm(496): Link of class 'Lcom/google/android/gms/internal/am;' failed
12-01 11:49:10.333: E/dalvikvm(496): Could not find class 'com.google.android.gms.internal.am', referenced from method com.google.android.gms.internal.gb.l
12-01 11:49:10.333: W/dalvikvm(496): VFY: unable to resolve new-instance 2897 (Lcom/google/android/gms/internal/am;) in Lcom/google/android/gms/internal/gb;
12-01 11:49:10.333: D/dalvikvm(496): VFY: replacing opcode 0x22 at 0x002f
12-01 11:49:10.342: I/dalvikvm(496): Failed resolving Lcom/google/android/gms/internal/am; interface 29 'Landroid/app/Application$ActivityLifecycleCallbacks;'
12-01 11:49:10.354: W/dalvikvm(496): Link of class 'Lcom/google/android/gms/internal/am;' failed
12-01 11:49:10.354: I/dalvikvm(496): Failed resolving Lcom/google/android/gms/internal/am; interface 29 'Landroid/app/Application$ActivityLifecycleCallbacks;'
12-01 11:49:10.362: W/dalvikvm(496): Link of class 'Lcom/google/android/gms/internal/am;' failed
12-01 11:49:10.362: W/dalvikvm(496): VFY: unable to find class referenced in signature (Lcom/google/android/gms/internal/am;)
12-01 11:49:10.362: D/dalvikvm(496): VFY: dead code 0x0031-003d in Lcom/google/android/gms/internal/gb;.l (Landroid/content/Context;)Lcom/google/android/gms/internal/an;
12-01 11:49:10.414: W/GooglePlayServicesUtil(496): Google Play services is missing.
Hey, Logs are not pretty much clear, will you please debug your code to trace where it's going wrong. Hope you have modified AndroidManifest.xml file as mentioned in ReadME file.
Or you can share your sample project to trace it out.

Thanks
Vishnu
ok , got it working .. .the PUSH messages are coming now on my device ...

my next problem is , when i click open the message, the app crashes ...

what do i do if i just want to start the app up when the message is clicked ?
Hey , have you changes the name of Activity in AndroidManifest.xml file.
If you are using App42GCMService.java file of our sample project, you need to make a change here with your own Activity.
 <service android:name="com.example.app42sample.App42GCMService" >
            <meta-data android:name="onMessageOpen" android:value="com.example.app42sample.MessageActivity" />
        </service>
Awesome ! Works fine now !

I just set it to com.example.app42sample.MainActivity and my app starts up :)

Thank ...

btw , whats the sound and badge option for ? can i send any sound and badge on Android ?
Hey, In Android you can customize your Notification in the same way you want, and also set the custom sound , badges count.
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
...