android push notification

0 votes

hi, i tried to setup push notifications in my android app. i follwed the tutorial and set it up. i dont know how much ive done right. ill be adding snippets of by code below. the ussr gets added to the push notification users in the app42 hq push options but when i click on send push from the hq the device doesnt recieve the notifications.

 

im explaining in short what i have done, i downloaded the push notification example available on github. made the package com.shephertz.app42.push.plugin in my app. copy pasted all the classes from the sample app to mine.

 

the following code is a part of my homeactivity which is launched after the user loggs in

import com.shephertz.app42.paas.sdk.android.App42API;
import com.shephertz.app42.paas.sdk.android.App42Log;
import com.shephertz.app42.push.plugin.App42GCMController;
import com.shephertz.app42.push.plugin.App42GCMController.App42GCMListener;
import com.shephertz.app42.push.plugin.App42GCMService;

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

public class HomeActivity extends AppCompatActivity implements App42GCMListener{

    private static final String GoogleProjectNo = "my projct no<editied for privacy>";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        App42API.setLoggedInUser(App42API.getLoggedInUser());
        App42Log.setDebug(true);
    }

    public void onStart() {
        super.onStart();
        if (App42GCMController.isPlayServiceAvailable(this)) {
            App42GCMController.getRegistrationId(HomeActivity.this,
                    GoogleProjectNo, this);
        } else {
            Log.i("App42PushNotification",
                    "No valid Google Play Services APK found.");
        }
    }


    @Override
    public void onError(String errorMsg) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onGCMRegistrationId(String gcmRegId) {
        // TODO Auto-generated method stub
        App42GCMController.storeRegistrationId(this, gcmRegId);
        if(!App42GCMController.isApp42Registerd(HomeActivity.this))
            App42GCMController.registerOnApp42(App42API.getLoggedInUser(), gcmRegId, this);
    }

    @Override
    public void onApp42Response(final String responseMessage) {
        // TODO Auto-generated method stub
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
            }
        });
    }

    @Override
    public void onRegisterApp42(final String responseMessage) {
        // TODO Auto-generated method stub
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                App42GCMController.storeApp42Success(HomeActivity.this);
            }
        });
    }

    final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String message = intent
                    .getStringExtra(App42GCMService.ExtraMessage);
        }
    };


}

 

please solve this for me asap. 

thanks

asked Apr 29, 2016 in Android by checker.kshitij (10 points)

1 Answer

0 votes

HI Checker,

Greetings!!!

As User is successfully registered on AppHQ, everything that you have done is fine. But there may be a case some configuration missing in AndroidManifest.xml file.

You need to mdifify the same as per steps mentioned in ReadME file.

  1. Need to add App42GCMService.java in service section.
  2. Need to add App42GCMReceiver in in receiver section that receives the push messages.

Will you please share the AndroidManifest.xml file, that will help us to trace the exact problem.

Thanks

Vishnu Garg

answered Apr 29, 2016 by Vishnu Garg (674 points)
here is the manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="urbandonate.com.urbandonateuser">

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="urbandonate.com.urbandonateuser.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <permission
        android:name="urbandonate.com.urbandonateuser.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <receiver
        android:name="com.shephertz.app42.push.plugin.App42GCMReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="urbandonate.com.urbandonateuser" />
        </intent-filter>
    </receiver>
    <service android:name="com.shephertz.app42.push.plugin.App42GCMService" >
    </service>
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="onMessageOpen"
        android:value="com.example.app42Sample.SplashActivty" />
Have you added the receiver and service in application Tag. All the data should be in application tag except the permissions.
made the following changes::


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="urbandonate.com.urbandonateuser">

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="urbandonate.com.urbandonateuser.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <permission
        android:name="urbandonate.com.urbandonateuser.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />


    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".SplashActivity"
            android:label="@string/app_name"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".NoLoginActivity"
            android:label="@string/title_activity_no_login"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".LoginActivity"
            android:label="@string/title_activity_login"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".RegisterActivity"
            android:label="@string/title_activity_register"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".HomeActivity"
            android:label="@string/title_activity_home"
            android:theme="@style/AppTheme.NoActionBar"></activity>

        <receiver
            android:name="com.shephertz.app42.push.plugin.App42GCMReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="urbandonate.com.urbandonateuser" />
            </intent-filter>
        </receiver>
        <service android:name="com.shephertz.app42.push.plugin.App42GCMService" >
        </service>
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="onMessageOpen"
            android:value="com.example.app42Sample.SplashActivty" />
    </application>

</manifest>

still cant recieve push notifications
hi, do let me know if you get a solution to my issue
Please enable Push Logs on AppHQ in Setting/AppManager option. So when you are sending message from AppHQ you can see logs in Notification section.
Please share that log as well. You have done the right configurations.
Have you submitted the server Key in Push Setting option of Android.
yes i have submitted the server key.
i have enabled logging in the apphq and tried to push several pushes, but the log still says no logs to show
Hi Checker,

Is it possible that you can share your app name with us. It will help us to provide better support to you.

P.S It would be great if you can add us as a collaborator on your app. Once we have done the debugging, you can remove it from your side.

Please follow the below steps to add us as a collaborator on your app:

Login to AppHQ Management Console
Click collaborator -> Click Add Email
Enter demo@shephertz.com and submit

It will help us to provide better support to you.

Regards,
Himanshu Sharma
the name of the app is UrbanDonate
i have added demo@shephertz.com as a collaborator
EDIT:
the push service is not working only on android 6.0
okay. i dont know what the issue was. but its got resolved now.

thanks a lot for your continuous support. much appreciated.
Hi Checker,

Thanks for adding us as a collaborator on your app. Could you please check the push message on device because i am able to see the success logs inside Push logs.

Regards,
Himanshu sharma
Great to know that the issue has been resolved for you. Please feel free to write us in case you need further help.

Regards,
Himanshu Sharma
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
...