Android 6.0及以上 权限适配

This commit is contained in:
kehaoyuan
2017-09-13 18:23:55 +08:00
parent 2e84aeaccf
commit 85031e89b6
10 changed files with 223 additions and 151 deletions

View File

@ -33,7 +33,6 @@ import com.gh.common.util.GameUtils;
import com.gh.common.util.LoginUtils;
import com.gh.common.util.PackageUtils;
import com.gh.common.util.PlatformUtils;
import com.gh.common.util.TokenUtils;
import com.gh.common.util.TrafficUtils;
import com.gh.download.DownloadManager;
import com.gh.gamecenter.db.info.ConcernInfo;
@ -46,7 +45,6 @@ import com.gh.gamecenter.eventbus.EBDownloadStatus;
import com.gh.gamecenter.eventbus.EBPackage;
import com.gh.gamecenter.eventbus.EBShowDialog;
import com.gh.gamecenter.eventbus.EBSkip;
import com.gh.gamecenter.eventbus.EBUISwitch;
import com.gh.gamecenter.fragment.MainFragment;
import com.gh.gamecenter.manager.ConcernManager;
import com.gh.gamecenter.manager.DataCollectionManager;
@ -54,7 +52,6 @@ import com.gh.gamecenter.manager.FilterManager;
import com.gh.gamecenter.manager.GameManager;
import com.gh.gamecenter.manager.PackageManager;
import com.gh.gamecenter.manager.UpdateManager;
import com.gh.gamecenter.retrofit.JSONObjectResponse;
import com.gh.gamecenter.retrofit.ObservableUtil;
import com.gh.gamecenter.retrofit.Response;
import com.gh.gamecenter.retrofit.RetrofitManager;
@ -634,8 +631,8 @@ public class MainActivity extends BaseActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 初始化gameMap
// DownloadManager.getInstance(this).initGameMap();
// 上传数据
DataCollectionManager.getInstance(getApplicationContext()).upload();
sp = PreferenceManager.getDefaultSharedPreferences(this);
isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(this), true);
@ -674,51 +671,11 @@ public class MainActivity extends BaseActivity {
// 检查是否有权限读取应用列表
checkPermission();
if (isNewFirstLaunch || TokenUtils.getDeviceId(this) == null) {
// AppController.MAIN_EXECUTOR.execute(new Runnable() {
// @Override
// public void run() {
// 注册设备
// TokenUtils.register(MainActivity.this.getApplicationContext());
// TokenUtils.getToken(MainActivity.this.getApplicationContext(), false) // TODO 是否移除
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(new Response<String>() {
// @Override
// public void onResponse(String token) {
// TokenUtils.checkDeviceInfo(MainActivity.this.getApplicationContext(), token);
// }
// });
// updateUserGhzs();
// initConcern(); // 初始化关注 移到登录成功后调用
// }
// });
} else {
// updateUserGhzs();
}
// 执行跳转事件
handler.postDelayed(skipRun, 500);
// if (sp.getBoolean("changeDefaultIcon", false) && sp.getInt("default_user_icon", 0) != 0) {
// postDefaultIcon(sp.getInt("default_user_icon", 0));
// }
getSuggestionType();
// if (LoginUtils.getUserInfo(this) != null && getIntent() != null && getIntent().getBundleExtra(KEY_DATA) != null
// && getIntent().getBundleExtra(KEY_DATA).getBoolean("exceptionReStart", false)) {
// DialogUtils.showWarningDialog(this, "发生闪退", "光环助手刚刚发生了闪退,反馈一下(只需简单描述你刚才的操作)以帮忙我们更好地修复问题?"
// , "暂不", " 反馈一下"
// , new DialogUtils.ConfirmListener() {
// @Override
// public void onConfirm() {
// SuggestionActivity.startSuggestionActivity(MainActivity.this, 3, null, null);
// }
// }, null);
// }
final String message = Config.getExceptionMsg(this);
if (LoginUtils.getUserInfo(this) != null && !TextUtils.isEmpty(message)) {
Config.setExceptionMsg(this, null);
@ -739,9 +696,6 @@ public class MainActivity extends BaseActivity {
super.onDestroy();
DownloadManager.getInstance(this).removeObserver(dataWatcher);
// if (sp.getBoolean("changeDefaultIcon", false) && sp.getInt("default_user_icon", 0) != 0) {
// postDefaultIcon(sp.getInt("default_user_icon", 0));
// }
handler.removeCallbacksAndMessages(null);
}
@ -762,7 +716,7 @@ public class MainActivity extends BaseActivity {
String string = response.string();
JSONObject object = new JSONObject(string);
String deviceId = object.getString("device_id");
Utils.log("========::" + deviceId);
Utils.log("========checkDevice::" + deviceId);
if (!TextUtils.isEmpty(deviceId)) {
oldUserSkip(deviceId);
}
@ -817,35 +771,6 @@ public class MainActivity extends BaseActivity {
}
private void getConcernDigest(final List<String> arrGameId) {
final ArrayList<GameEntity> concernDigest = new ArrayList<>();
if (arrGameId.size() == 0) {
EventBus.getDefault().post(new EBUISwitch("NewsWrapperFragment", -2)); // 没有关注
}
List<Observable<GameEntity>> list = new ArrayList<>();
for (String gameId : arrGameId) {
list.add(RetrofitManager.getApi().getGameDigest(gameId));
}
Observable.merge(list)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Response<GameEntity>() {
@Override
public void onCompleted() {
concernManager.addByList(concernDigest);
}
@Override
public void onNext(GameEntity response) {
concernDigest.add(response);
}
});
}
private void checkPermission() {
List<PackageInfo> installedList = getPackageManager().getInstalledPackages(0);
if (installedList.isEmpty()) {
@ -1036,27 +961,4 @@ public class MainActivity extends BaseActivity {
});
}
// 提交默认头像
private void postDefaultIcon(final int i) { // TODO 是否删除
Map<String, String> params = new HashMap<>();
params.put("icon_key", "icon" + i);
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
new JSONObject(params).toString());
RetrofitManager.getUser()
.postDefaultIcon(LoginUtils.getToken(this), body)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new JSONObjectResponse() {
@Override
public void onResponse(JSONObject response) {
sp.edit().putBoolean("changeDefaultIcon", false).apply();
}
@Override
public void onFailure(HttpException e) {
}
}
);
}
}