MobileFirst - Android 推送 - 无法订阅,通知令牌未在服务器上更新

Posted

技术标签:

【中文标题】MobileFirst - Android 推送 - 无法订阅,通知令牌未在服务器上更新【英文标题】:MobileFirst - Android push - Can't subscribe, notification token is not updated on the server 【发布时间】:2015-07-28 01:43:54 【问题描述】:

我正在尝试使用 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

【问题讨论】:

【参考方案1】:

看起来我所要做的就是从 MobileFirst Server 重新部署我的本机应用程序 API。

【讨论】:

我有同样的问题,但我无法解决它...请您提供更多信息。 ?谢谢 @Stefano Bertini 我所做的只是删除我的 Eclipse 工作区并重新安装所有内容,然后重新部署。 (我仍然每天至少这样做 4 到 5 次)如果可以,请避免使用 MFP。或者至少去买一瓶泰诺,哈哈

以上是关于MobileFirst - Android 推送 - 无法订阅,通知令牌未在服务器上更新的主要内容,如果未能解决你的问题,请参考以下文章

IBM MobileFirst - 添加推送清单权限的原生 Android 应用程序

IBM MobileFirst 8 - 推送通知错误代码:invalid_client

MobileFirst Platform v7.1 - 管理多个推送通知

IBM MobileFirst:如何让应用程序接收任何活动的推送通知

如何在 IBM MobileFirst 的顶部(状态栏)中获取推送通知

Mobilefirst 8.0 推送通知