我尝试使用Mobile First Server为本机Android应用程序设置推送通知。我相信我已根据文档正确配置了所有内容,但我收到以下错误...
我使用的是AVD仿真器(API 21)的Google API版本。 我还更新了服务器上的application-descriptor.xml文件,以包含我的发件人ID以及wlclient.properties文件。
WLPush.isAbleToSubscribe in WLPush.java:424 :: Can't subscribe, notification token is not updated on the server
这是我的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();
}
}
}
我的PushListener实现
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());
}
}
清单
<?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>
完整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
答案 0 :(得分:1)
看起来我所要做的就是从MobileFirst Server重新部署我的原生app API。