version:2.4

fix:更换图标,修改桌面隐藏其他应用
add:
This commit is contained in:
2022-02-22 10:10:02 +08:00
parent 6f409d2922
commit c67024dde5
22 changed files with 700 additions and 648 deletions

View File

@@ -214,96 +214,96 @@
<!-- Rich push 核心功能 since 2.0.6-->
<activity
android:name="cn.jpush.android.ui.PopWinActivity"
android:exported="false"
android:theme="@style/MyDialogStyle"
tools:replace="android:exported"></activity>
<!-- <activity-->
<!-- android:name="cn.jpush.android.ui.PopWinActivity"-->
<!-- android:exported="false"-->
<!-- android:theme="@style/MyDialogStyle"-->
<!-- tools:replace="android:exported"></activity>-->
<!-- Required SDK核心功能-->
<activity
android:name="cn.jpush.android.ui.PushActivity"
android:configChanges="orientation|keyboardHidden"
android:exported="false"
android:theme="@android:style/Theme.NoTitleBar"
tools:replace="android:exported">
<intent-filter>
<action android:name="cn.jpush.android.ui.PushActivity" />
<!-- <activity-->
<!-- android:name="cn.jpush.android.ui.PushActivity"-->
<!-- android:configChanges="orientation|keyboardHidden"-->
<!-- android:exported="false"-->
<!-- android:theme="@android:style/Theme.NoTitleBar"-->
<!-- tools:replace="android:exported">-->
<!-- <intent-filter>-->
<!-- <action android:name="cn.jpush.android.ui.PushActivity" />-->
<category android:name="android.intent.category.DEFAULT" />
<category android:name="${applicationId}" />
</intent-filter>
</activity>
<!-- <category android:name="android.intent.category.DEFAULT" />-->
<!-- <category android:name="${applicationId}" />-->
<!-- </intent-filter>-->
<!-- </activity>-->
<!-- Required SDK 核心功能-->
<!-- 可配置android:process参数将PushService放在其他进程中 -->
<service
android:name="cn.jpush.android.service.PushService"
android:exported="false"
android:process=":pushcore">
<intent-filter>
<action android:name="cn.jpush.android.intent.REGISTER" />
<action android:name="cn.jpush.android.intent.REPORT" />
<action android:name="cn.jpush.android.intent.PushService" />
<action android:name="cn.jpush.android.intent.PUSH_TIME" />
</intent-filter>
</service>
<!-- <service-->
<!-- android:name="cn.jpush.android.service.PushService"-->
<!-- android:exported="false"-->
<!-- android:process=":pushcore">-->
<!-- <intent-filter>-->
<!-- <action android:name="cn.jpush.android.intent.REGISTER" />-->
<!-- <action android:name="cn.jpush.android.intent.REPORT" />-->
<!-- <action android:name="cn.jpush.android.intent.PushService" />-->
<!-- <action android:name="cn.jpush.android.intent.PUSH_TIME" />-->
<!-- </intent-filter>-->
<!-- </service>-->
<!-- since 3.0.9 Required SDK 核心功能-->
<provider
android:name="cn.jpush.android.service.DataProvider"
android:authorities="${applicationId}.DataProvider"
android:exported="false"
android:process=":pushcore"
tools:replace="android:authorities" />
<!-- <provider-->
<!-- android:name="cn.jpush.android.service.DataProvider"-->
<!-- android:authorities="${applicationId}.DataProvider"-->
<!-- android:exported="false"-->
<!-- android:process=":pushcore"-->
<!-- tools:replace="android:authorities" />-->
<!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->
<!-- 若不启用该功能可删除该组件,将不拉起其他应用也不能被其他应用拉起 -->
<service
android:name="cn.jpush.android.service.DaemonService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="cn.jpush.android.intent.DaemonService" />
<category android:name="${applicationId}" />
</intent-filter>
<!-- <service-->
<!-- android:name="cn.jpush.android.service.DaemonService"-->
<!-- android:enabled="true"-->
<!-- android:exported="true">-->
<!-- <intent-filter>-->
<!-- <action android:name="cn.jpush.android.intent.DaemonService" />-->
<!-- <category android:name="${applicationId}" />-->
<!-- </intent-filter>-->
</service>
<!-- </service>-->
<!-- since 3.1.0 Required SDK 核心功能-->
<provider
android:name="cn.jpush.android.service.DownloadProvider"
android:authorities="${applicationId}.DownloadProvider"
android:exported="true"
tools:replace="android:authorities" />
<!-- <provider-->
<!-- android:name="cn.jpush.android.service.DownloadProvider"-->
<!-- android:authorities="${applicationId}.DownloadProvider"-->
<!-- android:exported="true"-->
<!-- tools:replace="android:authorities" />-->
<!-- Required SDK核心功能-->
<receiver
android:name="cn.jpush.android.service.PushReceiver"
android:enabled="true"
android:exported="false"
tools:replace="android:exported">
<intent-filter android:priority="1000">
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" /> <!--Required 显示通知栏 -->
<category android:name="${applicationId}" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<!-- Optional -->
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<!-- <receiver-->
<!-- android:name="cn.jpush.android.service.PushReceiver"-->
<!-- android:enabled="true"-->
<!-- android:exported="false"-->
<!-- tools:replace="android:exported">-->
<!-- <intent-filter android:priority="1000">-->
<!-- <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" /> &lt;!&ndash;Required 显示通知栏 &ndash;&gt;-->
<!-- <category android:name="${applicationId}" />-->
<!-- </intent-filter>-->
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.USER_PRESENT" />-->
<!-- <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />-->
<!-- </intent-filter>-->
<!-- &lt;!&ndash; Optional &ndash;&gt;-->
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.PACKAGE_ADDED" />-->
<!-- <action android:name="android.intent.action.PACKAGE_REMOVED" />-->
<data android:scheme="package" />
</intent-filter>
</receiver>
<!-- <data android:scheme="package" />-->
<!-- </intent-filter>-->
<!-- </receiver>-->
<!-- Required SDK核心功能-->
<receiver
android:name="cn.jpush.android.service.AlarmReceiver"
android:exported="false" />
<!-- <receiver-->
<!-- android:name="cn.jpush.android.service.AlarmReceiver"-->
<!-- android:exported="false" />-->
<!-- User defined. For test only 用户自定义的广播接收器-->
@@ -336,16 +336,16 @@
android:exported="true" />
<!--since 3.3.0 Required SDK核心功能-->
<activity
android:name="cn.jpush.android.service.JNotifyActivity"
android:exported="true"
android:taskAffinity="jpush.custom"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
<intent-filter>
<action android:name="cn.jpush.android.intent.JNotifyActivity" />
<category android:name="${applicationId}" />
</intent-filter>
</activity>
<!-- <activity-->
<!-- android:name="cn.jpush.android.service.JNotifyActivity"-->
<!-- android:exported="true"-->
<!-- android:taskAffinity="jpush.custom"-->
<!-- android:theme="@android:style/Theme.Translucent.NoTitleBar">-->
<!-- <intent-filter>-->
<!-- <action android:name="cn.jpush.android.intent.JNotifyActivity" />-->
<!-- <category android:name="${applicationId}" />-->
<!-- </intent-filter>-->
<!-- </activity>-->
<!-- since 3.3.0 Required SDK 核心功能-->
<!-- 可配置android:process参数将PushService放在其他进程中 -->
@@ -359,11 +359,12 @@
</service>
<!-- Required . Enable it you can get statistics data with channel -->
<meta-data
android:name="JPUSH_CHANNEL"
android:value="${JPUSH_CHANNEL}" />
<meta-data
android:name="JPUSH_APPKEY"
android:value="${JPUSH_APPKEY}" /> <!-- </>值来自开发者平台取得的AppKey-->
<!-- <meta-data-->
<!-- android:name="JPUSH_CHANNEL"-->
<!-- android:value="${JPUSH_CHANNEL}" />-->
<!-- <meta-data-->
<!-- android:name="JPUSH_APPKEY"-->
<!-- android:value="${JPUSH_APPKEY}" /> -->
<!-- &lt;!&ndash; </>值来自开发者平台取得的AppKey&ndash;&gt;-->
</application>
</manifest>

View File

@@ -1,11 +1,18 @@
buildscript {
repositories {
mavenCentral()
google()
mavenCentral()
maven {url 'http://developer.huawei.com/repo/'}
maven { url "https://jitpack.io" }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
classpath GRADLE_CLASS_PATH
classpath PROTOBUF_CLASS_PATH
classpath "com.tencent.android.tpns:tpnsplugin:1.8.0"
}
}
@@ -30,6 +37,8 @@ final String FRAMEWORK_PREBUILTS_DIR = "${ANDROID_TOP}/prebuilts/framework_inter
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
//apply plugin: "com.tencent.android.tpns"
android {
gradle.projectsEvaluated {
@@ -57,17 +66,19 @@ android {
defaultConfig {
minSdkVersion 26
targetSdkVersion 28
versionCode 13
versionName "2.2"
versionCode 15
versionName "2.4"
ndk {
//选择要添加的对应 cpu 类型的 .so 库。
abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
// 还可以添加 'x86', 'x86_64', 'mips', 'mips64'
}
manifestPlaceholders = [
JPUSH_PKGNAME: "com.aoleyun.os",
JPUSH_APPKEY : "0c7ba5a1622dba78d5bd00cc", //JPush 上注册的包名对应的 Appkey.
JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可.
XG_ACCESS_ID : "1500026378",
XG_ACCESS_KEY: "AH5QD9ZMBJ6R",
// JPUSH_PKGNAME: "com.aoleyun.os",
// JPUSH_APPKEY : "0c7ba5a1622dba78d5bd00cc", //JPush 上注册的包名对应的 Appkey.
// JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可.
]
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -314,9 +325,11 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.7'
//mmkv
implementation 'com.tencent:mmkv-static:1.2.10'
//腾讯移动推送 TPNS
implementation 'com.tencent.tpns:tpns:1.2.2.0-release'
//极光推送
implementation 'cn.jiguang.sdk:jpush:3.8.6' // 此处以JPush 3.8.6 版本为例。
implementation 'cn.jiguang.sdk:jcore:2.6.0' // 此处以JCore 2.6.0 版本为例。
// implementation 'cn.jiguang.sdk:jpush:3.8.6' // 此处以JPush 3.8.6 版本为例。
// implementation 'cn.jiguang.sdk:jcore:2.6.0' // 此处以JCore 2.6.0 版本为例。
//下载
implementation 'me.laoyuyu.aria:core:3.8.16'
annotationProcessor 'me.laoyuyu.aria:compiler:3.8.16'

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@@ -169,7 +169,6 @@ import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import cn.jpush.android.api.JPushInterface;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
@@ -342,6 +341,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
Observable.create(updateSubscribe)
.throttleFirst(6, TimeUnit.HOURS)
.subscribe(updateObserver);
JGYUtils.getInstance().wakeUpAppstore();
JGYUtils.getInstance().wakeUpDeviceInfo();
startService(new Intent(Launcher.this, MainService.class));
if (DEBUG_STRICT_MODE) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
@@ -471,12 +472,12 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
}
});
registerMessageReceiver(); // used for receive msg
JPushInterface.init(this);
String rid = JPushInterface.getRegistrationID(this);
if (!TextUtils.isEmpty(rid)) {
Log.e("setJpushAlias", "RegId:" + rid);
}
JPushInterface.getAlias(this, new Random().nextInt(100));
// JPushInterface.init(this);
// String rid = JPushInterface.getRegistrationID(this);
// if (!TextUtils.isEmpty(rid)) {
// Log.e("setJpushAlias", "RegId:" + rid);
// }
// JPushInterface.getAlias(this, new Random().nextInt(100));
}
@@ -1115,8 +1116,11 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
String app_name = APKUtils.getAppNameByPackage(Launcher.this, packageName);
long openTime = TimeUtils.getInstance().getStartTime() / 1000;
long closeTime = TimeUtils.getInstance().getEndTime() / 1000;
NetworkManager.getInstance().getAppUsageRecordControl()
NetworkManager.getInstance()
.getAppUsageRecordControl()
.sendAppUsageRecord(Utils.getSerial(), packageName, app_name, openTime, closeTime)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(Disposable d) {

View File

@@ -8,13 +8,15 @@ import android.util.Log;
import com.aoleyun.os.BuildConfig;
import com.aoleyun.os.uiuiutils.ToastUtil;
import com.aoleyun.os.uiuiutils.Utils;
import com.aoleyun.os.jpush.TagAliasOperatorHelper;
import com.aoleyun.os.network.HTTPInterface;
import com.aoleyun.os.network.NetworkManager;
import com.aoleyun.os.network.URLPath;
import com.aoleyun.os.uiuiutils.JGYUtils;
import com.aoleyun.os.uiuiutils.TimeUtils;
import com.arialyy.aria.core.Aria;
import com.tencent.android.tpush.XGIOperateCallback;
import com.tencent.android.tpush.XGPushConfig;
import com.tencent.android.tpush.XGPushManager;
import com.tencent.mmkv.MMKV;
import org.jetbrains.annotations.NotNull;
@@ -22,8 +24,6 @@ import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.JPushMessage;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
@@ -67,8 +67,21 @@ public class BaseApplication extends Application {
}
private void initJPush() {
JPushInterface.setDebugMode(BuildConfig.DEBUG); // 设置开启日志,发布时请关闭日志
JPushInterface.init(this);
// JPushInterface.setDebugMode(BuildConfig.DEBUG); // 设置开启日志,发布时请关闭日志
// JPushInterface.init(this);
XGPushConfig.enableDebug(this,true);
XGPushManager.registerPush(this, new XGIOperateCallback() {
@Override
public void onSuccess(Object data, int flag) {
//token在设备卸载重装的时候有可能会变
Log.d("TPush", "注册成功设备token为" + data);
}
@Override
public void onFail(Object data, int errCode, String msg) {
Log.d("TPush", "注册失败,错误码:" + errCode + ",错误信息:" + msg);
}
});
initAliasObservable();
initTagObservable();
setJpushAlias();
@@ -157,17 +170,17 @@ public class BaseApplication extends Application {
});
}
public void onAliasOperatorResult(JPushMessage jPushMessage) {
if (jPushMessage == null) {
return;
}
int errorCode = jPushMessage.getErrorCode();
onAliasResult.onResult(errorCode);
}
// public void onAliasOperatorResult(JPushMessage jPushMessage) {
// if (jPushMessage == null) {
// return;
// }
// int errorCode = jPushMessage.getErrorCode();
// onAliasResult.onResult(errorCode);
// }
public static void setJpushAlias() {
Log.e("jiguangInterface", "30s后重新设置alias");
JPushInterface.setAlias(context, TagAliasOperatorHelper.sequence++, Utils.getSerial());
// JPushInterface.setAlias(context, TagAliasOperatorHelper.sequence++, Utils.getSerial());
}
private void initTagObservable() {
@@ -266,13 +279,13 @@ public class BaseApplication extends Application {
});
}
public void onTagOperatorResult(JPushMessage jPushMessage) {
if (jPushMessage == null) {
return;
}
int errorCode = jPushMessage.getErrorCode();
onTagResult.onResult(errorCode);
}
// public void onTagOperatorResult(JPushMessage jPushMessage) {
// if (jPushMessage == null) {
// return;
// }
// int errorCode = jPushMessage.getErrorCode();
// onTagResult.onResult(errorCode);
// }
public static void setJpushTags() {
Log.e("jiguangInterface", "30s后重新设置tags");

View File

@@ -1,7 +1,6 @@
package com.aoleyun.os.jpush;
import android.app.Application;
import cn.jpush.android.api.JPushInterface;
/**
* For developer startup JPush SDK
@@ -16,7 +15,7 @@ public class ExampleApplication extends Application {
Logger.d(TAG, "[ExampleApplication] onCreate");
super.onCreate();
JPushInterface.setDebugMode(true); // 设置开启日志,发布时请关闭日志
JPushInterface.init(this); // 初始化 JPush
// JPushInterface.setDebugMode(true); // 设置开启日志,发布时请关闭日志
// JPushInterface.init(this); // 初始化 JPush
}
}

View File

@@ -15,7 +15,6 @@ import android.text.TextUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import cn.jpush.android.api.JPushInterface;
public class ExampleUtil {
public static final String PREFS_NAME = "JPUSH_EXAMPLE";
@@ -126,7 +125,7 @@ public class ExampleUtil {
}
}
public static String getDeviceId(Context context) {
return JPushInterface.getUdid(context);
}
// public static String getDeviceId(Context context) {
// return JPushInterface.getUdid(context);
// }
}

View File

@@ -4,43 +4,37 @@ import android.content.Context;
import com.aoleyun.os.base.BaseApplication;
import cn.jpush.android.api.CustomMessage;
import cn.jpush.android.api.JPushMessage;
import cn.jpush.android.service.JPushMessageReceiver;
/**
* 自定义JPush message 接收器,包括操作tag/alias的结果返回(仅仅包含tag/alias新接口部分)
* */
public class MyJPushMessageReceiver extends JPushMessageReceiver {
@Override
public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
TagAliasOperatorHelper.getInstance().onTagOperatorResult(context,jPushMessage);
super.onTagOperatorResult(context, jPushMessage);
BaseApplication.getInstance().onTagOperatorResult(jPushMessage);
}
@Override
public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage){
TagAliasOperatorHelper.getInstance().onCheckTagOperatorResult(context,jPushMessage);
super.onCheckTagOperatorResult(context, jPushMessage);
}
@Override
public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
TagAliasOperatorHelper.getInstance().onAliasOperatorResult(context,jPushMessage);
super.onAliasOperatorResult(context, jPushMessage);
BaseApplication.getInstance().onAliasOperatorResult(jPushMessage);
}
@Override
public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) {
TagAliasOperatorHelper.getInstance().onMobileNumberOperatorResult(context,jPushMessage);
super.onMobileNumberOperatorResult(context, jPushMessage);
}
@Override
public void onMessage(Context context, CustomMessage customMessage) {
super.onMessage(context, customMessage);
}
}
//public class MyJPushMessageReceiver extends JPushMessageReceiver {
//
// @Override
// public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
// TagAliasOperatorHelper.getInstance().onTagOperatorResult(context,jPushMessage);
// super.onTagOperatorResult(context, jPushMessage);
// BaseApplication.getInstance().onTagOperatorResult(jPushMessage);
// }
// @Override
// public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage){
// TagAliasOperatorHelper.getInstance().onCheckTagOperatorResult(context,jPushMessage);
// super.onCheckTagOperatorResult(context, jPushMessage);
// }
// @Override
// public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
// TagAliasOperatorHelper.getInstance().onAliasOperatorResult(context,jPushMessage);
// super.onAliasOperatorResult(context, jPushMessage);
// BaseApplication.getInstance().onAliasOperatorResult(jPushMessage);
// }
//
// @Override
// public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) {
// TagAliasOperatorHelper.getInstance().onMobileNumberOperatorResult(context,jPushMessage);
// super.onMobileNumberOperatorResult(context, jPushMessage);
// }
//
// @Override
// public void onMessage(Context context, CustomMessage customMessage) {
// super.onMessage(context, customMessage);
// }
//}

View File

@@ -15,8 +15,6 @@ import org.json.JSONObject;
import java.util.Iterator;
import cn.jpush.android.api.JPushInterface;
/**
* 自定义接收器
* <p>
@@ -24,132 +22,130 @@ import cn.jpush.android.api.JPushInterface;
* 1) 默认用户会打开主界面
* 2) 接收不到自定义消息
*/
public class MyReceiver extends BroadcastReceiver {
private static final String TAG = "JIGUANG-Example";
@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);
Logger.d(TAG, "[MyReceiver] 接收Registration Id : " + regId);
//send the Registration Id to your server...
} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
Logger.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
processCustomMessage(context, bundle);
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知");
int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
Logger.d(TAG, "[MyReceiver] 用户点击打开了通知");
//打开自定义的Activity
Intent i = new Intent(context, TestActivity.class);
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);
} else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
Logger.w(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected);
} else {
Logger.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());
}
} catch (Exception e) {
}
}
// 打印所有的 intent extra 数据
private static String printBundle(Bundle bundle) {
StringBuilder sb = new StringBuilder();
for (String key : bundle.keySet()) {
if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
sb.append("\nkey:" + key + ", value:" + bundle.getInt(key));
} else if (key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)) {
sb.append("\nkey:" + key + ", value:" + bundle.getBoolean(key));
} else if (key.equals(JPushInterface.EXTRA_EXTRA)) {
if (TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) {
Logger.i(TAG, "This message has no Extra data");
continue;
}
try {
JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
Iterator<String> it = json.keys();
while (it.hasNext()) {
String myKey = it.next();
sb.append("\nkey:" + key + ", value: [" +
myKey + " - " + json.optString(myKey) + "]");
}
} catch (JSONException e) {
Logger.e(TAG, "Get message extra JSON error!");
}
} else {
sb.append("\nkey:" + key + ", value:" + bundle.get(key));
}
}
return sb.toString();
}
private static final String SEND_RUNNING_APP = "2";
//应用锁
private static final String UPDATE_APP_LOCK = "39";
//send msg to MainActivity
private void processCustomMessage(Context context, Bundle bundle) {
// if (Launcher.isForeground) {
// String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
// String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
// Intent msgIntent = new Intent(Launcher.MESSAGE_RECEIVED_ACTION);
// msgIntent.putExtra(Launcher.KEY_MESSAGE, message);
// if (!ExampleUtil.isEmpty(extras)) {
// try {
// JSONObject extraJson = new JSONObject(extras);
// if (extraJson.length() > 0) {
// msgIntent.putExtra(Launcher.KEY_EXTRAS, extras);
// }
// } catch (JSONException e) {
//public class MyReceiver extends BroadcastReceiver {
// private static final String TAG = "JIGUANG-Example";
//
// }
// @Override
// public void onReceive(Context context, Intent intent) {
// try {
// Bundle bundle = intent.getExtras();
// Logger.d(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));
//
// }
// LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
// }
String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
String title = bundle.getString(JPushInterface.EXTRA_TITLE);
String type = bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE);
String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
switch (message) {
case SEND_RUNNING_APP:
getRunningApp(context);
break;
case UPDATE_APP_LOCK:
HTTPInterface.getAppPasswd();
break;
default:
break;
}
}
private void getRunningApp(Context context) {
HTTPInterface.sendRunningApp(context);
}
}
// if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
// String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
// Logger.d(TAG, "[MyReceiver] 接收Registration Id : " + regId);
// //send the Registration Id to your server...
//
// } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
// Logger.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
// processCustomMessage(context, bundle);
//
// } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
// Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知");
// int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
// Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);
//
// } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
// Logger.d(TAG, "[MyReceiver] 用户点击打开了通知");
//
// //打开自定义的Activity
// Intent i = new Intent(context, TestActivity.class);
// 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);
//
// } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
// boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
// Logger.w(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected);
// } else {
// Logger.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());
// }
// } catch (Exception e) {
//
// }
//
// }
//
// // 打印所有的 intent extra 数据
// private static String printBundle(Bundle bundle) {
// StringBuilder sb = new StringBuilder();
// for (String key : bundle.keySet()) {
// if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
// sb.append("\nkey:" + key + ", value:" + bundle.getInt(key));
// } else if (key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)) {
// sb.append("\nkey:" + key + ", value:" + bundle.getBoolean(key));
// } else if (key.equals(JPushInterface.EXTRA_EXTRA)) {
// if (TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) {
// Logger.i(TAG, "This message has no Extra data");
// continue;
// }
//
// try {
// JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
// Iterator<String> it = json.keys();
//
// while (it.hasNext()) {
// String myKey = it.next();
// sb.append("\nkey:" + key + ", value: [" +
// myKey + " - " + json.optString(myKey) + "]");
// }
// } catch (JSONException e) {
// Logger.e(TAG, "Get message extra JSON error!");
// }
//
// } else {
// sb.append("\nkey:" + key + ", value:" + bundle.get(key));
// }
// }
// return sb.toString();
// }
//
// private static final String SEND_RUNNING_APP = "2";
// //应用锁
// private static final String UPDATE_APP_LOCK = "39";
//
//
// //send msg to MainActivity
// private void processCustomMessage(Context context, Bundle bundle) {
//// if (Launcher.isForeground) {
//// String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
//// String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
//// Intent msgIntent = new Intent(Launcher.MESSAGE_RECEIVED_ACTION);
//// msgIntent.putExtra(Launcher.KEY_MESSAGE, message);
//// if (!ExampleUtil.isEmpty(extras)) {
//// try {
//// JSONObject extraJson = new JSONObject(extras);
//// if (extraJson.length() > 0) {
//// msgIntent.putExtra(Launcher.KEY_EXTRAS, extras);
//// }
//// } catch (JSONException e) {
////
//// }
////
//// }
//// LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
//// }
//
// String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
// String title = bundle.getString(JPushInterface.EXTRA_TITLE);
// String type = bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE);
// String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
//
// switch (message) {
// case SEND_RUNNING_APP:
// getRunningApp(context);
// break;
// case UPDATE_APP_LOCK:
// HTTPInterface.getAppPasswd();
// break;
// default:
// break;
// }
// }
//
// private void getRunningApp(Context context) {
// HTTPInterface.sendRunningApp(context);
// }
//
//}

View File

@@ -1,7 +1,6 @@
package com.aoleyun.os.jpush;
import cn.jpush.android.service.JCommonService;
public class PushService extends JCommonService {
}
//public class PushService extends JCommonService {
//
//}

View File

@@ -11,335 +11,334 @@ import com.aoleyun.os.uiuiutils.ToastUtil;
import java.util.Locale;
import java.util.Set;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.JPushMessage;
/**
* 处理tagalias相关的逻辑
* */
public class TagAliasOperatorHelper {
private static final String TAG = "JIGUANG-TagAliasHelper";
public static int sequence = 1;
/**增加*/
public static final int ACTION_ADD = 1;
/**覆盖*/
public static final int ACTION_SET = 2;
/**删除部分*/
public static final int ACTION_DELETE = 3;
/**删除所有*/
public static final int ACTION_CLEAN = 4;
/**查询*/
public static final int ACTION_GET = 5;
public static final int ACTION_CHECK = 6;
public static final int DELAY_SEND_ACTION = 1;
public static final int DELAY_SET_MOBILE_NUMBER_ACTION = 2;
private Context context;
private static TagAliasOperatorHelper mInstance;
private TagAliasOperatorHelper(){
}
public static TagAliasOperatorHelper getInstance(){
if(mInstance == null){
synchronized (TagAliasOperatorHelper.class){
if(mInstance == null){
mInstance = new TagAliasOperatorHelper();
}
}
}
return mInstance;
}
public void init(Context context){
if(context != null) {
this.context = context.getApplicationContext();
}
}
private SparseArray<Object> setActionCache = new SparseArray<Object>();
public Object get(int sequence){
return setActionCache.get(sequence);
}
public Object remove(int sequence){
return setActionCache.get(sequence);
}
public void put(int sequence, Object tagAliasBean){
setActionCache.put(sequence,tagAliasBean);
}
private Handler delaySendHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
switch (msg.what){
case DELAY_SEND_ACTION:
if(msg.obj !=null && msg.obj instanceof TagAliasBean){
Logger.i(TAG,"on delay time");
sequence++;
TagAliasBean tagAliasBean = (TagAliasBean) msg.obj;
setActionCache.put(sequence, tagAliasBean);
if(context!=null) {
handleAction(context, sequence, tagAliasBean);
}else{
Logger.e(TAG,"#unexcepted - context was null");
}
}else{
Logger.w(TAG,"#unexcepted - msg obj was incorrect");
}
break;
case DELAY_SET_MOBILE_NUMBER_ACTION:
if(msg.obj !=null && msg.obj instanceof String) {
Logger.i(TAG, "retry set mobile number");
sequence++;
String mobileNumber = (String) msg.obj;
setActionCache.put(sequence, mobileNumber);
if(context !=null) {
handleAction(context, sequence, mobileNumber);
}else {
Logger.e(TAG, "#unexcepted - context was null");
}
}else{
Logger.w(TAG,"#unexcepted - msg obj was incorrect");
}
break;
}
}
};
public void handleAction(Context context, int sequence, String mobileNumber){
put(sequence,mobileNumber);
Logger.d(TAG,"sequence:"+sequence+",mobileNumber:"+mobileNumber);
JPushInterface.setMobileNumber(context,sequence,mobileNumber);
}
/**
* 处理设置tag
* */
public void handleAction(Context context, int sequence, TagAliasBean tagAliasBean){
init(context);
if(tagAliasBean == null){
Logger.w(TAG,"tagAliasBean was null");
return;
}
put(sequence,tagAliasBean);
if(tagAliasBean.isAliasAction){
switch (tagAliasBean.action){
case ACTION_GET:
JPushInterface.getAlias(context,sequence);
break;
case ACTION_DELETE:
JPushInterface.deleteAlias(context,sequence);
break;
case ACTION_SET:
JPushInterface.setAlias(context,sequence,tagAliasBean.alias);
break;
default:
Logger.w(TAG,"unsupport alias action type");
return;
}
}else {
switch (tagAliasBean.action) {
case ACTION_ADD:
JPushInterface.addTags(context, sequence, tagAliasBean.tags);
break;
case ACTION_SET:
JPushInterface.setTags(context, sequence, tagAliasBean.tags);
break;
case ACTION_DELETE:
JPushInterface.deleteTags(context, sequence, tagAliasBean.tags);
break;
case ACTION_CHECK:
//一次只能check一个tag
String tag = (String)tagAliasBean.tags.toArray()[0];
JPushInterface.checkTagBindState(context,sequence,tag);
break;
case ACTION_GET:
JPushInterface.getAllTags(context, sequence);
break;
case ACTION_CLEAN:
JPushInterface.cleanTags(context, sequence);
break;
default:
Logger.w(TAG,"unsupport tag action type");
return;
}
}
}
private boolean RetryActionIfNeeded(int errorCode,TagAliasBean tagAliasBean){
if(!ExampleUtil.isConnected(context)){
Logger.w(TAG,"no network");
return false;
}
//返回的错误码为6002 超时,6014 服务器繁忙,都建议延迟重试
if(errorCode == 6002 || errorCode == 6014){
Logger.d(TAG,"need retry");
if(tagAliasBean!=null){
Message message = new Message();
message.what = DELAY_SEND_ACTION;
message.obj = tagAliasBean;
delaySendHandler.sendMessageDelayed(message,1000*60);
String logs =getRetryStr(tagAliasBean.isAliasAction, tagAliasBean.action,errorCode);
ExampleUtil.showToast(logs, context);
return true;
}
}
return false;
}
private boolean RetrySetMObileNumberActionIfNeeded(int errorCode, String mobileNumber){
if(!ExampleUtil.isConnected(context)){
Logger.w(TAG,"no network");
return false;
}
//返回的错误码为6002 超时,6024 服务器内部错误,建议稍后重试
if(errorCode == 6002 || errorCode == 6024){
Logger.d(TAG,"need retry");
Message message = new Message();
message.what = DELAY_SET_MOBILE_NUMBER_ACTION;
message.obj = mobileNumber;
delaySendHandler.sendMessageDelayed(message,1000*60);
String str = "Failed to set mobile number due to %s. Try again after 60s.";
str = String.format(Locale.ENGLISH,str,(errorCode == 6002 ? "timeout" : "server internal error”"));
ExampleUtil.showToast(str, context);
return true;
}
return false;
}
private String getRetryStr(boolean isAliasAction, int actionType, int errorCode){
String str = "Failed to %s %s due to %s. Try again after 60s.";
str = String.format(Locale.ENGLISH,str,getActionStr(actionType),(isAliasAction? "alias" : " tags") ,(errorCode == 6002 ? "timeout" : "server too busy"));
return str;
}
private String getActionStr(int actionType){
switch (actionType){
case ACTION_ADD:
return "add";
case ACTION_SET:
return "set";
case ACTION_DELETE:
return "delete";
case ACTION_GET:
return "get";
case ACTION_CLEAN:
return "clean";
case ACTION_CHECK:
return "check";
}
return "unkonw operation";
}
public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
int sequence = jPushMessage.getSequence();
Logger.i(TAG,"action - onTagOperatorResult, sequence:"+sequence+",tags:"+jPushMessage.getTags());
Logger.i(TAG,"tags size:"+jPushMessage.getTags().size());
init(context);
//根据sequence从之前操作缓存中获取缓存记录
TagAliasBean tagAliasBean = (TagAliasBean)setActionCache.get(sequence);
if(tagAliasBean == null){
ExampleUtil.showToast("获取缓存记录失败", context);
return;
}
if(jPushMessage.getErrorCode() == 0){
Logger.i(TAG,"action - modify tag Success,sequence:"+sequence);
setActionCache.remove(sequence);
String logs = getActionStr(tagAliasBean.action)+" tags success";
Logger.i(TAG,logs);
Log.e(TAG,"Tag绑定成功: " + jPushMessage.getTags());
ToastUtil.betaShow("Tag绑定成功: " + jPushMessage.getTags());
ExampleUtil.showToast(logs, context);
}else{
String logs = "Failed to " + getActionStr(tagAliasBean.action)+" tags";
if(jPushMessage.getErrorCode() == 6018){
//tag数量超过限制,需要先清除一部分再add
logs += ", tags is exceed limit need to clean";
}
logs += ", errorCode:" + jPushMessage.getErrorCode();
Logger.e(TAG, logs);
if(!RetryActionIfNeeded(jPushMessage.getErrorCode(),tagAliasBean)) {
ExampleUtil.showToast(logs, context);
}
}
}
public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage){
int sequence = jPushMessage.getSequence();
Logger.i(TAG,"action - onCheckTagOperatorResult, sequence:"+sequence+",checktag:"+jPushMessage.getCheckTag());
init(context);
//根据sequence从之前操作缓存中获取缓存记录
TagAliasBean tagAliasBean = (TagAliasBean)setActionCache.get(sequence);
if(tagAliasBean == null){
ExampleUtil.showToast("获取缓存记录失败", context);
return;
}
if(jPushMessage.getErrorCode() == 0){
Logger.i(TAG,"tagBean:"+tagAliasBean);
setActionCache.remove(sequence);
String logs = getActionStr(tagAliasBean.action)+" tag "+jPushMessage.getCheckTag() + " bind state success,state:"+jPushMessage.getTagCheckStateResult();
Logger.i(TAG,logs);
ExampleUtil.showToast(logs, context);
}else{
String logs = "Failed to " + getActionStr(tagAliasBean.action)+" tags, errorCode:" + jPushMessage.getErrorCode();
Logger.e(TAG, logs);
if(!RetryActionIfNeeded(jPushMessage.getErrorCode(),tagAliasBean)) {
ExampleUtil.showToast(logs, context);
}
}
}
public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
int sequence = jPushMessage.getSequence();
Logger.i(TAG,"action - onAliasOperatorResult, sequence:"+sequence+",alias:"+jPushMessage.getAlias());
init(context);
//根据sequence从之前操作缓存中获取缓存记录
TagAliasBean tagAliasBean = (TagAliasBean)setActionCache.get(sequence);
if(tagAliasBean == null){
ExampleUtil.showToast("获取缓存记录失败", context);
return;
}
if(jPushMessage.getErrorCode() == 0){
Logger.i(TAG,"action - modify alias Success,sequence:"+sequence);
setActionCache.remove(sequence);
String logs = getActionStr(tagAliasBean.action)+" alias success";
Logger.i(TAG,logs);
Log.e(TAG,"Alias绑定成功: "+jPushMessage.getAlias());
ToastUtil.betaShow("Alias绑定成功: "+jPushMessage.getAlias());
ExampleUtil.showToast(logs, context);
}else{
String logs = "Failed to " + getActionStr(tagAliasBean.action)+" alias, errorCode:" + jPushMessage.getErrorCode();
Logger.e(TAG, logs);
if(!RetryActionIfNeeded(jPushMessage.getErrorCode(),tagAliasBean)) {
ExampleUtil.showToast(logs, context);
}
}
}
//设置手机号码回调
public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) {
int sequence = jPushMessage.getSequence();
Logger.i(TAG,"action - onMobileNumberOperatorResult, sequence:"+sequence+",mobileNumber:"+jPushMessage.getMobileNumber());
init(context);
if(jPushMessage.getErrorCode() == 0){
Logger.i(TAG,"action - set mobile number Success,sequence:"+sequence);
setActionCache.remove(sequence);
}else{
String logs = "Failed to set mobile number, errorCode:" + jPushMessage.getErrorCode();
Logger.e(TAG, logs);
if(!RetrySetMObileNumberActionIfNeeded(jPushMessage.getErrorCode(),jPushMessage.getMobileNumber())){
ExampleUtil.showToast(logs, context);
}
}
}
public static class TagAliasBean{
public int action;
public Set<String> tags;
public String alias;
public boolean isAliasAction;
@Override
public String toString() {
return "TagAliasBean{" +
"action=" + action +
", tags=" + tags +
", alias='" + alias + '\'' +
", isAliasAction=" + isAliasAction +
'}';
}
}
}
//public class TagAliasOperatorHelper {
// private static final String TAG = "JIGUANG-TagAliasHelper";
// public static int sequence = 1;
// /**增加*/
// public static final int ACTION_ADD = 1;
// /**覆盖*/
// public static final int ACTION_SET = 2;
// /**删除部分*/
// public static final int ACTION_DELETE = 3;
// /**删除所有*/
// public static final int ACTION_CLEAN = 4;
// /**查询*/
// public static final int ACTION_GET = 5;
//
// public static final int ACTION_CHECK = 6;
//
// public static final int DELAY_SEND_ACTION = 1;
//
// public static final int DELAY_SET_MOBILE_NUMBER_ACTION = 2;
//
// private Context context;
//
// private static TagAliasOperatorHelper mInstance;
// private TagAliasOperatorHelper(){
// }
// public static TagAliasOperatorHelper getInstance(){
// if(mInstance == null){
// synchronized (TagAliasOperatorHelper.class){
// if(mInstance == null){
// mInstance = new TagAliasOperatorHelper();
// }
// }
// }
// return mInstance;
// }
// public void init(Context context){
// if(context != null) {
// this.context = context.getApplicationContext();
// }
// }
// private SparseArray<Object> setActionCache = new SparseArray<Object>();
//
// public Object get(int sequence){
// return setActionCache.get(sequence);
// }
// public Object remove(int sequence){
// return setActionCache.get(sequence);
// }
// public void put(int sequence, Object tagAliasBean){
// setActionCache.put(sequence,tagAliasBean);
// }
// private Handler delaySendHandler = new Handler(){
// @Override
// public void handleMessage(Message msg) {
// switch (msg.what){
// case DELAY_SEND_ACTION:
// if(msg.obj !=null && msg.obj instanceof TagAliasBean){
// Logger.i(TAG,"on delay time");
// sequence++;
// TagAliasBean tagAliasBean = (TagAliasBean) msg.obj;
// setActionCache.put(sequence, tagAliasBean);
// if(context!=null) {
// handleAction(context, sequence, tagAliasBean);
// }else{
// Logger.e(TAG,"#unexcepted - context was null");
// }
// }else{
// Logger.w(TAG,"#unexcepted - msg obj was incorrect");
// }
// break;
// case DELAY_SET_MOBILE_NUMBER_ACTION:
// if(msg.obj !=null && msg.obj instanceof String) {
// Logger.i(TAG, "retry set mobile number");
// sequence++;
// String mobileNumber = (String) msg.obj;
// setActionCache.put(sequence, mobileNumber);
// if(context !=null) {
// handleAction(context, sequence, mobileNumber);
// }else {
// Logger.e(TAG, "#unexcepted - context was null");
// }
// }else{
// Logger.w(TAG,"#unexcepted - msg obj was incorrect");
// }
// break;
// }
// }
// };
// public void handleAction(Context context, int sequence, String mobileNumber){
// put(sequence,mobileNumber);
// Logger.d(TAG,"sequence:"+sequence+",mobileNumber:"+mobileNumber);
// JPushInterface.setMobileNumber(context,sequence,mobileNumber);
// }
// /**
// * 处理设置tag
// * */
// public void handleAction(Context context, int sequence, TagAliasBean tagAliasBean){
// init(context);
// if(tagAliasBean == null){
// Logger.w(TAG,"tagAliasBean was null");
// return;
// }
// put(sequence,tagAliasBean);
// if(tagAliasBean.isAliasAction){
// switch (tagAliasBean.action){
// case ACTION_GET:
// JPushInterface.getAlias(context,sequence);
// break;
// case ACTION_DELETE:
// JPushInterface.deleteAlias(context,sequence);
// break;
// case ACTION_SET:
// JPushInterface.setAlias(context,sequence,tagAliasBean.alias);
// break;
// default:
// Logger.w(TAG,"unsupport alias action type");
// return;
// }
// }else {
// switch (tagAliasBean.action) {
// case ACTION_ADD:
// JPushInterface.addTags(context, sequence, tagAliasBean.tags);
// break;
// case ACTION_SET:
// JPushInterface.setTags(context, sequence, tagAliasBean.tags);
// break;
// case ACTION_DELETE:
// JPushInterface.deleteTags(context, sequence, tagAliasBean.tags);
// break;
// case ACTION_CHECK:
// //一次只能check一个tag
// String tag = (String)tagAliasBean.tags.toArray()[0];
// JPushInterface.checkTagBindState(context,sequence,tag);
// break;
// case ACTION_GET:
// JPushInterface.getAllTags(context, sequence);
// break;
// case ACTION_CLEAN:
// JPushInterface.cleanTags(context, sequence);
// break;
// default:
// Logger.w(TAG,"unsupport tag action type");
// return;
// }
// }
// }
// private boolean RetryActionIfNeeded(int errorCode,TagAliasBean tagAliasBean){
// if(!ExampleUtil.isConnected(context)){
// Logger.w(TAG,"no network");
// return false;
// }
// //返回的错误码为6002 超时,6014 服务器繁忙,都建议延迟重试
// if(errorCode == 6002 || errorCode == 6014){
// Logger.d(TAG,"need retry");
// if(tagAliasBean!=null){
// Message message = new Message();
// message.what = DELAY_SEND_ACTION;
// message.obj = tagAliasBean;
// delaySendHandler.sendMessageDelayed(message,1000*60);
// String logs =getRetryStr(tagAliasBean.isAliasAction, tagAliasBean.action,errorCode);
// ExampleUtil.showToast(logs, context);
// return true;
// }
// }
// return false;
// }
// private boolean RetrySetMObileNumberActionIfNeeded(int errorCode, String mobileNumber){
// if(!ExampleUtil.isConnected(context)){
// Logger.w(TAG,"no network");
// return false;
// }
// //返回的错误码为6002 超时,6024 服务器内部错误,建议稍后重试
// if(errorCode == 6002 || errorCode == 6024){
// Logger.d(TAG,"need retry");
// Message message = new Message();
// message.what = DELAY_SET_MOBILE_NUMBER_ACTION;
// message.obj = mobileNumber;
// delaySendHandler.sendMessageDelayed(message,1000*60);
// String str = "Failed to set mobile number due to %s. Try again after 60s.";
// str = String.format(Locale.ENGLISH,str,(errorCode == 6002 ? "timeout" : "server internal error”"));
// ExampleUtil.showToast(str, context);
// return true;
// }
// return false;
//
// }
// private String getRetryStr(boolean isAliasAction, int actionType, int errorCode){
// String str = "Failed to %s %s due to %s. Try again after 60s.";
// str = String.format(Locale.ENGLISH,str,getActionStr(actionType),(isAliasAction? "alias" : " tags") ,(errorCode == 6002 ? "timeout" : "server too busy"));
// return str;
// }
//
// private String getActionStr(int actionType){
// switch (actionType){
// case ACTION_ADD:
// return "add";
// case ACTION_SET:
// return "set";
// case ACTION_DELETE:
// return "delete";
// case ACTION_GET:
// return "get";
// case ACTION_CLEAN:
// return "clean";
// case ACTION_CHECK:
// return "check";
// }
// return "unkonw operation";
// }
//
// public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
// int sequence = jPushMessage.getSequence();
// Logger.i(TAG,"action - onTagOperatorResult, sequence:"+sequence+",tags:"+jPushMessage.getTags());
// Logger.i(TAG,"tags size:"+jPushMessage.getTags().size());
// init(context);
// //根据sequence从之前操作缓存中获取缓存记录
// TagAliasBean tagAliasBean = (TagAliasBean)setActionCache.get(sequence);
// if(tagAliasBean == null){
// ExampleUtil.showToast("获取缓存记录失败", context);
// return;
// }
// if(jPushMessage.getErrorCode() == 0){
// Logger.i(TAG,"action - modify tag Success,sequence:"+sequence);
// setActionCache.remove(sequence);
// String logs = getActionStr(tagAliasBean.action)+" tags success";
// Logger.i(TAG,logs);
// Log.e(TAG,"Tag绑定成功: " + jPushMessage.getTags());
// ToastUtil.betaShow("Tag绑定成功: " + jPushMessage.getTags());
// ExampleUtil.showToast(logs, context);
// }else{
// String logs = "Failed to " + getActionStr(tagAliasBean.action)+" tags";
// if(jPushMessage.getErrorCode() == 6018){
// //tag数量超过限制,需要先清除一部分再add
// logs += ", tags is exceed limit need to clean";
// }
// logs += ", errorCode:" + jPushMessage.getErrorCode();
// Logger.e(TAG, logs);
// if(!RetryActionIfNeeded(jPushMessage.getErrorCode(),tagAliasBean)) {
// ExampleUtil.showToast(logs, context);
// }
// }
// }
//
// public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage){
// int sequence = jPushMessage.getSequence();
// Logger.i(TAG,"action - onCheckTagOperatorResult, sequence:"+sequence+",checktag:"+jPushMessage.getCheckTag());
// init(context);
// //根据sequence从之前操作缓存中获取缓存记录
// TagAliasBean tagAliasBean = (TagAliasBean)setActionCache.get(sequence);
// if(tagAliasBean == null){
// ExampleUtil.showToast("获取缓存记录失败", context);
// return;
// }
// if(jPushMessage.getErrorCode() == 0){
// Logger.i(TAG,"tagBean:"+tagAliasBean);
// setActionCache.remove(sequence);
// String logs = getActionStr(tagAliasBean.action)+" tag "+jPushMessage.getCheckTag() + " bind state success,state:"+jPushMessage.getTagCheckStateResult();
// Logger.i(TAG,logs);
// ExampleUtil.showToast(logs, context);
// }else{
// String logs = "Failed to " + getActionStr(tagAliasBean.action)+" tags, errorCode:" + jPushMessage.getErrorCode();
// Logger.e(TAG, logs);
// if(!RetryActionIfNeeded(jPushMessage.getErrorCode(),tagAliasBean)) {
// ExampleUtil.showToast(logs, context);
// }
// }
// }
//
// public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
// int sequence = jPushMessage.getSequence();
// Logger.i(TAG,"action - onAliasOperatorResult, sequence:"+sequence+",alias:"+jPushMessage.getAlias());
// init(context);
// //根据sequence从之前操作缓存中获取缓存记录
// TagAliasBean tagAliasBean = (TagAliasBean)setActionCache.get(sequence);
// if(tagAliasBean == null){
// ExampleUtil.showToast("获取缓存记录失败", context);
// return;
// }
// if(jPushMessage.getErrorCode() == 0){
// Logger.i(TAG,"action - modify alias Success,sequence:"+sequence);
// setActionCache.remove(sequence);
// String logs = getActionStr(tagAliasBean.action)+" alias success";
// Logger.i(TAG,logs);
// Log.e(TAG,"Alias绑定成功: "+jPushMessage.getAlias());
// ToastUtil.betaShow("Alias绑定成功: "+jPushMessage.getAlias());
// ExampleUtil.showToast(logs, context);
// }else{
// String logs = "Failed to " + getActionStr(tagAliasBean.action)+" alias, errorCode:" + jPushMessage.getErrorCode();
// Logger.e(TAG, logs);
// if(!RetryActionIfNeeded(jPushMessage.getErrorCode(),tagAliasBean)) {
// ExampleUtil.showToast(logs, context);
// }
// }
// }
// //设置手机号码回调
// public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) {
// int sequence = jPushMessage.getSequence();
// Logger.i(TAG,"action - onMobileNumberOperatorResult, sequence:"+sequence+",mobileNumber:"+jPushMessage.getMobileNumber());
// init(context);
// if(jPushMessage.getErrorCode() == 0){
// Logger.i(TAG,"action - set mobile number Success,sequence:"+sequence);
// setActionCache.remove(sequence);
// }else{
// String logs = "Failed to set mobile number, errorCode:" + jPushMessage.getErrorCode();
// Logger.e(TAG, logs);
// if(!RetrySetMObileNumberActionIfNeeded(jPushMessage.getErrorCode(),jPushMessage.getMobileNumber())){
// ExampleUtil.showToast(logs, context);
// }
// }
// }
//
// public static class TagAliasBean{
// public int action;
// public Set<String> tags;
// public String alias;
// public boolean isAliasAction;
//
// @Override
// public String toString() {
// return "TagAliasBean{" +
// "action=" + action +
// ", tags=" + tags +
// ", alias='" + alias + '\'' +
// ", isAliasAction=" + isAliasAction +
// '}';
// }
// }
//}

View File

@@ -6,8 +6,6 @@ import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;
import cn.jpush.android.api.JPushInterface;
public class TestActivity extends Activity {
@Override
@@ -21,8 +19,8 @@ public class TestActivity extends Activity {
String title = null;
String content = null;
if(bundle!=null){
title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
content = bundle.getString(JPushInterface.EXTRA_ALERT);
// title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
// content = bundle.getString(JPushInterface.EXTRA_ALERT);
}
tv.setText("Title : " + title + " " + "Content : " + content);
}

View File

@@ -35,6 +35,8 @@ import android.content.pm.ShortcutInfo;
import android.os.Handler;
import android.os.Process;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.SettingsValidators;
import android.text.TextUtils;
import android.util.Log;
import android.util.LongSparseArray;
@@ -274,8 +276,8 @@ public class LoaderTask implements Runnable {
this.add("com.aoleyunos.dop1");
this.add("com.aoleyunos.dop2");
//system
this.add("com.android.documentsui");
this.add("com.android.messaging");
// this.add("com.android.documentsui");
// this.add("com.android.messaging");
this.add("com.android.music");
this.add("com.android.camera");
this.add("com.android.camera2");
@@ -296,16 +298,26 @@ public class LoaderTask implements Runnable {
final Context context = mApp.getContext();
ArrayList<Pair<ItemInfo, Object>> installQueue = new ArrayList<>();
final List<UserHandle> profiles = mUserManager.getUserProfiles();
String whiteList = Settings.System.getString(context.getContentResolver(), "only_jgy_shortcut_list");
for (UserHandle user : profiles) {
final List<LauncherActivityInfo> apps = mLauncherApps.getActivityList(null, user);
ArrayList<InstallShortcutReceiver.PendingInstallShortcutInfo> added = new ArrayList<InstallShortcutReceiver.PendingInstallShortcutInfo>();
synchronized (this) {
for (LauncherActivityInfo app : apps) {
if (BuildConfig.APPLICATION_ID.equals(app.getApplicationInfo().packageName))
continue;
Log.e(TAG, "verifyApplications: " + app.getApplicationInfo().packageName);
/*系统应用*/
if ((app.getApplicationFlags() & ApplicationInfo.FLAG_SYSTEM) == 1) {
if (!showApp.contains(app.getApplicationInfo().packageName)) {
continue;
}
} else {
if (TextUtils.isEmpty(whiteList)) {
continue;
} else if (!whiteList.contains(app.getApplicationInfo().packageName)){
continue;
}
}
InstallShortcutReceiver.PendingInstallShortcutInfo pendingInstallShortcutInfo = new InstallShortcutReceiver.PendingInstallShortcutInfo(app, context);
added.add(pendingInstallShortcutInfo);

View File

@@ -7,7 +7,7 @@ import android.util.Log;
import com.aoleyun.os.network.bean.AppPasswdBean;
import com.aoleyun.os.network.bean.BaseResponse;
import com.aoleyun.os.uiuiutils.APKUtils;
import com.aoleyun.os.jpush.TagAliasOperatorHelper;
//import com.aoleyun.os.jpush.TagAliasOperatorHelper;
import com.aoleyun.os.uiuiutils.JGYUtils;
import com.aoleyun.os.uiuiutils.TimeUtils;
import com.google.gson.Gson;
@@ -23,9 +23,6 @@ import io.reactivex.Observer;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import static com.aoleyun.os.jpush.TagAliasOperatorHelper.ACTION_SET;
import static com.aoleyun.os.jpush.TagAliasOperatorHelper.sequence;
/**
* @author : fanhuitong
* e-mail :
@@ -97,7 +94,7 @@ public class HTTPInterface {
}
}
});
setTag(context, set);
// setTag(context, set);
} else {
Log.e(TAG + ":" + "setJpushTags", "onNext: " + "batch empty");
}
@@ -159,13 +156,13 @@ public class HTTPInterface {
});
}
private static void setTag(Context context, Set set) {
TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();
tagAliasBean.action = ACTION_SET;
sequence++;
tagAliasBean.tags = set;
tagAliasBean.isAliasAction = false;
TagAliasOperatorHelper.getInstance().handleAction(context, sequence, tagAliasBean);
}
// private static void setTag(Context context, Set set) {
// TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();
// tagAliasBean.action = ACTION_SET;
// sequence++;
// tagAliasBean.tags = set;
// tagAliasBean.isAliasAction = false;
// TagAliasOperatorHelper.getInstance().handleAction(context, sequence, tagAliasBean);
// }
}

View File

@@ -1,14 +1,17 @@
package com.aoleyun.os.uiuiutils;
import android.annotation.SuppressLint;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import com.android.server.BootReceiver;
import com.aoleyun.os.BuildConfig;
import com.aoleyun.os.model.LoaderTask;
@@ -180,5 +183,30 @@ public class JGYUtils {
appSet.addAll(LoaderTask.showApp);
return appSet.contains(pkg);
}
public static final String PACKAGE_DEVICEINFO = "com.aoleyun.sn";
public static final String PACKAGE_APPSTORE = "com.aoleyun.appstore";
public static final String CLASS_DEVICEINFO = "com.aoleyun.sn.receiver.BootReceiver";
public static final String CLASS_APPSTORE = "com.aoleyun.appstore.receiver.BootReceiver";
public static final String ACTION_DEVICEINFO = "com.aoleyun.sn.intent.action.BOOT_COMPLETED";
public static final String ACTION_APPSTORE = "com.aoleyun.appstore.intent.action.BOOT_COMPLETED";
public void wakeUpDeviceInfo() {
//启动设备信息
Intent bootIntent = new Intent(ACTION_DEVICEINFO);
bootIntent.setComponent(new ComponentName(PACKAGE_DEVICEINFO, CLASS_DEVICEINFO));
mContext.sendBroadcast(bootIntent);
}
public void wakeUpAppstore() {
//启动应用市场
Intent bootIntent = new Intent(ACTION_APPSTORE);
bootIntent.setComponent(new ComponentName(PACKAGE_APPSTORE, CLASS_APPSTORE));
mContext.sendBroadcast(bootIntent);
}
}