update:2019.03.27

fix:更新极光推送框架到最新版本
add:
This commit is contained in:
2020-03-27 18:46:43 +08:00
parent eda0eff802
commit a22583da81
22 changed files with 2261 additions and 301 deletions

View File

@@ -56,6 +56,7 @@ import com.mjsheng.myappstore.bean.NetAndLaunchData;
import com.mjsheng.myappstore.bean.UploadAppInfo;
import com.mjsheng.myappstore.bean.UserInfo;
import com.mjsheng.myappstore.comm.CommonDatas;
import com.mjsheng.myappstore.jpush.TagAliasOperatorHelper;
import com.mjsheng.myappstore.network.HTTPInterface;
import com.mjsheng.myappstore.network.Network;
import com.mjsheng.myappstore.network.api.AppLimitApi;
@@ -90,11 +91,15 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import cn.jpush.android.api.CustomMessage;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.JPushMessage;
import cn.jpush.android.api.TagAliasCallback;
import cn.jpush.android.service.JPushMessageReceiver;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
@@ -105,6 +110,14 @@ import okhttp3.ResponseBody;
import rx.Observable;
import rx.functions.Action1;
import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.ACTION_ADD;
import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.ACTION_CHECK;
import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.ACTION_CLEAN;
import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.ACTION_DELETE;
import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.ACTION_GET;
import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.ACTION_SET;
import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.TagAliasBean;
import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.sequence;
public class MainActivity extends AppCompatActivity implements NetStateChangeObserver {
@@ -114,11 +127,132 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
private final String ACTION_HrReceiver_JGY_DIS = "qch_jgy_network_disallow";
private final String ACTION_HrReceiver_JGY = "qch_jgy_network_allow";
private DownloadManager downloadManager;
public static boolean isForeground = false;
private ImageView imageView;
private TextView tv_devsn, tv_devmac, tv_version;
private int DeviceInfo;
//jiguang
public static boolean isForeground = false;
//for receive customer msg from jpush server
private MessageReceiver mMessageReceiver;
public static final String MESSAGE_RECEIVED_ACTION = "com.jiaoguanyi.appstore.MESSAGE_RECEIVED_ACTION";
public static final String KEY_TITLE = "title";
public static final String KEY_MESSAGE = "message";
public static final String KEY_EXTRAS = "extras";
public void registerMessageReceiver() {
mMessageReceiver = new MessageReceiver();
IntentFilter filter = new IntentFilter();
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
filter.addAction(MESSAGE_RECEIVED_ACTION);
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, filter);
}
public class MessageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
try {
if (MESSAGE_RECEIVED_ACTION.equals(intent.getAction())) {
String messge = intent.getStringExtra(KEY_MESSAGE);
String extras = intent.getStringExtra(KEY_EXTRAS);
StringBuilder showMsg = new StringBuilder();
showMsg.append(KEY_MESSAGE + " : " + messge + "\n");
if (!ExampleUtil.isEmpty(extras)) {
showMsg.append(KEY_EXTRAS + " : " + extras + "\n");
}
// setCostomMsg(showMsg.toString());
}
} catch (Exception e) {
}
}
}
public void onTagAliasAction(int i) {
Set<String> tags = null;
String alias = null;
int action = -1;
boolean isAliasAction = false;
switch (i) {
//设置手机号码:
case 0:
// handleSetMobileNumber();
return;
//增加tag
case 1:
// tags = getInPutTags();
if (tags == null) {
return;
}
action = ACTION_ADD;
break;
//设置tag
case 2:
// tags = getInPutTags();
if (tags == null) {
return;
}
action = ACTION_SET;
break;
//删除tag
case 3:
// tags = getInPutTags();
if (tags == null) {
return;
}
action = ACTION_DELETE;
break;
//获取所有tag
case 4:
action = ACTION_GET;
break;
//清除所有tag
case 5:
action = ACTION_CLEAN;
break;
case 6:
// tags = getInPutTags();
if (tags == null) {
return;
}
action = ACTION_CHECK;
break;
//设置alias
case 7:
// alias = getInPutAlias();
alias = Utils.getSerial();
if (TextUtils.isEmpty(alias)) {
return;
}
isAliasAction = true;
action = ACTION_SET;
break;
//获取alias
case 8:
isAliasAction = true;
action = ACTION_GET;
break;
//删除alias
case 9:
isAliasAction = true;
action = ACTION_DELETE;
break;
default:
return;
}
TagAliasBean tagAliasBean = new TagAliasBean();
tagAliasBean.action = action;
sequence++;
if (isAliasAction) {
tagAliasBean.alias = alias;
} else {
tagAliasBean.tags = tags;
}
tagAliasBean.isAliasAction = isAliasAction;
TagAliasOperatorHelper.getInstance().handleAction(getApplicationContext(), sequence, tagAliasBean);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
@@ -131,9 +265,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
// super.onSaveInstanceState(outState, outPersistentState);
}
private class LocationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// ToastTool.show("广播:::"+intent.getAction() + "--------" + intent.getStringExtra("package_name"));
@@ -164,6 +296,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
callback = new ToastCallback(this);
initView();
timerImitate();
initData();
downloadManager = DownloadService.getDownloadManager();
@@ -173,6 +306,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
sendBroadcast(allIntent);
}
//获取教管易版本号
synchronized private String getAPPVersionName() {
PackageManager pm = getPackageManager();
@@ -229,9 +363,10 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
Log.e("mjhsneg", "gagagag--------------------------" + Utils.getSerial());
getLockedState();
initJpush();//初始化极光推送
setJpushTags();
HTTPInterface.setJpushTags(this);
// update();//接口更新app
sendMACaddress();
checkUpdate();//更新app
Log.e("mac", com.blankj.utilcode.util.DeviceUtils.getMacAddress());
DeviceInfo = (int) SPUtils.get(this, "isLogined", 2);
@@ -326,42 +461,6 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
}
//for receive customer msg from jpush server
private MessageReceiver mMessageReceiver;
public static final String MESSAGE_RECEIVED_ACTION = "com.example.jpushdemo.MESSAGE_RECEIVED_ACTION";
public static final String KEY_TITLE = "title";
public static final String KEY_MESSAGE = "message";
public static final String KEY_EXTRAS = "extras";
public void registerMessageReceiver() {
mMessageReceiver = new MessageReceiver();
IntentFilter filter = new IntentFilter();
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
filter.addAction(MESSAGE_RECEIVED_ACTION);
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, filter);
}
public class MessageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
try {
if (MESSAGE_RECEIVED_ACTION.equals(intent.getAction())) {
String messge = intent.getStringExtra(KEY_MESSAGE);
String extras = intent.getStringExtra(KEY_EXTRAS);
StringBuilder showMsg = new StringBuilder();
showMsg.append(KEY_MESSAGE + " : " + messge + "\n");
if (!ExampleUtil.isEmpty(extras)) {
showMsg.append(KEY_EXTRAS + " : " + extras + "\n");
}
// setCostomMsg(showMsg.toString());
}
} catch (Exception e) {
}
}
}
private boolean locked = false;
public void getLockedState() {
@@ -419,7 +518,6 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
Aria.download(this).resumeAllTask();
// getForceDownload();//强制下载apk
resetDevice();//恢复出厂设置
checkUpdate();//更新app
// fromNetToUpdate();
String registrationID = JPushInterface.getRegistrationID(MainActivity.this);
Log.e("mjsheng", registrationID + "------------------------");
@@ -499,20 +597,23 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
@Override
protected void onStop() {
super.onStop();
}
@Override
protected void onPause() {
isForeground = false;
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
isForeground = true;
Intent allIntent = new Intent();
allIntent.setAction(Utils.DOWNLOAD_ALLTASK_ACTION);
sendBroadcast(allIntent);
loadHeadImg(Configure.HTTP_TAG_HOME_PAGE_URL);
lazyLoading();
}
@@ -670,82 +771,41 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
});
}
private void setJpushTags() {
OkGo.get(Configure.GET_DEVICES_TAGS)
.params("sn", Utils.getSerial())
.execute(new StringCallback() {
@Override
public void onSuccess(String s, Call call, Response response) {
Log.e("fht", s);
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(s);
int code = jsonObject.getInteger("code");
com.alibaba.fastjson.JSONObject data = jsonObject.getJSONObject("data");
if (code == 200) {
String batch = data.getString("batch");
if (batch != null && !batch.equals("")) {
Set set = new HashSet();
set.add(batch);
JPushInterface.setTags(MainActivity.this, set, new TagAliasCallback() {
@Override
public void gotResult(int i, String s, Set<String> set) {
if (set == null) {
Log.e("initmjsheng", "set is null");
} else {
Log.e("initmjsheng", "set ---" + set.toString());
}
Log.e("JPushInterface", s + "---" + i + "---");
if (i == 0) {
Log.e("JPushInterface", "Tag绑定成功");
} else if (i == 6001) {
Log.e("JPushInterface", "无效的设置,用户名为空");
} else if (i == 6002) {
Log.e("JPushInterface", "设置超时,请重试");
timerImitate();
} else if (i == 6011) {
Log.e("JPushInterface", "短时间内操作过于频繁");
} else if (i == 996) {
Log.e("JPushInterface", "网络连接断开");
timerImitate();
}
}
});
}
}
}
@Override
public void onError(Call call, Response response, Exception e) {
super.onError(call, response, e);
Log.e("fht", e.getMessage());
}
});
}
private void initJpush() {
JPushInterface.setAlias(this, Utils.getSerial(), new TagAliasCallback() {
@Override
public void gotResult(int i, String s, Set<String> set) {
if (set == null) {
Log.e("mjhseng", "set is null");
} else {
Log.e("mjhseng", "set ---" + set.toString());
}
Log.e("JPushInterface", s + "---" + i + "---");
if (i == 0) {
Log.e("JPushInterface", "JPush绑定成功");
} else if (i == 6001) {
Log.e("JPushInterface", "无效的设置,用户名为空");
} else if (i == 6002) {
Log.e("JPushInterface", "设置超时,请重试");
timerImitate();
} else if (i == 6011) {
Log.e("JPushInterface", "短时间内操作过于频繁");
} else if (i == 996) {
Log.e("JPushInterface", "网络连接断开");
}
}
});
onTagAliasAction(7);
String rid = JPushInterface.getRegistrationID(getApplicationContext());
if (!rid.isEmpty()) {
// ToastUtil.debugShow("RegId:" + rid);
Log.e("jiguang", "RegId:" + rid);
} else {
// ToastUtil.show("Get registration fail, JPush init failed!");
// Toast.makeText(this, "Get registration fail, JPush init failed!", Toast.LENGTH_SHORT).show();
}
JPushInterface.getAlias(this, new Random().nextInt(100));
// JPushInterface.setAlias(this, Utils.getSerial(), new TagAliasCallback() {
// @Override
// public void gotResult(int i, String s, Set<String> set) {
// if (set == null) {
// Log.e("mjhseng", "set is null");
// } else {
// Log.e("mjhseng", "set ---" + set.toString());
// }
// Log.e("JPushInterface", s + "---" + i + "---");
// if (i == 0) {
// Log.e("JPushInterface", "JPush绑定成功");
// } else if (i == 6001) {
// Log.e("JPushInterface", "无效的设置,用户名为空");
// } else if (i == 6002) {
// Log.e("JPushInterface", "设置超时,请重试");
// timerImitate();
// } else if (i == 6011) {
// Log.e("JPushInterface", "短时间内操作过于频繁");
// } else if (i == 996) {
// Log.e("JPushInterface", "网络连接断开");
// }
// }
// });
}
@@ -758,8 +818,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
public void call(Long aLong) {
Log.e("JPushInterface", "JPushInterface重新加载");
initJpush();
setJpushTags();
HTTPInterface.setJpushTags(MainActivity.this);
}
});
}
@@ -1104,7 +1163,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
if ("com.jiaoguanyi.appstore".equals(forceDownloadData.getApp_package())) {
Aria.download(this)
.load(forceDownloadData.getApp_url()) //读取下载地址
.setDownloadPath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString("com.mjsheng.myappstore") + ".apk")
.setDownloadPath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString("com.jiaoguanyi.appstore") + ".apk")
.setExtendField("com.mjsheng.myappstore")
.start(); //启动下载}