version:
fix: update:删除极光推送
This commit is contained in:
@@ -197,9 +197,9 @@ dependencies {
|
|||||||
implementation 'com.google.zxing:core:3.3.0'
|
implementation 'com.google.zxing:core:3.3.0'
|
||||||
//fastjson
|
//fastjson
|
||||||
implementation 'com.alibaba:fastjson:1.2.76'
|
implementation 'com.alibaba:fastjson:1.2.76'
|
||||||
//极光推送
|
// //极光推送
|
||||||
implementation 'cn.jiguang.sdk:jpush:3.8.6' // 此处以JPush 3.4.1 版本为例。
|
// implementation 'cn.jiguang.sdk:jpush:3.8.6' // 此处以JPush 3.4.1 版本为例。
|
||||||
implementation 'cn.jiguang.sdk:jcore:2.6.0' // 此处以JCore 2.2.4 版本为例。
|
// implementation 'cn.jiguang.sdk:jcore:2.6.0' // 此处以JCore 2.2.4 版本为例。
|
||||||
//banner图
|
//banner图
|
||||||
implementation 'com.zhpan.library:bannerview:2.6.4'
|
implementation 'com.zhpan.library:bannerview:2.6.4'
|
||||||
//更换字体框架
|
//更换字体框架
|
||||||
|
|||||||
@@ -110,147 +110,6 @@
|
|||||||
<data android:scheme="package" />
|
<data android:scheme="package" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<provider
|
|
||||||
android:name="androidx.core.content.FileProvider"
|
|
||||||
android:authorities="com.uiui.appstore.fileprovider"
|
|
||||||
android:exported="false"
|
|
||||||
android:grantUriPermissions="true">
|
|
||||||
<meta-data
|
|
||||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
|
||||||
android:resource="@xml/file_paths" />
|
|
||||||
</provider>
|
|
||||||
<!-- 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" />
|
|
||||||
<!-- 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" />
|
|
||||||
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
<category android:name="com.uiui.appstore" />
|
|
||||||
</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>
|
|
||||||
<!-- since 3.0.9 Required SDK 核心功能 -->
|
|
||||||
<provider
|
|
||||||
android:name="cn.jpush.android.service.DataProvider"
|
|
||||||
android:authorities="com.uiui.appstore.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="com.uiui.appstore" />
|
|
||||||
</intent-filter>
|
|
||||||
</service>
|
|
||||||
<!-- since 3.1.0 Required SDK 核心功能 -->
|
|
||||||
<provider
|
|
||||||
android:name="cn.jpush.android.service.DownloadProvider"
|
|
||||||
android:authorities="com.uiui.appstore.DownloadProvider"
|
|
||||||
android:exported="true"
|
|
||||||
tools:replace="android:authorities" />
|
|
||||||
<!-- Required SDK核心功能 -->
|
|
||||||
<receiver
|
|
||||||
android:name="cn.jpush.android.service.PushReceiver"
|
|
||||||
android:enabled="true"
|
|
||||||
android:exported="false">
|
|
||||||
<intent-filter android:priority="1000">
|
|
||||||
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />
|
|
||||||
<!-- Required 显示通知栏 -->
|
|
||||||
<category android:name="com.uiui.appstore" />
|
|
||||||
</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" />
|
|
||||||
|
|
||||||
<data android:scheme="package" />
|
|
||||||
</intent-filter>
|
|
||||||
</receiver>
|
|
||||||
<!-- Required SDK核心功能 -->
|
|
||||||
<receiver
|
|
||||||
android:name="cn.jpush.android.service.AlarmReceiver"
|
|
||||||
android:exported="false" /> <!-- 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="com.uiui.appstore" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
<!-- Since JCore2.0.0 Required SDK核心功能 -->
|
|
||||||
<!-- 这个Service要继承JCommonService -->
|
|
||||||
<service
|
|
||||||
android:name="com.uiui.appstore.jpush.PushService"
|
|
||||||
android:process=":pushcore">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="cn.jiguang.user.service.action" />
|
|
||||||
</intent-filter>
|
|
||||||
</service>
|
|
||||||
<!-- User defined. For test only 用户自定义的广播接收器 -->
|
|
||||||
<receiver
|
|
||||||
android:name="com.uiui.appstore.jpush.MyReceiver"
|
|
||||||
android:enabled="true"
|
|
||||||
android:exported="false">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="cn.jpush.android.intent.REGISTRATION" />
|
|
||||||
<!-- Required 用户注册SDK的intent -->
|
|
||||||
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" />
|
|
||||||
<!-- Required 用户接收SDK消息的intent -->
|
|
||||||
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" />
|
|
||||||
<!-- Required 用户接收SDK通知栏信息的intent -->
|
|
||||||
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />
|
|
||||||
<!-- Required 用户打开自定义通知栏的intent -->
|
|
||||||
<action android:name="cn.jpush.android.intent.CONNECTION" />
|
|
||||||
<!-- 接收网络变化 连接/断开 since 1.6.3 -->
|
|
||||||
<category android:name="com.uiui.appstore" />
|
|
||||||
</intent-filter>
|
|
||||||
</receiver>
|
|
||||||
<!-- User defined. For test only 用户自定义接收消息器,3.0.7开始支持,目前新tag/alias接口设置结果会在该广播接收器对应的方法中回调 -->
|
|
||||||
<receiver android:name="com.uiui.appstore.jpush.MyJPushMessageReceiver">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
|
|
||||||
|
|
||||||
<category android:name="com.uiui.appstore" />
|
|
||||||
</intent-filter>
|
|
||||||
</receiver>
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name="com.uiui.appstore.receiver.InstallResultReceiver"
|
android:name="com.uiui.appstore.receiver.InstallResultReceiver"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
@@ -268,13 +127,19 @@
|
|||||||
<data android:scheme="package" />
|
<data android:scheme="package" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
<!-- Required . Enable it you can get statistics data with channel -->
|
<provider
|
||||||
<meta-data
|
android:name="androidx.core.content.FileProvider"
|
||||||
android:name="JPUSH_CHANNEL"
|
android:authorities="com.uiui.appstore.fileprovider"
|
||||||
android:value="developer-default" />
|
android:exported="false"
|
||||||
<meta-data
|
android:grantUriPermissions="true">
|
||||||
android:name="JPUSH_APPKEY"
|
<meta-data
|
||||||
android:value="${JPUSH_APPKEY}" />
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
android:resource="@xml/file_paths" />
|
||||||
|
</provider>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -1,11 +1,6 @@
|
|||||||
package com.uiui.appstore.activity;
|
package com.uiui.appstore.activity;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.content.pm.PackageInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
@@ -22,6 +17,10 @@ import androidx.fragment.app.Fragment;
|
|||||||
import androidx.fragment.app.FragmentPagerAdapter;
|
import androidx.fragment.app.FragmentPagerAdapter;
|
||||||
import androidx.viewpager.widget.ViewPager;
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
|
import com.flyco.tablayout.SlidingTabLayout;
|
||||||
|
import com.hjq.permissions.OnPermission;
|
||||||
|
import com.hjq.permissions.Permission;
|
||||||
|
import com.hjq.permissions.XXPermissions;
|
||||||
import com.uiui.appstore.R;
|
import com.uiui.appstore.R;
|
||||||
import com.uiui.appstore.base.BaseActivity;
|
import com.uiui.appstore.base.BaseActivity;
|
||||||
import com.uiui.appstore.bean.AppInfo;
|
import com.uiui.appstore.bean.AppInfo;
|
||||||
@@ -29,42 +28,24 @@ import com.uiui.appstore.bean.BaseResponse;
|
|||||||
import com.uiui.appstore.bean.UserInfo;
|
import com.uiui.appstore.bean.UserInfo;
|
||||||
import com.uiui.appstore.fragment.FeaturedFragment;
|
import com.uiui.appstore.fragment.FeaturedFragment;
|
||||||
import com.uiui.appstore.fragment.ManageFragment;
|
import com.uiui.appstore.fragment.ManageFragment;
|
||||||
import com.uiui.appstore.jpush.ExampleUtil;
|
|
||||||
import com.uiui.appstore.jpush.LocalBroadcastManager;
|
|
||||||
import com.uiui.appstore.jpush.TagAliasOperatorHelper;
|
|
||||||
import com.uiui.appstore.network.NetInterfaceManager;
|
import com.uiui.appstore.network.NetInterfaceManager;
|
||||||
import com.uiui.appstore.service.GuardService;
|
import com.uiui.appstore.service.GuardService;
|
||||||
import com.uiui.appstore.service.InitJpushServer;
|
import com.uiui.appstore.service.InitJpushServer;
|
||||||
import com.uiui.appstore.service.MyDownloadService;
|
import com.uiui.appstore.service.MyDownloadService;
|
||||||
import com.uiui.appstore.service.StepService;
|
import com.uiui.appstore.service.StepService;
|
||||||
import com.uiui.appstore.utils.LogUtils;
|
|
||||||
import com.uiui.appstore.utils.SPUtils;
|
import com.uiui.appstore.utils.SPUtils;
|
||||||
import com.uiui.appstore.utils.ToastUtil;
|
import com.uiui.appstore.utils.ToastUtil;
|
||||||
import com.uiui.appstore.utils.Utils;
|
import com.uiui.appstore.utils.Utils;
|
||||||
import com.flyco.tablayout.SlidingTabLayout;
|
|
||||||
import com.hjq.permissions.OnPermission;
|
|
||||||
import com.hjq.permissions.Permission;
|
|
||||||
import com.hjq.permissions.XXPermissions;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import cn.jpush.android.api.JPushInterface;
|
|
||||||
import io.reactivex.Observer;
|
import io.reactivex.Observer;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.Disposable;
|
import io.reactivex.disposables.Disposable;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
|
||||||
import static com.uiui.appstore.jpush.TagAliasOperatorHelper.ACTION_ADD;
|
|
||||||
import static com.uiui.appstore.jpush.TagAliasOperatorHelper.ACTION_CHECK;
|
|
||||||
import static com.uiui.appstore.jpush.TagAliasOperatorHelper.ACTION_CLEAN;
|
|
||||||
import static com.uiui.appstore.jpush.TagAliasOperatorHelper.ACTION_DELETE;
|
|
||||||
import static com.uiui.appstore.jpush.TagAliasOperatorHelper.ACTION_GET;
|
|
||||||
import static com.uiui.appstore.jpush.TagAliasOperatorHelper.ACTION_SET;
|
|
||||||
import static com.uiui.appstore.jpush.TagAliasOperatorHelper.TagAliasBean;
|
|
||||||
import static com.uiui.appstore.jpush.TagAliasOperatorHelper.sequence;
|
|
||||||
|
|
||||||
public class MainActivity extends BaseActivity {
|
public class MainActivity extends BaseActivity {
|
||||||
private static final String TAG = MainActivity.class.getSimpleName();
|
private static final String TAG = MainActivity.class.getSimpleName();
|
||||||
@@ -73,28 +54,11 @@ public class MainActivity extends BaseActivity {
|
|||||||
private SlidingTabLayout mSlidingTabLayout;
|
private SlidingTabLayout mSlidingTabLayout;
|
||||||
private ViewPager mViewPager;
|
private ViewPager mViewPager;
|
||||||
private long exitTime = 0;
|
private long exitTime = 0;
|
||||||
public static boolean isForeground = false;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
Log.e(TAG, "onCreate");
|
Log.e(TAG, "onCreate");
|
||||||
// requestPermission();
|
|
||||||
registerMessageReceiver(); // used for receive msg
|
|
||||||
String rid = JPushInterface.getRegistrationID(getApplicationContext());
|
|
||||||
if (!rid.isEmpty()) {
|
|
||||||
// ToastUtil.debugShow("RegId:" + rid);
|
|
||||||
LogUtils.e("jiguang", "RegId:" + rid);
|
|
||||||
onTagAliasAction(7);
|
|
||||||
} else {
|
|
||||||
// ToastUtil.show("Get registration fail, JPush init failed!");
|
|
||||||
// Toast.makeText(this, "Get registration fail, JPush init failed!", Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
// OKGO.getUserInfo(handler);
|
|
||||||
|
|
||||||
// PackageManager pm = getPackageManager();
|
|
||||||
// pm.setApplicationEnabledSetting("com.tencent.qqmusic", PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
|
|
||||||
startService(new Intent(MainActivity.this, MyDownloadService.class));
|
startService(new Intent(MainActivity.this, MyDownloadService.class));
|
||||||
starService();
|
starService();
|
||||||
}
|
}
|
||||||
@@ -134,7 +98,6 @@ public class MainActivity extends BaseActivity {
|
|||||||
Log.e(TAG, "onSaveInstanceState");
|
Log.e(TAG, "onSaveInstanceState");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initView() {
|
protected void initView() {
|
||||||
iv_appicon = findViewById(R.id.iv_appicon);
|
iv_appicon = findViewById(R.id.iv_appicon);
|
||||||
@@ -187,7 +150,6 @@ public class MainActivity extends BaseActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initData() {
|
protected void initData() {
|
||||||
// OKGO.getAllAppPackageName(handler);
|
|
||||||
getAllAppPackageName();
|
getAllAppPackageName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,132 +158,6 @@ public class MainActivity extends BaseActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化 JPush。如果已经初始化,但没有登录成功,则执行重新登录。
|
|
||||||
private void init() {
|
|
||||||
JPushInterface.init(getApplicationContext());
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
Log.e("jiguang", "sn:" + alias);
|
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String[] permission = new String[]{
|
private String[] permission = new String[]{
|
||||||
// Permission.SYSTEM_ALERT_WINDOW,
|
// Permission.SYSTEM_ALERT_WINDOW,
|
||||||
// Permission.CAMERA,
|
// Permission.CAMERA,
|
||||||
|
|||||||
@@ -5,20 +5,11 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.uiui.appstore.R;
|
|
||||||
import com.uiui.appstore.jpush.Logger;
|
|
||||||
import com.uiui.appstore.network.NetInterfaceManager;
|
|
||||||
import com.uiui.appstore.receiver.AppManagerReceiver;
|
|
||||||
import com.uiui.appstore.utils.JGYUtils;
|
|
||||||
import com.uiui.appstore.utils.LogUtils;
|
|
||||||
import com.uiui.appstore.utils.ToastUtil;
|
|
||||||
import com.arialyy.aria.core.Aria;
|
import com.arialyy.aria.core.Aria;
|
||||||
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
|
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
|
||||||
import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator;
|
import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator;
|
||||||
@@ -28,20 +19,18 @@ import com.scwang.smartrefresh.layout.api.RefreshHeader;
|
|||||||
import com.scwang.smartrefresh.layout.api.RefreshLayout;
|
import com.scwang.smartrefresh.layout.api.RefreshLayout;
|
||||||
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
|
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
|
||||||
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
|
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
|
||||||
|
import com.uiui.appstore.R;
|
||||||
import org.json.JSONException;
|
import com.uiui.appstore.network.NetInterfaceManager;
|
||||||
import org.json.JSONObject;
|
import com.uiui.appstore.receiver.AppManagerReceiver;
|
||||||
|
import com.uiui.appstore.utils.JGYUtils;
|
||||||
import cn.jpush.android.api.CustomMessage;
|
import com.uiui.appstore.utils.LogUtils;
|
||||||
import cn.jpush.android.api.JPushInterface;
|
import com.uiui.appstore.utils.ToastUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by asus on 2017/10/27.
|
* Created by asus on 2017/10/27.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class BaseApplication extends Application {
|
public class BaseApplication extends Application {
|
||||||
private static final String TAG = "JIGUANG-Example";
|
private static final String TAG = BaseApplication.class.getSimpleName();
|
||||||
|
|
||||||
|
|
||||||
private static BaseApplication app;
|
private static BaseApplication app;
|
||||||
|
|
||||||
@@ -73,14 +62,8 @@ public class BaseApplication extends Application {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
Logger.d(TAG, "[ExampleApplication] onCreate");
|
|
||||||
JPushInterface.setDebugMode(true); // 设置开启日志,发布时请关闭日志
|
|
||||||
JPushInterface.init(this); // 初始化 JPush
|
|
||||||
app = this;
|
app = this;
|
||||||
ToastUtil.init(this);
|
ToastUtil.init(this);
|
||||||
// OkGo.getInstance().init(this)
|
|
||||||
// .setRetryCount(10)//重试次数
|
|
||||||
// ;
|
|
||||||
JGYUtils.init(this);
|
JGYUtils.init(this);
|
||||||
Aria.init(this);
|
Aria.init(this);
|
||||||
Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
|
Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
|
||||||
@@ -89,8 +72,11 @@ public class BaseApplication extends Application {
|
|||||||
if (!isDebug(this)) {
|
if (!isDebug(this)) {
|
||||||
catchException();
|
catchException();
|
||||||
}
|
}
|
||||||
//全局字体初始化
|
registAppReceive();
|
||||||
|
NetInterfaceManager.init(this);
|
||||||
|
JGYUtils.hookWebView();
|
||||||
|
|
||||||
|
//全局字体初始化
|
||||||
// CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
|
// CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
|
||||||
// // .setDefaultFontPath("fonts/1234.ttf")
|
// // .setDefaultFontPath("fonts/1234.ttf")
|
||||||
// .setDefaultFontPath("fonts/SourceHanSansCN-ExtraLight.ttf")
|
// .setDefaultFontPath("fonts/SourceHanSansCN-ExtraLight.ttf")
|
||||||
@@ -98,9 +84,6 @@ public class BaseApplication extends Application {
|
|||||||
// .setFontAttrId(R.attr.fontPath)
|
// .setFontAttrId(R.attr.fontPath)
|
||||||
// .build()
|
// .build()
|
||||||
// );
|
// );
|
||||||
registAppReceive();
|
|
||||||
NetInterfaceManager.init(this);
|
|
||||||
JGYUtils.hookWebView();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private AppManagerReceiver mAppManagerReceiver;
|
private AppManagerReceiver mAppManagerReceiver;
|
||||||
@@ -116,7 +99,6 @@ public class BaseApplication extends Application {
|
|||||||
registerReceiver(mAppManagerReceiver, filter);
|
registerReceiver(mAppManagerReceiver, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isDebug(Context context) {
|
public boolean isDebug(Context context) {
|
||||||
boolean isDebug = context.getApplicationInfo() != null &&
|
boolean isDebug = context.getApplicationInfo() != null &&
|
||||||
(context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
|
(context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
|
||||||
@@ -151,284 +133,4 @@ public class BaseApplication extends Application {
|
|||||||
public Context getAppContext() {
|
public Context getAppContext() {
|
||||||
return getApplicationContext();
|
return getApplicationContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
//定义接收极光推送消息的类型
|
|
||||||
// 2.获取当前正在运行得应用和电量
|
|
||||||
// 3.数据线传输管控
|
|
||||||
// 4.TF卡管控
|
|
||||||
// 5.蓝牙管控
|
|
||||||
// 6.浏览器上网管控
|
|
||||||
// 7.应用联网管控
|
|
||||||
// 8.应用锁管控
|
|
||||||
// 9.强制安装应用
|
|
||||||
// 10.强制卸载应用
|
|
||||||
private static final String JIGUANG_GET_STARTTIME = "2";
|
|
||||||
private static final String JIGUANG_USB_STATE = "3";
|
|
||||||
private static final String JIGUANG_TFCARD_STATE = "4";
|
|
||||||
private static final String JIGUANG_BLUETOOTH_STATE = "5";
|
|
||||||
private static final String JIGUANG_BROWSER_URLPATH = "6";
|
|
||||||
private static final String JIGUANG_APP_NETWORKSTATE = "7";
|
|
||||||
private static final String JIGUANG_APP_LOCKEDSTATE = "8";
|
|
||||||
private static final String JIGUANG_FORCE_INSTALLAPK = "9";
|
|
||||||
private static final String JIGUANG_FORCE_UNINSTALLAPK = "10";
|
|
||||||
|
|
||||||
synchronized public void manageCustomMessage(CustomMessage customMessage) {
|
|
||||||
if (customMessage == null) {
|
|
||||||
LogUtils.e("jiguang", "customMessage is NULL");
|
|
||||||
} else {
|
|
||||||
String MESSAGE = customMessage.message;
|
|
||||||
//MESSAGE用作判断
|
|
||||||
String TITLE = customMessage.title;
|
|
||||||
String CONTENT_TYPE = customMessage.contentType;
|
|
||||||
String EXTRA = customMessage.extra;
|
|
||||||
LogUtils.e("EXTRA", EXTRA);
|
|
||||||
switch (MESSAGE) {
|
|
||||||
case JIGUANG_GET_STARTTIME:
|
|
||||||
// sendStartTime(EXTRA);
|
|
||||||
case JIGUANG_USB_STATE:
|
|
||||||
setUsbState(EXTRA);
|
|
||||||
break;
|
|
||||||
case JIGUANG_TFCARD_STATE:
|
|
||||||
setTfcardState(EXTRA);
|
|
||||||
break;
|
|
||||||
case JIGUANG_BLUETOOTH_STATE:
|
|
||||||
setBluetoothState(EXTRA);
|
|
||||||
break;
|
|
||||||
case JIGUANG_BROWSER_URLPATH:
|
|
||||||
setBrowserUrlpath(EXTRA);
|
|
||||||
break;
|
|
||||||
case JIGUANG_APP_NETWORKSTATE:
|
|
||||||
setAppNetworkstate(EXTRA);
|
|
||||||
break;
|
|
||||||
case JIGUANG_APP_LOCKEDSTATE:
|
|
||||||
setAppLockedstate(EXTRA);
|
|
||||||
break;
|
|
||||||
case JIGUANG_FORCE_INSTALLAPK:
|
|
||||||
// intallApk(EXTRA);
|
|
||||||
break;
|
|
||||||
case JIGUANG_FORCE_UNINSTALLAPK:
|
|
||||||
// unintallApk(EXTRA);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized private void defaults(String jsonArray) {
|
|
||||||
if (jsonArray.length() > 0) {
|
|
||||||
try {
|
|
||||||
JSONObject extra = new JSONObject(jsonArray);
|
|
||||||
String packageName = extra.getString("package");
|
|
||||||
int is_network = extra.getInt("is_network");
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
LogUtils.e("defaults", e.getMessage());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ToastUtil.debugShow("defaults jsonArray is NULL");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//USB数据功能管控
|
|
||||||
//仅充电:usb_charge
|
|
||||||
//MTP模式:usb_mtp
|
|
||||||
//Midi模式:usb_midi
|
|
||||||
synchronized private void setUsbState(String jsonArray) {
|
|
||||||
if (jsonArray.length() > 0) {
|
|
||||||
try {
|
|
||||||
JSONObject extra = new JSONObject(jsonArray);
|
|
||||||
int is_dataline = extra.getInt("is_dataline");
|
|
||||||
if (is_dataline == 1) {
|
|
||||||
boolean qch_usb_choose = Settings.System.putString(getContentResolver(), "qch_usb_choose", "usb_charge");
|
|
||||||
LogUtils.e("setUsbState:", Settings.System.getString(getContentResolver(), "qch_usb_choose"));
|
|
||||||
} else {
|
|
||||||
boolean qch_usb_choose = Settings.System.putString(getContentResolver(), "qch_usb_choose", "usb_mtp");
|
|
||||||
LogUtils.e("setUsbState:", Settings.System.getString(getContentResolver(), "qch_usb_choose"));
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
LogUtils.e("setUsbState", e.getMessage());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ToastUtil.debugShow("setUsbState jsonArray is NULL");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized private void setTfcardState(String jsonArray) {
|
|
||||||
if (jsonArray.length() > 0) {
|
|
||||||
try {
|
|
||||||
JSONObject extra = new JSONObject(jsonArray);
|
|
||||||
int is_tf = extra.getInt("is_tf");
|
|
||||||
boolean qch_sdcard_forbid_on = Settings.System.putInt(getContentResolver(), "qch_sdcard_forbid_on", is_tf);
|
|
||||||
if (qch_sdcard_forbid_on) {
|
|
||||||
LogUtils.e("setTfcardState:", Settings.System.getString(getContentResolver(), "qch_sdcard_forbid_on"));
|
|
||||||
} else {
|
|
||||||
ToastUtil.debugShow("setTfcardState failed,state:" + is_tf);
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
LogUtils.e("setTfcardState", e.getMessage());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ToastUtil.debugShow("setTfcardState jsonArray is NULL");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized private void setBluetoothState(String jsonArray) {
|
|
||||||
if (jsonArray.length() > 0) {
|
|
||||||
try {
|
|
||||||
JSONObject extra = new JSONObject(jsonArray);
|
|
||||||
int is_bluetooth = extra.getInt("is_bluetooth");
|
|
||||||
boolean qch_bt_forbid_on = Settings.System.putInt(getContentResolver(), "qch_bt_forbid_on", is_bluetooth);
|
|
||||||
if (qch_bt_forbid_on) {
|
|
||||||
LogUtils.e("setBluetoothState:", Settings.System.getString(getContentResolver(), "qch_bt_forbid_on"));
|
|
||||||
} else {
|
|
||||||
ToastUtil.debugShow("setBluetoothState failed,state:" + is_bluetooth);
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
LogUtils.e("setBluetoothState", e.getMessage());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ToastUtil.debugShow("setBluetoothState jsonArray is NULL");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized private void setBrowserUrlpath(String jsonArray) {
|
|
||||||
if (jsonArray.length() > 0) {
|
|
||||||
try {
|
|
||||||
JSONObject extra = new JSONObject(jsonArray);
|
|
||||||
String browser = extra.getString("browser");
|
|
||||||
boolean setBrowserUrlpath = Settings.System.putString(getContentResolver(), "DeselectBrowserArray", browser);
|
|
||||||
LogUtils.e("setBrowserUrlpath:", String.valueOf(setBrowserUrlpath));
|
|
||||||
if (setBrowserUrlpath) {
|
|
||||||
LogUtils.e("getBrowserUrlpath:", Settings.System.getString(getContentResolver(), "DeselectBrowserArray"));
|
|
||||||
} else {
|
|
||||||
ToastUtil.debugShow("setBrowserUrlpath failed,url:" + browser);
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
LogUtils.e("setBrowserUrlpath", e.getMessage());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
boolean setBrowserUrlpath = Settings.System.putString(getContentResolver(), "DeselectBrowserArray", "invalid");
|
|
||||||
|
|
||||||
ToastUtil.debugShow("setBrowserUrlpath jsonArray is NULL,set default: " + setBrowserUrlpath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized private void setAppNetworkstate(String jsonArray) {
|
|
||||||
if (jsonArray.length() > 0) {
|
|
||||||
try {
|
|
||||||
JSONObject extra = new JSONObject(jsonArray);
|
|
||||||
String package0 = extra.getString("package0");
|
|
||||||
String package1 = extra.getString("package1");
|
|
||||||
if (package0.length() != 0) {
|
|
||||||
boolean qch_jgy_network_disallow = Settings.System.putString(getContentResolver(), "qch_jgy_network_allow", package0);
|
|
||||||
LogUtils.e("fht", "setAppNetworkstate::" + qch_jgy_network_disallow + ":" + Settings.System.getString(getContentResolver(), "qch_jgy_network_allow"));
|
|
||||||
} else {
|
|
||||||
boolean qch_jgy_network_disallow = Settings.System.putString(getContentResolver(), "qch_jgy_network_allow", "invalid");
|
|
||||||
LogUtils.e("fht", "setAppNetworkstate::" + qch_jgy_network_disallow + ":" + Settings.System.getString(getContentResolver(), "qch_jgy_network_allow"));
|
|
||||||
}
|
|
||||||
if (package1.length() != 0) {
|
|
||||||
boolean qch_jgy_network_disallow = Settings.System.putString(getContentResolver(), "qch_jgy_network_disallow", package1);
|
|
||||||
LogUtils.e("fht", "setAppNetworkstate::" + qch_jgy_network_disallow + ":" + Settings.System.getString(getContentResolver(), "qch_jgy_network_disallow"));
|
|
||||||
} else {
|
|
||||||
boolean qch_jgy_network_disallow = Settings.System.putString(getContentResolver(), "qch_jgy_network_disallow", "invalid");
|
|
||||||
LogUtils.e("fht", "setAppNetworkstate::" + qch_jgy_network_disallow + ":" + Settings.System.getString(getContentResolver(), "qch_jgy_network_disallow"));
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
LogUtils.e("setAppNetworkstate", e.getMessage());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ToastUtil.debugShow("setAppNetworkstate jsonArray is NULL");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized private void setAppLockedstate(String jsonArray) {
|
|
||||||
if (jsonArray.length() > 0) {
|
|
||||||
try {
|
|
||||||
JSONObject extra = new JSONObject(jsonArray);
|
|
||||||
String packageName = extra.getString("package");
|
|
||||||
int is_lock = extra.getInt("is_lock");
|
|
||||||
ToastUtil.debugShow("收到应用锁管控消息:包名" + packageName + "is_lock_state:" + is_lock);
|
|
||||||
PackageManager pm = getPackageManager();
|
|
||||||
//后台为0可能传过来null
|
|
||||||
if (is_lock == 1) {
|
|
||||||
pm.setApplicationEnabledSetting(packageName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
|
|
||||||
} else {
|
|
||||||
pm.setApplicationEnabledSetting(packageName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
LogUtils.e("setAppLockedstate", e.getMessage());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ToastUtil.debugShow("setAppLockedstate jsonArray is NULL");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//静默安装应用,使用okgo,断网会出现问题,等待修改使用aria
|
|
||||||
// synchronized private void intallApk(String jsondata) {
|
|
||||||
// try {
|
|
||||||
// JSONObject extra = new JSONObject(jsondata);
|
|
||||||
// final String packages = extra.getString("package");
|
|
||||||
// ToastUtil.debugShow("收到应用安装消息:包名" + packages);
|
|
||||||
// String url = extra.getString("url");
|
|
||||||
// OkGo.<File>get(url)
|
|
||||||
// .execute(new FileCallback() {
|
|
||||||
// @Override
|
|
||||||
// public void onSuccess(final Response<File> response) {
|
|
||||||
//// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
|
|
||||||
// new Thread(new Runnable() {
|
|
||||||
// @Override
|
|
||||||
// public void run() {
|
|
||||||
// ApkUtils.installApp(app.getAppContext(), response.body().getAbsolutePath());
|
|
||||||
// }
|
|
||||||
// }).start();
|
|
||||||
// LogUtils.e("onSuccess", "download file successful,now installing");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void onError(Response<File> response) {
|
|
||||||
// super.onError(response);
|
|
||||||
// LogUtils.e("manageCustomMessage", "File download Failure");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void downloadProgress(Progress progress) {
|
|
||||||
// super.downloadProgress(progress);
|
|
||||||
// LogUtils.e("downloadProgress", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// } catch (JSONException e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// LogUtils.e("intallApk", e.getMessage());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// synchronized private void unintallApk(String json) {
|
|
||||||
// String sn_id = (String) SPUtils.get(getApplicationContext(), "sn_id", "-1");
|
|
||||||
// try {
|
|
||||||
// JSONObject object = new JSONObject(json);
|
|
||||||
// String packageName = object.getString("package");
|
|
||||||
// ToastUtil.debugShow("收到应用卸载消息:包名" + packageName);
|
|
||||||
// if (!packageName.equals("") && !packageName.equals(getApplicationContext().getPackageName())) {
|
|
||||||
// if (!ApkUtils.isAvailable(getApplicationContext(), packageName)) {
|
|
||||||
// OKGO.setAppuninstallInfo(sn_id, packageName);
|
|
||||||
// } else {
|
|
||||||
// ApkUtils.deleteApkInSilence(packageName);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } catch (JSONException e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// LogUtils.e("unintallApk", e.getMessage());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,132 +0,0 @@
|
|||||||
package com.uiui.appstore.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.os.Looper;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package com.uiui.appstore.jpush.Invalid;
|
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
|
|
||||||
import com.uiui.appstore.jpush.Logger;
|
|
||||||
|
|
||||||
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(true); // 设置开启日志,发布时请关闭日志
|
|
||||||
JPushInterface.init(this); // 初始化 JPush
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,163 +0,0 @@
|
|||||||
package com.uiui.appstore.jpush.Invalid;
|
|
||||||
|
|
||||||
|
|
||||||
//public class MainActivity extends InstrumentedActivity implements OnClickListener{
|
|
||||||
//
|
|
||||||
// private Button mInit;
|
|
||||||
// private Button mSetting;
|
|
||||||
// private Button mStopPush;
|
|
||||||
// private Button mResumePush;
|
|
||||||
// private Button mGetRid;
|
|
||||||
// private TextView mRegId;
|
|
||||||
// private EditText msgText;
|
|
||||||
//
|
|
||||||
// public static boolean isForeground = false;
|
|
||||||
// @Override
|
|
||||||
// public void onCreate(Bundle savedInstanceState) {
|
|
||||||
// super.onCreate(savedInstanceState);
|
|
||||||
// setContentView(R.layout.main);
|
|
||||||
// initView();
|
|
||||||
// registerMessageReceiver(); // used for receive msg
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void initView(){
|
|
||||||
// TextView mImei = (TextView) findViewById(R.id.tv_imei);
|
|
||||||
// String udid = ExampleUtil.getImei(getApplicationContext(), "");
|
|
||||||
// if (null != udid) mImei.setText("IMEI: " + udid);
|
|
||||||
//
|
|
||||||
// TextView mAppKey = (TextView) findViewById(R.id.tv_appkey);
|
|
||||||
// String appKey = ExampleUtil.getAppKey(getApplicationContext());
|
|
||||||
// if (null == appKey) appKey = "AppKey异常";
|
|
||||||
// mAppKey.setText("AppKey: " + appKey);
|
|
||||||
//
|
|
||||||
// mRegId = (TextView) findViewById(R.id.tv_regId);
|
|
||||||
// mRegId.setText("RegId:");
|
|
||||||
//
|
|
||||||
// String packageName = getPackageName();
|
|
||||||
// TextView mPackage = (TextView) findViewById(R.id.tv_package);
|
|
||||||
// mPackage.setText("PackageName: " + packageName);
|
|
||||||
//
|
|
||||||
// String deviceId = ExampleUtil.getDeviceId(getApplicationContext());
|
|
||||||
// TextView mDeviceId = (TextView) findViewById(R.id.tv_device_id);
|
|
||||||
// mDeviceId.setText("deviceId:" + deviceId);
|
|
||||||
//
|
|
||||||
// String versionName = ExampleUtil.GetVersion(getApplicationContext());
|
|
||||||
// TextView mVersion = (TextView) findViewById(R.id.tv_version);
|
|
||||||
// mVersion.setText("Version: " + versionName);
|
|
||||||
//
|
|
||||||
// mInit = (Button)findViewById(R.id.init);
|
|
||||||
// mInit.setOnClickListener(this);
|
|
||||||
//
|
|
||||||
// mStopPush = (Button)findViewById(R.id.stopPush);
|
|
||||||
// mStopPush.setOnClickListener(this);
|
|
||||||
//
|
|
||||||
// mResumePush = (Button)findViewById(R.id.resumePush);
|
|
||||||
// mResumePush.setOnClickListener(this);
|
|
||||||
//
|
|
||||||
// mGetRid = (Button) findViewById(R.id.getRegistrationId);
|
|
||||||
// mGetRid.setOnClickListener(this);
|
|
||||||
//
|
|
||||||
// mSetting = (Button)findViewById(R.id.setting);
|
|
||||||
// mSetting.setOnClickListener(this);
|
|
||||||
//
|
|
||||||
// msgText = (EditText)findViewById(R.id.msg_rec);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void onClick(View v) {
|
|
||||||
// switch (v.getId()) {
|
|
||||||
// case R.id.init:
|
|
||||||
// init();
|
|
||||||
// break;
|
|
||||||
// case R.id.setting:
|
|
||||||
// Intent intent = new Intent(MainActivity.this, PushSetActivity.class);
|
|
||||||
// startActivity(intent);
|
|
||||||
// break;
|
|
||||||
// case R.id.stopPush:
|
|
||||||
// JPushInterface.stopPush(getApplicationContext());
|
|
||||||
// break;
|
|
||||||
// case R.id.resumePush:
|
|
||||||
// JPushInterface.resumePush(getApplicationContext());
|
|
||||||
// break;
|
|
||||||
// case R.id.getRegistrationId:
|
|
||||||
// String rid = JPushInterface.getRegistrationID(getApplicationContext());
|
|
||||||
// if (!rid.isEmpty()) {
|
|
||||||
// mRegId.setText("RegId:" + rid);
|
|
||||||
// } else {
|
|
||||||
// Toast.makeText(this, "Get registration fail, JPush init failed!", Toast.LENGTH_SHORT).show();
|
|
||||||
// }
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // 初始化 JPush。如果已经初始化,但没有登录成功,则执行重新登录。
|
|
||||||
// private void init(){
|
|
||||||
// JPushInterface.init(getApplicationContext());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// protected void onResume() {
|
|
||||||
// isForeground = true;
|
|
||||||
// super.onResume();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// protected void onPause() {
|
|
||||||
// isForeground = false;
|
|
||||||
// super.onPause();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// protected void onDestroy() {
|
|
||||||
// LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
|
|
||||||
// super.onDestroy();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// //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 void setCostomMsg(String msg){
|
|
||||||
// if (null != msgText) {
|
|
||||||
// msgText.setText(msg);
|
|
||||||
// msgText.setVisibility(View.VISIBLE);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
//}
|
|
||||||
@@ -1,265 +0,0 @@
|
|||||||
package com.uiui.appstore.jpush.Invalid;
|
|
||||||
|
|
||||||
//public class PushSetActivity extends InstrumentedActivity implements OnClickListener {
|
|
||||||
// private static final String TAG = "JIGUANG-Example";
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void onCreate(Bundle icicle) {
|
|
||||||
// super.onCreate(icicle);
|
|
||||||
// setContentView(R.layout.push_set_dialog);
|
|
||||||
// initListener();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void initListener() {
|
|
||||||
// //增加tag
|
|
||||||
// findViewById(R.id.bt_addtag).setOnClickListener(this);
|
|
||||||
// //设置tag
|
|
||||||
// findViewById(R.id.bt_settag).setOnClickListener(this);
|
|
||||||
// //删除tag
|
|
||||||
// findViewById(R.id.bt_deletetag).setOnClickListener(this);
|
|
||||||
// //获取所有tag
|
|
||||||
// findViewById(R.id.bt_getalltag).setOnClickListener(this);
|
|
||||||
// //清除所有tag
|
|
||||||
// findViewById(R.id.bt_cleantag).setOnClickListener(this);
|
|
||||||
// //查询tag绑定状态
|
|
||||||
// findViewById(R.id.bt_checktag).setOnClickListener(this);
|
|
||||||
//
|
|
||||||
// //设置alias
|
|
||||||
// findViewById(R.id.bt_setalias).setOnClickListener(this);
|
|
||||||
// //获取alias
|
|
||||||
// findViewById(R.id.bt_getalias).setOnClickListener(this);
|
|
||||||
// //删除alias
|
|
||||||
// findViewById(R.id.bt_deletealias).setOnClickListener(this);
|
|
||||||
// //设置手机号码
|
|
||||||
// findViewById(R.id.bt_setmobileNumber).setOnClickListener(this);
|
|
||||||
// //StyleAddActions
|
|
||||||
// findViewById(R.id.setStyle0).setOnClickListener(this);
|
|
||||||
// //StyleBasic
|
|
||||||
// findViewById(R.id.setStyle1).setOnClickListener(this);
|
|
||||||
// //StyleCustom
|
|
||||||
// findViewById(R.id.setStyle2).setOnClickListener(this);
|
|
||||||
// //SetPushTime
|
|
||||||
// findViewById(R.id.bu_setTime).setOnClickListener(this);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void onClick(View view) {
|
|
||||||
// switch (view.getId()) {
|
|
||||||
// case R.id.setStyle0:
|
|
||||||
// setAddActionsStyle();
|
|
||||||
// break;
|
|
||||||
// case R.id.setStyle1:
|
|
||||||
// setStyleBasic();
|
|
||||||
// break;
|
|
||||||
// case R.id.setStyle2:
|
|
||||||
// setStyleCustom();
|
|
||||||
// break;
|
|
||||||
// case R.id.bu_setTime:
|
|
||||||
// Intent intent = new Intent(PushSetActivity.this, SettingActivity.class);
|
|
||||||
// startActivity(intent);
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// onTagAliasAction(view);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// TagAliasCallback tagAlias = new TagAliasCallback() {
|
|
||||||
// @Override
|
|
||||||
// public void gotResult(int responseCode, String alias, Set<String> tags) {
|
|
||||||
// Log.e(TAG,"responseCode:"+responseCode+",alias:"+alias+",tags:"+tags);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 设置通知提示方式 - 基础属性
|
|
||||||
// */
|
|
||||||
// private void setStyleBasic() {
|
|
||||||
// BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(PushSetActivity.this);
|
|
||||||
// builder.statusBarDrawable = R.drawable.ic_launcher;
|
|
||||||
// builder.notificationFlags = Notification.FLAG_AUTO_CANCEL; //设置为点击后自动消失
|
|
||||||
// builder.notificationDefaults = Notification.DEFAULT_SOUND; //设置为铃声( Notification.DEFAULT_SOUND)或者震动( Notification.DEFAULT_VIBRATE)
|
|
||||||
// JPushInterface.setPushNotificationBuilder(1, builder);
|
|
||||||
// Toast.makeText(PushSetActivity.this, "Basic Builder - 1", Toast.LENGTH_SHORT).show();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 设置通知栏样式 - 定义通知栏Layout
|
|
||||||
// */
|
|
||||||
// private void setStyleCustom() {
|
|
||||||
// CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(PushSetActivity.this, R.layout.customer_notitfication_layout, R.id.icon, R.id.title, R.id.text);
|
|
||||||
// builder.layoutIconDrawable = R.drawable.ic_launcher;
|
|
||||||
// builder.developerArg0 = "developerArg2";
|
|
||||||
// JPushInterface.setPushNotificationBuilder(2, builder);
|
|
||||||
// Toast.makeText(PushSetActivity.this, "Custom Builder - 2", Toast.LENGTH_SHORT).show();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
||||||
// if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
||||||
// finish();
|
|
||||||
// }
|
|
||||||
// return super.onKeyDown(keyCode, event);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void setAddActionsStyle() {
|
|
||||||
// MultiActionsNotificationBuilder builder = new MultiActionsNotificationBuilder(PushSetActivity.this);
|
|
||||||
// builder.addJPushAction(R.drawable.jpush_ic_richpush_actionbar_back, "first", "my_extra1");
|
|
||||||
// builder.addJPushAction(R.drawable.jpush_ic_richpush_actionbar_back, "second", "my_extra2");
|
|
||||||
// builder.addJPushAction(R.drawable.jpush_ic_richpush_actionbar_back, "third", "my_extra3");
|
|
||||||
// JPushInterface.setPushNotificationBuilder(10, builder);
|
|
||||||
//
|
|
||||||
// Toast.makeText(PushSetActivity.this, "AddActions Builder - 10", Toast.LENGTH_SHORT).show();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// /**===========================================================================**/
|
|
||||||
// /**=========================TAG/ALIAS 相关=====================================**/
|
|
||||||
// /**===========================================================================**/
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 处理tag/alias相关操作的点击
|
|
||||||
// * */
|
|
||||||
// public void onTagAliasAction(View view) {
|
|
||||||
// Set<String> tags = null;
|
|
||||||
// String alias = null;
|
|
||||||
// int action = -1;
|
|
||||||
// boolean isAliasAction = false;
|
|
||||||
// switch (view.getId()){
|
|
||||||
// //设置手机号码:
|
|
||||||
// case R.id.bt_setmobileNumber:
|
|
||||||
// handleSetMobileNumber();
|
|
||||||
// return;
|
|
||||||
// //增加tag
|
|
||||||
// case R.id.bt_addtag:
|
|
||||||
// tags = getInPutTags();
|
|
||||||
// if(tags == null){
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// action = ACTION_ADD;
|
|
||||||
// break;
|
|
||||||
// //设置tag
|
|
||||||
// case R.id.bt_settag:
|
|
||||||
// tags = getInPutTags();
|
|
||||||
// if(tags == null){
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// action = ACTION_SET;
|
|
||||||
// break;
|
|
||||||
// //删除tag
|
|
||||||
// case R.id.bt_deletetag:
|
|
||||||
// tags = getInPutTags();
|
|
||||||
// if(tags == null){
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// action = ACTION_DELETE;
|
|
||||||
// break;
|
|
||||||
// //获取所有tag
|
|
||||||
// case R.id.bt_getalltag:
|
|
||||||
// action = ACTION_GET;
|
|
||||||
// break;
|
|
||||||
// //清除所有tag
|
|
||||||
// case R.id.bt_cleantag:
|
|
||||||
// action = ACTION_CLEAN;
|
|
||||||
// break;
|
|
||||||
// case R.id.bt_checktag:
|
|
||||||
// tags = getInPutTags();
|
|
||||||
// if(tags == null){
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// action = ACTION_CHECK;
|
|
||||||
// break;
|
|
||||||
// //设置alias
|
|
||||||
// case R.id.bt_setalias:
|
|
||||||
// alias = getInPutAlias();
|
|
||||||
// if(TextUtils.isEmpty(alias)){
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// isAliasAction = true;
|
|
||||||
// action = ACTION_SET;
|
|
||||||
// break;
|
|
||||||
// //获取alias
|
|
||||||
// case R.id.bt_getalias:
|
|
||||||
// isAliasAction = true;
|
|
||||||
// action = ACTION_GET;
|
|
||||||
// break;
|
|
||||||
// //删除alias
|
|
||||||
// case R.id.bt_deletealias:
|
|
||||||
// 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);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void handleSetMobileNumber(){
|
|
||||||
// EditText mobileEdit = (EditText) findViewById(R.id.et_mobilenumber);
|
|
||||||
// String mobileNumber = mobileEdit.getText().toString().trim();
|
|
||||||
// if (TextUtils.isEmpty(mobileNumber)) {
|
|
||||||
// Toast.makeText(getApplicationContext(), R.string.mobilenumber_empty_guide, Toast.LENGTH_SHORT).show();
|
|
||||||
// }
|
|
||||||
// if (!ExampleUtil.isValidMobileNumber(mobileNumber)) {
|
|
||||||
// Toast.makeText(getApplicationContext(), R.string.error_tag_gs_empty, Toast.LENGTH_SHORT).show();
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// sequence++;
|
|
||||||
// TagAliasOperatorHelper.getInstance().handleAction(getApplicationContext(),sequence,mobileNumber);
|
|
||||||
// }
|
|
||||||
// /**
|
|
||||||
// * 获取输入的alias
|
|
||||||
// * */
|
|
||||||
// private String getInPutAlias(){
|
|
||||||
// EditText aliasEdit = (EditText) findViewById(R.id.et_alias);
|
|
||||||
// String alias = aliasEdit.getText().toString().trim();
|
|
||||||
// if (TextUtils.isEmpty(alias)) {
|
|
||||||
// Toast.makeText(getApplicationContext(), R.string.error_alias_empty, Toast.LENGTH_SHORT).show();
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
// if (!ExampleUtil.isValidTagAndAlias(alias)) {
|
|
||||||
// Toast.makeText(getApplicationContext(), R.string.error_tag_gs_empty, Toast.LENGTH_SHORT).show();
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
// return alias;
|
|
||||||
// }
|
|
||||||
// /**
|
|
||||||
// * 获取输入的tags
|
|
||||||
// * */
|
|
||||||
// private Set<String> getInPutTags(){
|
|
||||||
// EditText tagEdit = (EditText) findViewById(R.id.et_tag);
|
|
||||||
// String tag = tagEdit.getText().toString().trim();
|
|
||||||
// // 检查 tag 的有效性
|
|
||||||
// if (TextUtils.isEmpty(tag)) {
|
|
||||||
// Toast.makeText(getApplicationContext(), R.string.error_tag_empty, Toast.LENGTH_SHORT).show();
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // ","隔开的多个 转换成 Set
|
|
||||||
// String[] sArray = tag.split(",");
|
|
||||||
// Set<String> tagSet = new LinkedHashSet<String>();
|
|
||||||
// for (String sTagItme : sArray) {
|
|
||||||
// if (!ExampleUtil.isValidTagAndAlias(sTagItme)) {
|
|
||||||
// Toast.makeText(getApplicationContext(), R.string.error_tag_gs_empty, Toast.LENGTH_SHORT).show();
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
// tagSet.add(sTagItme);
|
|
||||||
// }
|
|
||||||
// if(tagSet.isEmpty()){
|
|
||||||
// Toast.makeText(getApplicationContext(), R.string.error_tag_empty, Toast.LENGTH_SHORT).show();
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
// return tagSet;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
@@ -1,177 +0,0 @@
|
|||||||
package com.uiui.appstore.jpush.Invalid;
|
|
||||||
|
|
||||||
//public class SettingActivity extends InstrumentedActivity implements OnClickListener {
|
|
||||||
// TimePicker startTime;
|
|
||||||
// TimePicker endTime;
|
|
||||||
// CheckBox mMonday ;
|
|
||||||
// CheckBox mTuesday ;
|
|
||||||
// CheckBox mWednesday;
|
|
||||||
// CheckBox mThursday;
|
|
||||||
// CheckBox mFriday ;
|
|
||||||
// CheckBox mSaturday;
|
|
||||||
// CheckBox mSunday ;
|
|
||||||
// Button mSetTime;
|
|
||||||
// SharedPreferences mSettings;
|
|
||||||
// Editor mEditor;
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void onCreate(Bundle icicle) {
|
|
||||||
// super.onCreate(icicle);
|
|
||||||
// setContentView(R.layout.set_push_time);
|
|
||||||
// init();
|
|
||||||
// initListener();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void onStart() {
|
|
||||||
// super.onStart();
|
|
||||||
// initData();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void init(){
|
|
||||||
// startTime = (TimePicker) findViewById(R.id.start_time);
|
|
||||||
// endTime = (TimePicker) findViewById(R.id.end_time);
|
|
||||||
// startTime.setIs24HourView(DateFormat.is24HourFormat(this));
|
|
||||||
// endTime.setIs24HourView(DateFormat.is24HourFormat(this));
|
|
||||||
// mSetTime = (Button)findViewById(R.id.bu_setTime);
|
|
||||||
// mMonday = (CheckBox)findViewById(R.id.cb_monday);
|
|
||||||
// mTuesday = (CheckBox)findViewById(R.id.cb_tuesday);
|
|
||||||
// mWednesday = (CheckBox)findViewById(R.id.cb_wednesday);
|
|
||||||
// mThursday = (CheckBox)findViewById(R.id.cb_thursday);
|
|
||||||
// mFriday = (CheckBox)findViewById(R.id.cb_friday);
|
|
||||||
// mSaturday = (CheckBox)findViewById(R.id.cb_saturday);
|
|
||||||
// mSunday = (CheckBox)findViewById(R.id.cb_sunday);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void initListener(){
|
|
||||||
// mSetTime.setOnClickListener(this);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void initData(){
|
|
||||||
// mSettings = getSharedPreferences(ExampleUtil.PREFS_NAME, MODE_PRIVATE);
|
|
||||||
// String days = mSettings.getString(ExampleUtil.PREFS_DAYS, "");
|
|
||||||
// if (!TextUtils.isEmpty(days)) {
|
|
||||||
// initAllWeek(false);
|
|
||||||
// String[] sArray = days.split(",");
|
|
||||||
// for (String day : sArray) {
|
|
||||||
// setWeek(day);
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// initAllWeek(true);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// int startTimeStr = mSettings.getInt(ExampleUtil.PREFS_START_TIME, 0);
|
|
||||||
// startTime.setCurrentHour(startTimeStr);
|
|
||||||
// int endTimeStr = mSettings.getInt(ExampleUtil.PREFS_END_TIME, 23);
|
|
||||||
// endTime.setCurrentHour(endTimeStr);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void onClick(View v) {
|
|
||||||
// switch (v.getId()) {
|
|
||||||
// case R.id.bu_setTime:
|
|
||||||
// v.requestFocus();
|
|
||||||
// v.requestFocusFromTouch();
|
|
||||||
// setPushTime();
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// *设置允许接收通知时间
|
|
||||||
// */
|
|
||||||
// private void setPushTime(){
|
|
||||||
// int startime = startTime.getCurrentHour();
|
|
||||||
// int endtime = endTime.getCurrentHour();
|
|
||||||
// if (startime > endtime) {
|
|
||||||
// Toast.makeText(SettingActivity.this, "开始时间不能大于结束时间", Toast.LENGTH_SHORT).show();
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// StringBuffer daysSB = new StringBuffer();
|
|
||||||
// Set<Integer> days = new HashSet<Integer>();
|
|
||||||
// if (mSunday.isChecked()) {
|
|
||||||
// days.add(0);
|
|
||||||
// daysSB.append("0,");
|
|
||||||
// }
|
|
||||||
// if (mMonday.isChecked()) {
|
|
||||||
// days.add(1);
|
|
||||||
// daysSB.append("1,");
|
|
||||||
// }
|
|
||||||
// if (mTuesday.isChecked()) {
|
|
||||||
// days.add(2);
|
|
||||||
// daysSB.append("2,");
|
|
||||||
// }
|
|
||||||
// if (mWednesday.isChecked()) {
|
|
||||||
// days.add(3);
|
|
||||||
// daysSB.append("3,");
|
|
||||||
// }
|
|
||||||
// if (mThursday.isChecked()) {
|
|
||||||
// days.add(4);
|
|
||||||
// daysSB.append("4,");
|
|
||||||
// }
|
|
||||||
// if (mFriday.isChecked()) {
|
|
||||||
// days.add(5);
|
|
||||||
// daysSB.append("5,");
|
|
||||||
// }
|
|
||||||
// if (mSaturday.isChecked()) {
|
|
||||||
// days.add(6);
|
|
||||||
// daysSB.append("6,");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// //调用JPush api设置Push时间
|
|
||||||
// JPushInterface.setPushTime(getApplicationContext(), days, startime, endtime);
|
|
||||||
//
|
|
||||||
// mEditor = mSettings.edit();
|
|
||||||
// mEditor.putString(ExampleUtil.PREFS_DAYS, daysSB.toString());
|
|
||||||
// mEditor.putInt(ExampleUtil.PREFS_START_TIME, startime);
|
|
||||||
// mEditor.putInt(ExampleUtil.PREFS_END_TIME, endtime);
|
|
||||||
// mEditor.commit();
|
|
||||||
// Toast.makeText(SettingActivity.this, R.string.setting_su, Toast.LENGTH_SHORT).show();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
||||||
// if (keyCode == KeyEvent.KEYCODE_BACK){
|
|
||||||
// finish();
|
|
||||||
// }
|
|
||||||
// return super.onKeyDown(keyCode, event);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void setWeek(String day){
|
|
||||||
// int dayId = Integer.valueOf(day);
|
|
||||||
// switch (dayId) {
|
|
||||||
// case 0:
|
|
||||||
// mSunday.setChecked(true);
|
|
||||||
// break;
|
|
||||||
// case 1:
|
|
||||||
// mMonday.setChecked(true);
|
|
||||||
// break;
|
|
||||||
// case 2:
|
|
||||||
// mTuesday.setChecked(true);
|
|
||||||
// break;
|
|
||||||
// case 3:
|
|
||||||
// mWednesday.setChecked(true);
|
|
||||||
// break;
|
|
||||||
// case 4:
|
|
||||||
// mThursday.setChecked(true);
|
|
||||||
// break;
|
|
||||||
// case 5:
|
|
||||||
// mFriday.setChecked(true);
|
|
||||||
// break;
|
|
||||||
// case 6:
|
|
||||||
// mSaturday.setChecked(true);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void initAllWeek(boolean isChecked) {
|
|
||||||
// mSunday.setChecked(isChecked);
|
|
||||||
// mMonday.setChecked(isChecked);
|
|
||||||
// mTuesday.setChecked(isChecked);
|
|
||||||
// mWednesday.setChecked(isChecked);
|
|
||||||
// mThursday.setChecked(isChecked);
|
|
||||||
// mFriday.setChecked(isChecked);
|
|
||||||
// mSaturday.setChecked(isChecked);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package com.uiui.appstore.jpush.Invalid;
|
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,263 +0,0 @@
|
|||||||
package com.uiui.appstore.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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package com.uiui.appstore.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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package com.uiui.appstore.jpush;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.uiui.appstore.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);
|
|
||||||
}
|
|
||||||
@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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@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);
|
|
||||||
BaseApplication.getInstance().manageCustomMessage(customMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
package com.uiui.appstore.jpush;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import com.uiui.appstore.activity.MainActivity;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import cn.jpush.android.api.JPushInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义接收器
|
|
||||||
*
|
|
||||||
* 如果不定义这个 Receiver,则:
|
|
||||||
* 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_RICHPUSH_CALLBACK.equals(intent.getAction())) {
|
|
||||||
Logger.d(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA));
|
|
||||||
//在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码,比如打开新的Activity, 打开一个网页等..
|
|
||||||
|
|
||||||
} 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
//send msg to MainActivity
|
|
||||||
private void processCustomMessage(Context context, Bundle bundle) {
|
|
||||||
if (MainActivity.isForeground) {
|
|
||||||
String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
|
|
||||||
String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
|
|
||||||
Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);
|
|
||||||
msgIntent.putExtra(MainActivity.KEY_MESSAGE, message);
|
|
||||||
if (!ExampleUtil.isEmpty(extras)) {
|
|
||||||
try {
|
|
||||||
JSONObject extraJson = new JSONObject(extras);
|
|
||||||
if (extraJson.length() > 0) {
|
|
||||||
msgIntent.putExtra(MainActivity.KEY_EXTRAS, extras);
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.uiui.appstore.jpush;
|
|
||||||
|
|
||||||
import cn.jpush.android.service.JCommonService;
|
|
||||||
|
|
||||||
public class PushService extends JCommonService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,338 +0,0 @@
|
|||||||
package com.uiui.appstore.jpush;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Message;
|
|
||||||
import android.util.SparseArray;
|
|
||||||
|
|
||||||
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);
|
|
||||||
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);
|
|
||||||
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 +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user