Hi,
Our app main activity already extends an activity. But in your example you've showcased in MainActivity.java which is extending App42Activity and then instantiating the service in onCreate method. But we want to implement it with out extending your App42Activity. I've tried instantiating but it fails to register. It throws an error at Utils.registerWithApp42(). Please provide a solution on how to instantiate your service with out extending App42Activity.
My code details below.
<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.VIBRATE" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.papp.HomePage.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
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="com.papp.HomePage" />
</intent-filter>
</receiver>
<service android:name="com.papp.HomePage.GCMIntentService">
<meta-data android:name="onMessageOpen"
android:value="com.papp.HomePage" />
</service>
GCMIntentService.java is largely based on the example you've provided.
we've added this additionally.
public App42CallBack app42CallBack = new App42CallBack() {
@Override
public void onSuccess(Object arg0) {
App42Log.debug(" ..... Registration Success ....");
GCMRegistrar.setRegisteredOnServer(App42API.appContext, true);
}
@Override
public void onException(Exception paramException) {
App42Log.debug(" ..... Registration Failed ....");
App42Log.debug("storeDeviceToken : Exception : on startup " +paramException);
}
};
//Method to get registered with App42 Platform
public void registerWithApp42(String regId) {
App42Log.debug(" Registering on App42 Server ....");
App42API.buildPushNotificationService().storeDeviceToken(App42API.getLoggedInUser(), regId, app42CallBack);
}
And in MainPage.java onCreate function we're instantiating your service like below.
/* Setting up for push notifications. */
App42API.initialize(this,"5762e5d4ad459e4b4c869f18c7e8a96cbf16c226762ca68864361782a4c2d065",
"922c7bd0f375772782d22683fb3edcea21fa79528cdb79aa8aefa7d127bea668");
GCMIntentService gcm = new GCMIntentService();
gcm.registerWithApp42("230348217944");