Reputation: 8992
I'm trying to set up push notification for a native android application using the Mobile First Server. I believe i have everything configured properly according to the documentation but I am receiving the following error...
I am using the Google API version of the AVD emulator (API 21). I also updated the application-descriptor.xml file on my server to include my sender ID as well as the wlclient.properties file.
WLPush.isAbleToSubscribe in WLPush.java:424 :: Can't subscribe, notification token is not updated on the server
This is my PushActivity
public class PushActivity extends AppCompatActivity {
private static final String LOG_TAG = PushActivity.class.getSimpleName();
private WLClient mWLClient;
private WLPush mPush;
private Button mSubscribe;
private PushListener mPushListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_push);
mWLClient = WLClient.getInstance();
mPush = mWLClient.getPush();
mPushListener = new PushListener();
mSubscribe = (Button) findViewById(R.id.subscribe);
mSubscribe.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mPush.subscribe("myAndroid", new WLPushOptions(), mPushListener);
}
});
mPush.setOnReadyToSubscribeListener(mPushListener);
}
@Override
protected void onResume() {
super.onResume();
if (mPush != null){
mPush.setForeground(true);
}
}
@Override
protected void onPause() {
super.onPause();
if (mPush != null){
mPush.setForeground(false);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mPush != null){
mPush.unregisterReceivers();
}
}
}
My PushListener implementation
public class PushListener implements WLOnReadyToSubscribeListener, WLResponseListener, WLEventSourceListener {
private static final String LOG_TAG = PushListener.class.getSimpleName();
@Override
public void onReceive(String s, String s1) {
Log.d(LOG_TAG,"Notification Received: " + s + ", " + s1);
}
@Override
public void onReadyToSubscribe() {
WLClient.getInstance().getPush().registerEventSourceCallback("myAndroid","PushAdapter","PushEventSource",this);
}
@Override
public void onSuccess(WLResponse wlResponse) {
Log.d(LOG_TAG,wlResponse.getResponseText());
}
@Override
public void onFailure(WLFailResponse wlFailResponse) {
Log.d(LOG_TAG,wlFailResponse.getResponseText());
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<permission android:name="com.company.hitch.mobilefirsttestapp.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.company.hitch.mobilefirsttestapp.permission.C2D_MESSAGE"/>
<!--<permission android:name="com.google.android.c2dm.permission.RECEIVE"-->
<!--android:protectionLevel="signature"/>-->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name=".AppState"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".authentication.ValidateUserIdActivity"
android:label="@string/title_activity_log_in" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
</activity>
<activity android:name="com.worklight.wlclient.ui.UIActivity" />
<activity
android:name=".authentication.ChallengeActivity"
android:label="@string/title_activity_challenge" >
</activity>
<activity
android:name=".log.LogActivity"
android:label="@string/title_activity_log" >
</activity>
<activity
android:name=".log.LogDetailActivity"
android:label="@string/title_activity_log_detail" >
</activity>
<activity
android:name=".authentication.ValidatePasswordActivity"
android:label="@string/title_activity_password" >
</activity>
<activity
android:name=".authentication.AccountSelectionActivity"
android:label="@string/title_activity_account_selection" >
</activity>
<activity
android:name=".push.PushActivity"
android:label="@string/title_activity_push"
android:theme="@style/AppTheme"
android:launchMode="singleTask">
<intent-filter>
<action android:name="com.company.hitch.mobilefirsttestapp.push.PushActivity.NOTIFICATION"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service android:name="com.worklight.wlclient.push.GCMIntentService"/>
<receiver android:name="com.worklight.wlclient.push.WLBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="com.company.hitch.mobilefirsttestapp"/>
</intent-filter>
<intent-filter>
<action android:name="com.google.comandroid.c2dm.intent.REGISTRATION"/>
<category android:name="com.company.hitch.mobilefirsttestapp"/>
</intent-filter>
</receiver>
</application>
Full Logcat
GCMClientFactory.getInstance in GCMClientFactory.java:25 :: Using GCMAPIClient
GCMAPIClient.unregisterReceivers in GCMAPIClient.java:132 :: unregister:Receiver not registered: null
WLPush.unregisterReceivers in WLPush.java:820 :: unregisterReceivers:Receiver not registered: com.worklight.wlclient.api.WLPush$3@dfee794
WLPush.isAbleToSubscribe in WLPush.java:424 :: Can't subscribe, notification token is not updated on the server
Upvotes: 0
Views: 454
Reputation: 8992
Looks like all I had to do was re-deploy my native app API from the MobileFirst Server.
Upvotes: 1