提交 782081b4 authored 作者: lgd's avatar lgd

1.推送

上级 e7017a05
package com.wd.workoffice.service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wd.workoffice.bean.event.NotifyEvent;
import com.wd.workoffice.ui.activity.MainActivity;
import com.wd.workoffice.util.DataKeeper;
import com.wd.workoffice.util.UserKeeper;
import org.greenrobot.eventbus.EventBus;
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;
/**
* 自定义接收器
* author : flexible
* email : lgd19940421@163.com
* github: https://github.com/FlexibleXd
* <p>
* 如果不定义这个 Receiver,则:
* * 1) 默认用户会打开主界面
* * 2) 接收不到自定义消息
**/
public class JPushReceive extends BroadcastReceiver {
private static final String TAG = "JIGUANG-Example";
public class JPushReceive extends JPushMessageReceiver{
private static final String TAG = "PushMessageReceiver";
@Override
public void onReceive(Context context, Intent intent) {
try {
Bundle bundle = intent.getExtras();
// Logger.d(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));
if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
Log.d(TAG, "[MyReceiver] 接收Registration Id : " + regId);
//send the Registration Id to your server...
} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
Log.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
// processCustomMessage(context, bundle);
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
Log.d(TAG, "[MyReceiver] 接收到推送下来的通知");
int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
Log.d(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);
//TODO 判断消息.审核无动作,消息维系按钮
DataKeeper.getInstance().keepMsgStatus(true);
EventBus.getDefault().post(new NotifyEvent(0,"notice"));
public void onMessage(Context context, CustomMessage customMessage) {
Log.e(TAG,"[onMessage] "+customMessage);
// processCustomMessage(context,customMessage);
}
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
Log.d(TAG, "[MyReceiver] 用户点击打开了通知");
//TODO 判断消息,审核跳转,消息无动作
@Override
public void onNotifyMessageOpened(Context context, NotificationMessage message) {
Log.e(TAG,"[onNotifyMessageOpened] "+message);
try{
JSONObject msgData = JSON.parseObject(message.notificationExtras);
String msgType = msgData.getString("msgType");
if (TextUtils.equals(msgType,"approval")){
//打开自定义的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 );
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP );
context.startActivity(i);
EventBus.getDefault().post(new NotifyEvent(1,"approval"));
} else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
Log.d(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA));
//在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码,比如打开新的Activity, 打开一个网页等..
}
}catch (Throwable throwable){
Log.e(TAG,"[onMessage] throwable "+throwable.toString());
}
}
} else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
Log.d(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected);
@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.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());
Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮未定义");
}
}
} catch (Exception e) {
@Override
public void onNotifyMessageArrived(Context context, NotificationMessage message) {
Log.e(TAG,"[onNotifyMessageArrived] "+message);
JSONObject msgData = JSON.parseObject(message.notificationExtras);
String msgType = msgData.getString("msgType");
if (!TextUtils.equals(msgType,"approval")){
DataKeeper.getInstance().keepMsgStatus(true);
EventBus.getDefault().post(new NotifyEvent(0,"notice"));
}
}
@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) {
// Log.e(TAG,"[onNotificationSettingsCheck] isOn:"+isOn+",source:"+source);
// }
}
......@@ -6,6 +6,7 @@ import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
......@@ -43,6 +44,7 @@ import androidx.fragment.app.FragmentManager;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import butterknife.ButterKnife;
import cn.jpush.android.api.JPushInterface;
import flexible.xd.android_base.base.AppManager;
import flexible.xd.android_base.model.event.LoginEvent;
import me.jessyan.autosize.internal.CancelAdapt;
......@@ -69,6 +71,7 @@ public class MainActivity extends WorkBaseActivity implements BottomNavigationBa
startActivity(MainLoginActivity.class);
return;
}
WorkUtils.handleAlias(Integer.valueOf(UserKeeper.getInstance().getUserId()), 2);
ButterKnife.bind(this);
QMUIStatusBarHelper.translucent(this);
QMUIStatusBarHelper.setStatusBarLightMode(this);
......@@ -206,6 +209,7 @@ public class MainActivity extends WorkBaseActivity implements BottomNavigationBa
super.onBackPressed();
}
}
/**
* 消息红点是否显示
*/
......@@ -217,6 +221,7 @@ public class MainActivity extends WorkBaseActivity implements BottomNavigationBa
shapeBadgeItem.hide();
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void login(LoginEvent lg) {
if (!UserKeeper.getInstance().getMesLogin()) {
......@@ -243,7 +248,7 @@ public class MainActivity extends WorkBaseActivity implements BottomNavigationBa
public void notify(NotifyEvent event) {
if (event.getType() == 0) {
shapeIsShow();
}else {
} else {
startActivity(WorkApprovalActivity.class, "type", "2", "status", "0", "title", "待我审批");
}
}
......
......@@ -21,6 +21,7 @@ import com.wd.workoffice.ui.activity.MainLoginActivity;
import com.wd.workoffice.ui.activity.login.LoginActivity;
import com.wd.workoffice.util.DataKeeper;
import com.wd.workoffice.util.UserKeeper;
import com.wd.workoffice.util.WorkUtils;
import org.greenrobot.eventbus.EventBus;
......@@ -103,6 +104,7 @@ public class UserSettingActivity extends WorkToolBarActivity {
private void logout() {
toast("退出成功");
WorkUtils.handleAlias(Integer.valueOf(UserKeeper.getInstance().getUserId()),1);
Intent intent = new Intent(UserSettingActivity.this, MainLoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
UserKeeper.getInstance().clearAll();
......
......@@ -10,6 +10,7 @@ import android.provider.MediaStore;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
......@@ -47,6 +48,7 @@ import java.util.Map;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import cn.jpush.android.api.JPushInterface;
import flexible.xd.android_base.network.rtfhttp.RtfHelper;
import flexible.xd.android_base.network.rtfhttp.Transformer;
import io.reactivex.disposables.Disposable;
......@@ -341,7 +343,7 @@ public class WorkUtils {
return name;
}
// case 0:
// case 0:
// return @"正常";
// break;
// case 1:
......@@ -383,7 +385,7 @@ public class WorkUtils {
case "2":
name = "长水口";
break;
case"3":
case "3":
name = "其他";
break;
}
......@@ -643,7 +645,7 @@ public class WorkUtils {
* @return
*/
public static boolean isImg(String type) {
return TextUtils.equals("jpg", type) ||TextUtils.equals("jpeg", type) || TextUtils.equals("gif", type) || TextUtils.equals("webp", type) ||
return TextUtils.equals("jpg", type) || TextUtils.equals("jpeg", type) || TextUtils.equals("gif", type) || TextUtils.equals("webp", type) ||
TextUtils.equals("png", type) || TextUtils.equals("bmp", type) || TextUtils.equals("JPEG", type) || TextUtils.equals("GIF", type) || TextUtils.equals("WEBP", type) ||
TextUtils.equals("PNG", type) || TextUtils.equals("BMP", type);
}
......@@ -845,4 +847,26 @@ public class WorkUtils {
}
});
}
/**
* 监听
*
* @param sequence
* @param type 0 ,get 1,delete 2,set
*/
public static void handleAlias(int sequence, int type) {
switch (type) {
case 0:
JPushInterface.getAlias(WorkApp.getAppContext(), sequence);
break;
case 1:
JPushInterface.deleteAlias(WorkApp.getAppContext(), sequence);
break;
case 2:
JPushInterface.setAlias(WorkApp.getAppContext(), sequence, sequence + "");
break;
default:
return;
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论