Commit c27e1ebd authored by mengcuiguang's avatar mengcuiguang

优化极光推送问题

parent 2c833e5a
...@@ -166,6 +166,13 @@ ...@@ -166,6 +166,13 @@
<category android:name="com.mints.xunmi" /> <category android:name="com.mints.xunmi" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<!--since 3.3.0 接收JPush相关事件-->
<receiver android:name=".service.PushMessageReceiver">
<intent-filter>
<action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
<category android:name="${applicationId}"></category>
</intent-filter>
</receiver>
<service android:name="com.amap.api.location.APSService" /> <service android:name="com.amap.api.location.APSService" />
......
package com.mints.xunmi.service;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import com.mints.xunmi.ui.activitys.MainActivity;
import org.json.JSONException;
import org.json.JSONObject;
import cn.jpush.android.api.CmdMessage;
import cn.jpush.android.api.CustomMessage;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.JPushMessage;
import cn.jpush.android.api.NotificationMessage;
import cn.jpush.android.service.JPushMessageReceiver;
public class PushMessageReceiver extends JPushMessageReceiver {
private static final String TAG = "PushMessageReceiver";
@Override
public void onMessage(Context context, CustomMessage customMessage) {
Log.e(TAG,"[onMessage] "+customMessage);
processCustomMessage(context,customMessage);
}
@Override
public void onNotifyMessageOpened(Context context, NotificationMessage message) {
Log.e(TAG,"[onNotifyMessageOpened] "+message);
try{
//打开自定义的Activity
Intent i = new Intent(context, MainActivity.class);
Bundle bundle = new Bundle();
bundle.putString(JPushInterface.EXTRA_NOTIFICATION_TITLE,message.notificationTitle);
bundle.putString(JPushInterface.EXTRA_ALERT,message.notificationContent);
i.putExtras(bundle);
//i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP );
context.startActivity(i);
}catch (Throwable throwable){
}
}
@Override
public void onMultiActionClicked(Context context, Intent intent) {
Log.e(TAG, "[onMultiActionClicked] 用户点击了通知栏按钮");
String nActionExtra = intent.getExtras().getString(JPushInterface.EXTRA_NOTIFICATION_ACTION_EXTRA);
//开发者根据不同 Action 携带的 extra 字段来分配不同的动作。
if(nActionExtra==null){
Log.d(TAG,"ACTION_NOTIFICATION_CLICK_ACTION nActionExtra is null");
return;
}
if (nActionExtra.equals("my_extra1")) {
Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮一");
} else if (nActionExtra.equals("my_extra2")) {
Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮二");
} else if (nActionExtra.equals("my_extra3")) {
Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮三");
} else {
Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮未定义");
}
}
@Override
public void onNotifyMessageArrived(Context context, NotificationMessage message) {
Log.e(TAG,"[onNotifyMessageArrived] "+message);
}
@Override
public void onNotifyMessageDismiss(Context context, NotificationMessage message) {
Log.e(TAG,"[onNotifyMessageDismiss] "+message);
}
@Override
public void onRegister(Context context, String registrationId) {
Log.e(TAG,"[onRegister] "+registrationId);
}
@Override
public void onConnected(Context context, boolean isConnected) {
Log.e(TAG,"[onConnected] "+isConnected);
}
@Override
public void onCommandResult(Context context, CmdMessage cmdMessage) {
Log.e(TAG,"[onCommandResult] "+cmdMessage);
}
@Override
public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
super.onTagOperatorResult(context, jPushMessage);
}
@Override
public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage){
super.onCheckTagOperatorResult(context, jPushMessage);
}
@Override
public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
super.onAliasOperatorResult(context, jPushMessage);
}
@Override
public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) {
super.onMobileNumberOperatorResult(context, jPushMessage);
}
//send msg to MainActivity
private void processCustomMessage(Context context, CustomMessage customMessage) {
// if (MainActivity.isForeground) {
// String message = customMessage.message;
// String extras = customMessage.extra;
// Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);
// msgIntent.putExtra(MainActivity.KEY_MESSAGE, message);
// if (!ExampleUtil.isEmpty(extras)) {
// try {
// JSONObject extraJson = new JSONObject(extras);
// if (extraJson.length() > 0) {
// msgIntent.putExtra(MainActivity.KEY_EXTRAS, extras);
// }
// } catch (JSONException e) {
//
// }
//
// }
// LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
// }
}
@Override
public void onNotificationSettingsCheck(Context context, boolean isOn, int source) {
super.onNotificationSettingsCheck(context, isOn, source);
Log.e(TAG,"[onNotificationSettingsCheck] isOn:"+isOn+",source:"+source);
}
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states --> <!-- Non focused states -->
<item android:color="@color/main_mints_temp" android:state_selected="true" /> <item android:color="@color/main_mints" android:state_selected="true" />
<item android:color="@color/black_text" android:state_selected="false" /> <item android:color="@color/black_text" android:state_selected="false" />
</selector> </selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="main_mints">#187CFB</color> <color name="main_mints">#187CFB</color>
<color name="main_mints_temp">#2DE8BD</color>
<color name="main_mints_blue">#172b54</color> <color name="main_mints_blue">#172b54</color>
<color name="white">#FFFFFF</color> <color name="white">#FFFFFF</color>
<color name="graygai">#D9D9D9</color> <color name="graygai">#D9D9D9</color>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment