完善推送逻辑,增加推送渠道组
This commit is contained in:
parent
1b1ee0a3ec
commit
1ceb45d401
|
|
@ -8,6 +8,11 @@
|
|||
package com.ifish.baseclass;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
|
|
@ -15,6 +20,7 @@ import androidx.multidex.MultiDexApplication;
|
|||
|
||||
import com.alibaba.sdk.android.push.CloudPushService;
|
||||
import com.alibaba.sdk.android.push.CommonCallback;
|
||||
import com.alibaba.sdk.android.push.PushControlService;
|
||||
import com.alibaba.sdk.android.push.huawei.HuaWeiRegister;
|
||||
import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory;
|
||||
import com.alibaba.sdk.android.push.register.MiPushRegister;
|
||||
|
|
@ -47,7 +53,7 @@ public class BaseApplication extends MultiDexApplication {
|
|||
* 正式环境
|
||||
*/
|
||||
public static String BASE = "https://app.ifish7.cn/";//正式环境 接口访问地址
|
||||
// public static String BASE = "http://139.196.24.156:7080/";//测试环境 接口访问地址
|
||||
// public static String BASE = "http://139.196.24.156:7080/";//测试环境 接口访问地址
|
||||
public static String BASE_URL = BASE + "api/";// 接口URL
|
||||
|
||||
@Override
|
||||
|
|
@ -107,7 +113,47 @@ public class BaseApplication extends MultiDexApplication {
|
|||
private void initalipushSDK() {
|
||||
PushServiceFactory.init(this);
|
||||
|
||||
//创建渠道
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
// 通知渠道的id。
|
||||
String id = "1";
|
||||
// 用户可以看到的通知渠道的名字。
|
||||
CharSequence name = "爱鱼奇";
|
||||
// 用户可以看到的通知渠道的描述。
|
||||
// String description = "通知";
|
||||
int importance = NotificationManager.IMPORTANCE_HIGH;
|
||||
NotificationChannel mChannel = new NotificationChannel(id, name, importance);
|
||||
// 配置通知渠道的属性。
|
||||
// mChannel.setDescription(description);
|
||||
// 设置通知出现时的闪灯(如果Android设备支持的话)。
|
||||
mChannel.enableLights(true);
|
||||
mChannel.setLightColor(Color.RED);
|
||||
// 设置通知出现时的震动(如果Android设备支持的话)。
|
||||
mChannel.enableVibration(true);
|
||||
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
|
||||
// 最后在notificationmanager中创建该通知渠道。
|
||||
mNotificationManager.createNotificationChannel(mChannel);
|
||||
}
|
||||
|
||||
PushServiceFactory.getPushControlService().setConnectionChangeListener(new PushControlService.ConnectionChangeListener() {
|
||||
@Override
|
||||
public void onConnect() {
|
||||
Log.d("AliyunPush", "Aliyun Push connected");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnect(String s, String s1) {
|
||||
Log.d("AliyunPush", "Aliyun Push disconnect, errorCode:" + s + " msg = " + s1);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
final CloudPushService pushService = PushServiceFactory.getCloudPushService();
|
||||
|
||||
//仅适用于Debug包,正式包不需要此行
|
||||
pushService.setLogLevel(CloudPushService.LOG_DEBUG);
|
||||
|
||||
pushService.register(this, new CommonCallback() {
|
||||
@Override
|
||||
public void onSuccess(String response) {
|
||||
|
|
@ -144,7 +190,7 @@ public class BaseApplication extends MultiDexApplication {
|
|||
private void initShareSDK() {
|
||||
// 友盟社会化分享SDK预初始化函数
|
||||
// preInit预初始化函数耗时极少,不会影响App首次冷启动用户体验
|
||||
UMConfigure.preInit(this,"55f7d5bfe0f55a14770001da","ifish");
|
||||
UMConfigure.preInit(this, "55f7d5bfe0f55a14770001da", "ifish");
|
||||
/**
|
||||
* 在微博开放平台设置的授权回调REDIRECT_URL必须与代码中设置一致 http://open.weibo.com/apps/1240247140/info/advanced
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ import androidx.core.app.ActivityCompat;
|
|||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.lidroid.xutils.util.LogUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -64,7 +66,7 @@ public class PermissionHelper {
|
|||
//=========Constructors- END=========
|
||||
public void request(PermissionCallback permissionCallback) {
|
||||
this.mPermissionCallback = permissionCallback;
|
||||
if (checkSelfPermission(permissions) == false) {
|
||||
if (!checkSelfPermission(permissions)) {
|
||||
showRational = shouldShowRational(permissions);
|
||||
if (activity != null)
|
||||
ActivityCompat.requestPermissions(activity, filterNotGrantedPermission(permissions), REQUEST_CODE);
|
||||
|
|
@ -93,7 +95,7 @@ public class PermissionHelper {
|
|||
|
||||
if (denied) {
|
||||
boolean currentShowRational = shouldShowRational(permissions);
|
||||
if (currentShowRational == false) {
|
||||
if (!currentShowRational) {
|
||||
if (mPermissionCallback != null)
|
||||
mPermissionCallback.onPermissionDeniedBySystem();
|
||||
} else {
|
||||
|
|
@ -176,14 +178,14 @@ public class PermissionHelper {
|
|||
private boolean shouldShowRational(String[] permissions) {
|
||||
boolean currentShowRational = false;
|
||||
for (String permission : permissions) {
|
||||
|
||||
LogUtils.d("ifish LHD 遍历权限 = "+permission);
|
||||
if (activity != null) {
|
||||
if (shouldShowRequestPermissionRationale(activity, permission) == true) {
|
||||
if (shouldShowRequestPermissionRationale(activity, permission)) {
|
||||
currentShowRational = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (fragment.shouldShowRequestPermissionRationale(permission) == true) {
|
||||
if (fragment.shouldShowRequestPermissionRationale(permission)) {
|
||||
currentShowRational = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue