version:1.1

fix:
add:应用使用数据统计
This commit is contained in:
2021-12-25 16:54:44 +08:00
parent 88f65afb48
commit 71e5516ab8
159 changed files with 1671 additions and 3312 deletions

View File

@@ -0,0 +1,25 @@
package com.uiui.sn.jpush;
import android.app.Application;
import com.uiui.sn.BuildConfig;
import cn.jpush.android.api.JPushInterface;
/**
* For developer startup JPush SDK
*
* 一般建议在自定义 Application 类里初始化。也可以在主 Activity 里。
*/
public class ExampleApplication extends Application {
private static final String TAG = "JIGUANG-Example";
@Override
public void onCreate() {
Logger.d(TAG, "[ExampleApplication] onCreate");
super.onCreate();
JPushInterface.setDebugMode(BuildConfig.DEBUG); // 设置开启日志,发布时请关闭日志
JPushInterface.init(this); // 初始化 JPush
}
}

View File

@@ -0,0 +1,131 @@
package com.uiui.sn.jpush;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.telephony.TelephonyManager;
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";
public static final String PREFS_DAYS = "JPUSH_EXAMPLE_DAYS";
public static final String PREFS_START_TIME = "PREFS_START_TIME";
public static final String PREFS_END_TIME = "PREFS_END_TIME";
public static final String KEY_APP_KEY = "JPUSH_APPKEY";
public static boolean isEmpty(String s) {
if (null == s)
return true;
if (s.length() == 0)
return true;
if (s.trim().length() == 0)
return true;
return false;
}
/**
* 只能以 “+” 或者 数字开头;后面的内容只能包含 “-” 和 数字。
* */
private final static String MOBILE_NUMBER_CHARS = "^[+0-9][-0-9]{1,}$";
public static boolean isValidMobileNumber(String s) {
if(TextUtils.isEmpty(s)) return true;
Pattern p = Pattern.compile(MOBILE_NUMBER_CHARS);
Matcher m = p.matcher(s);
return m.matches();
}
// 校验Tag Alias 只能是数字,英文字母和中文
public static boolean isValidTagAndAlias(String s) {
Pattern p = Pattern.compile("^[\u4E00-\u9FA50-9a-zA-Z_!@#$&*+=.|]+$");
Matcher m = p.matcher(s);
return m.matches();
}
// 取得AppKey
public static String getAppKey(Context context) {
Bundle metaData = null;
String appKey = null;
try {
ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
context.getPackageName(), PackageManager.GET_META_DATA);
if (null != ai)
metaData = ai.metaData;
if (null != metaData) {
appKey = metaData.getString(KEY_APP_KEY);
if ((null == appKey) || appKey.length() != 24) {
appKey = null;
}
}
} catch (NameNotFoundException e) {
}
return appKey;
}
// 取得版本号
public static String GetVersion(Context context) {
try {
PackageInfo manager = context.getPackageManager().getPackageInfo(
context.getPackageName(), 0);
return manager.versionName;
} catch (NameNotFoundException e) {
return "Unknown";
}
}
public static void showToast(final String toast, final Context context)
{
// new Thread(new Runnable() {
//
// @Override
// public void run() {
// Looper.prepare();
//// Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();
// Looper.loop();
// }
// }).start();
}
public static boolean isConnected(Context context) {
ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = conn.getActiveNetworkInfo();
return (info != null && info.isConnected());
}
public static String getImei(Context context, String imei) {
String ret = null;
try {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
ret = telephonyManager.getDeviceId();
} catch (Exception e) {
Logger.e(ExampleUtil.class.getSimpleName(), e.getMessage());
}
if (isReadableASCII(ret)){
return ret;
} else {
return imei;
}
}
private static boolean isReadableASCII(CharSequence string){
if (TextUtils.isEmpty(string)) return false;
try {
Pattern p = Pattern.compile("[\\x20-\\x7E]+");
return p.matcher(string).matches();
} catch (Throwable e){
return true;
}
}
public static String getDeviceId(Context context) {
return JPushInterface.getUdid(context);
}
}

View File

@@ -0,0 +1,263 @@
package com.uiui.sn.jpush;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
/**
* Created by efan on 2017/4/14.
*/
public final class LocalBroadcastManager {
private static final String TAG = "JIGUANG-Example";
private static final boolean DEBUG = false;
private final Context mAppContext;
private final HashMap<BroadcastReceiver, ArrayList<IntentFilter>> mReceivers = new HashMap<BroadcastReceiver, ArrayList<IntentFilter>>();
private final HashMap<String, ArrayList<ReceiverRecord>> mActions = new HashMap<String, ArrayList<ReceiverRecord>> ();
private final ArrayList<BroadcastRecord> mPendingBroadcasts = new ArrayList<BroadcastRecord>();
static final int MSG_EXEC_PENDING_BROADCASTS = 1;
private final Handler mHandler;
private static final Object mLock = new Object();
private static LocalBroadcastManager mInstance;
public static LocalBroadcastManager getInstance(Context context) {
Object var1 = mLock;
synchronized (mLock) {
if (mInstance == null) {
mInstance = new LocalBroadcastManager(context.getApplicationContext());
}
return mInstance;
}
}
private LocalBroadcastManager(Context context) {
this.mAppContext = context;
this.mHandler = new Handler(context.getMainLooper()) {
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
LocalBroadcastManager.this.executePendingBroadcasts();
break;
default:
super.handleMessage(msg);
}
}
};
}
public void registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
HashMap var3 = this.mReceivers;
synchronized (this.mReceivers) {
ReceiverRecord entry = new ReceiverRecord(filter, receiver);
ArrayList filters = (ArrayList) this.mReceivers.get(receiver);
if (filters == null) {
filters = new ArrayList(1);
this.mReceivers.put(receiver, filters);
}
filters.add(filter);
for (int i = 0; i < filter.countActions(); ++i) {
String action = filter.getAction(i);
ArrayList entries = (ArrayList) this.mActions.get(action);
if (entries == null) {
entries = new ArrayList(1);
this.mActions.put(action, entries);
}
entries.add(entry);
}
}
}
public void unregisterReceiver(BroadcastReceiver receiver) {
HashMap var2 = this.mReceivers;
synchronized (this.mReceivers) {
ArrayList filters = (ArrayList) this.mReceivers.remove(receiver);
if (filters != null) {
for (int i = 0; i < filters.size(); ++i) {
IntentFilter filter = (IntentFilter) filters.get(i);
for (int j = 0; j < filter.countActions(); ++j) {
String action = filter.getAction(j);
ArrayList receivers = (ArrayList) this.mActions.get(action);
if (receivers != null) {
for (int k = 0; k < receivers.size(); ++k) {
if (((ReceiverRecord) receivers.get(k)).receiver == receiver) {
receivers.remove(k);
--k;
}
}
if (receivers.size() <= 0) {
this.mActions.remove(action);
}
}
}
}
}
}
}
public boolean sendBroadcast(Intent intent) {
HashMap var2 = this.mReceivers;
synchronized (this.mReceivers) {
String action = intent.getAction();
String type = intent.resolveTypeIfNeeded(this.mAppContext.getContentResolver());
Uri data = intent.getData();
String scheme = intent.getScheme();
Set categories = intent.getCategories();
boolean debug = (intent.getFlags() & 8) != 0;
if (debug) {
Logger.v("LocalBroadcastManager", "Resolving type " + type + " scheme " + scheme + " of intent " + intent);
}
ArrayList entries = (ArrayList) this.mActions.get(intent.getAction());
if (entries != null) {
if (debug) {
Logger.v("LocalBroadcastManager", "Action list: " + entries);
}
ArrayList receivers = null;
int i;
for (i = 0; i < entries.size(); ++i) {
ReceiverRecord receiver = (ReceiverRecord) entries.get(i);
if (debug) {
Logger.v("LocalBroadcastManager", "Matching against filter " + receiver.filter);
}
if (receiver.broadcasting) {
if (debug) {
Logger.v("LocalBroadcastManager", " Filter\'s target already added");
}
} else {
int match = receiver.filter.match(action, type, scheme, data, categories, "LocalBroadcastManager");
if (match >= 0) {
if (debug) {
Logger.v("LocalBroadcastManager", " Filter matched! match=0x" + Integer.toHexString(match));
}
if (receivers == null) {
receivers = new ArrayList();
}
receivers.add(receiver);
receiver.broadcasting = true;
} else if (debug) {
String reason;
switch (match) {
case -4:
reason = "category";
break;
case -3:
reason = "action";
break;
case -2:
reason = "data";
break;
case -1:
reason = "type";
break;
default:
reason = "unknown reason";
}
Logger.v("LocalBroadcastManager", " Filter did not match: " + reason);
}
}
}
if (receivers != null) {
for (i = 0; i < receivers.size(); ++i) {
((ReceiverRecord) receivers.get(i)).broadcasting = false;
}
this.mPendingBroadcasts.add(new BroadcastRecord(intent, receivers));
if (!this.mHandler.hasMessages(1)) {
this.mHandler.sendEmptyMessage(1);
}
return true;
}
}
return false;
}
}
public void sendBroadcastSync(Intent intent) {
if (this.sendBroadcast(intent)) {
this.executePendingBroadcasts();
}
}
private void executePendingBroadcasts() {
while (true) {
BroadcastRecord[] brs = null;
HashMap i = this.mReceivers;
synchronized (this.mReceivers) {
int br = this.mPendingBroadcasts.size();
if (br <= 0) {
return;
}
brs = new BroadcastRecord[br];
this.mPendingBroadcasts.toArray(brs);
this.mPendingBroadcasts.clear();
}
for (int var6 = 0; var6 < brs.length; ++var6) {
BroadcastRecord var7 = brs[var6];
for (int j = 0; j < var7.receivers.size(); ++j) {
((ReceiverRecord) var7.receivers.get(j)).receiver.onReceive(this.mAppContext, var7.intent);
}
}
}
}
private static class BroadcastRecord {
final Intent intent;
final ArrayList<ReceiverRecord> receivers;
BroadcastRecord(Intent _intent, ArrayList<ReceiverRecord> _receivers) {
this.intent = _intent;
this.receivers = _receivers;
}
}
private static class ReceiverRecord {
final IntentFilter filter;
final BroadcastReceiver receiver;
boolean broadcasting;
ReceiverRecord(IntentFilter _filter, BroadcastReceiver _receiver) {
this.filter = _filter;
this.receiver = _receiver;
}
public String toString() {
StringBuilder builder = new StringBuilder(128);
builder.append("Receiver{");
builder.append(this.receiver);
builder.append(" filter=");
builder.append(this.filter);
builder.append("}");
return builder.toString();
}
}
}

View File

@@ -0,0 +1,40 @@
package com.uiui.sn.jpush;
import android.util.Log;
/**
* Created by efan on 2017/4/13.
*/
public class Logger {
//设为false关闭日志
private static final boolean LOG_ENABLE = true;
public static void i(String tag, String msg){
if (LOG_ENABLE){
Log.i(tag, msg);
}
}
public static void v(String tag, String msg){
if (LOG_ENABLE){
Log.v(tag, msg);
}
}
public static void d(String tag, String msg){
if (LOG_ENABLE){
Log.d(tag, msg);
}
}
public static void w(String tag, String msg){
if (LOG_ENABLE){
Log.w(tag, msg);
}
}
public static void e(String tag, String msg){
if (LOG_ENABLE){
Log.e(tag, msg);
}
}
}

View File

@@ -0,0 +1,46 @@
package com.uiui.sn.jpush;
import android.content.Context;
import com.uiui.sn.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);
BaseApplication.getInstance().onTagOperatorResult(jPushMessage);
super.onTagOperatorResult(context, 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);
BaseApplication.getInstance().onAliasOperatorResult(jPushMessage);
super.onAliasOperatorResult(context, 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

@@ -0,0 +1,7 @@
package com.uiui.sn.jpush;
import cn.jpush.android.service.JCommonService;
public class PushService extends JCommonService {
}

View File

@@ -0,0 +1,345 @@
package com.uiui.sn.jpush;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.util.SparseArray;
import com.uiui.sn.utils.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.debugShow("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.debugShow("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

@@ -0,0 +1,32 @@
package com.uiui.sn.jpush;
import android.app.Activity;
import android.content.Intent;
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
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("用户自定义打开的Activity");
Intent intent = getIntent();
if (null != intent) {
Bundle bundle = getIntent().getExtras();
String title = null;
String content = null;
if(bundle!=null){
title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
content = bundle.getString(JPushInterface.EXTRA_ALERT);
}
tv.setText("Title : " + title + " " + "Content : " + content);
}
addContentView(tv, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
}
}