|
|
@ -3,6 +3,7 @@ package com.qhclh.ytzh.home; |
|
|
import android.Manifest; |
|
|
import android.Manifest; |
|
|
import android.content.Intent; |
|
|
import android.content.Intent; |
|
|
import android.net.Uri; |
|
|
import android.net.Uri; |
|
|
|
|
|
import android.os.Looper; |
|
|
import android.support.annotation.NonNull; |
|
|
import android.support.annotation.NonNull; |
|
|
import android.support.v4.app.FragmentTransaction; |
|
|
import android.support.v4.app.FragmentTransaction; |
|
|
import android.support.v7.widget.Toolbar; |
|
|
import android.support.v7.widget.Toolbar; |
|
|
@ -42,6 +43,7 @@ import butterknife.BindView; |
|
|
import butterknife.OnClick; |
|
|
import butterknife.OnClick; |
|
|
import pub.devrel.easypermissions.AfterPermissionGranted; |
|
|
import pub.devrel.easypermissions.AfterPermissionGranted; |
|
|
import pub.devrel.easypermissions.EasyPermissions; |
|
|
import pub.devrel.easypermissions.EasyPermissions; |
|
|
|
|
|
import util.UpdateAppUtils; |
|
|
|
|
|
|
|
|
public class MainActivity extends BaseActivity { |
|
|
public class MainActivity extends BaseActivity { |
|
|
@BindView(R.id.toolbar) |
|
|
@BindView(R.id.toolbar) |
|
|
@ -394,6 +396,7 @@ public class MainActivity extends BaseActivity { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final int REQUEST_PERMISSION_CAMERA_CODE = 1021; |
|
|
private static final int REQUEST_PERMISSION_CAMERA_CODE = 1021; |
|
|
|
|
|
private static final int REQUEST_PERMISSION_CAMERA_CODE_W = 1022; |
|
|
|
|
|
|
|
|
@AfterPermissionGranted(REQUEST_PERMISSION_CAMERA_CODE) |
|
|
@AfterPermissionGranted(REQUEST_PERMISSION_CAMERA_CODE) |
|
|
private void dongtaiQuanxian() { |
|
|
private void dongtaiQuanxian() { |
|
|
@ -417,7 +420,21 @@ public class MainActivity extends BaseActivity { |
|
|
@Override |
|
|
@Override |
|
|
public void onWindowFocusChanged(boolean hasFocus) { |
|
|
public void onWindowFocusChanged(boolean hasFocus) { |
|
|
super.onWindowFocusChanged(hasFocus); |
|
|
super.onWindowFocusChanged(hasFocus); |
|
|
checkUpData(); |
|
|
|
|
|
|
|
|
writepermission(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@AfterPermissionGranted(REQUEST_PERMISSION_CAMERA_CODE_W) |
|
|
|
|
|
private void writepermission() { |
|
|
|
|
|
String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE}; |
|
|
|
|
|
if (!EasyPermissions.hasPermissions(this, perms)) { |
|
|
|
|
|
// Do not have permissions, request them now |
|
|
|
|
|
EasyPermissions.requestPermissions(this, getString(R.string.permission_phonestate), |
|
|
|
|
|
REQUEST_PERMISSION_CAMERA_CODE_W, perms); |
|
|
|
|
|
} else { |
|
|
|
|
|
// Already have permission, do the thing |
|
|
|
|
|
// ... |
|
|
|
|
|
checkUpData(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void checkUpData() { |
|
|
private void checkUpData() { |
|
|
@ -432,19 +449,30 @@ public class MainActivity extends BaseActivity { |
|
|
downLoadBean = gson.fromJson(jsonString, DownLoadBean.class); |
|
|
downLoadBean = gson.fromJson(jsonString, DownLoadBean.class); |
|
|
versionName = downLoadBean.getVersion(); |
|
|
versionName = downLoadBean.getVersion(); |
|
|
downloadUrl = downLoadBean.getDownload(); |
|
|
downloadUrl = downLoadBean.getDownload(); |
|
|
String localversionname = ApkUtils.getVersionName(MainActivity.this); |
|
|
|
|
|
|
|
|
|
|
|
if (localversionname.equals(versionName)) { |
|
|
|
|
|
// showToast(""); |
|
|
|
|
|
} else { |
|
|
|
|
|
Intent intent = new Intent(); |
|
|
|
|
|
intent.setAction("android.intent.action.VIEW"); |
|
|
|
|
|
Uri content_url = Uri.parse(downloadUrl); |
|
|
|
|
|
intent.setData(content_url); |
|
|
|
|
|
startActivity(intent); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Looper.prepare(); |
|
|
|
|
|
UpdateAppUtils.from(MainActivity.this) |
|
|
|
|
|
.checkBy(UpdateAppUtils.CHECK_BY_VERSION_NAME) //更新检测方式,默认为VersionCode |
|
|
|
|
|
.serverVersionName(versionName) |
|
|
|
|
|
.apkPath(downloadUrl) |
|
|
|
|
|
.showNotification(true) //是否显示下载进度到通知栏,默认为true |
|
|
|
|
|
.downloadBy(UpdateAppUtils.DOWNLOAD_BY_APP) //下载方式:app下载、手机浏览器下载。默认app下载 |
|
|
|
|
|
.isForce(true) //是否强制更新,默认false 强制更新情况下用户不同意更新则不能使用app |
|
|
|
|
|
.update(); |
|
|
|
|
|
Looper.loop(); |
|
|
|
|
|
// String localversionname = ApkUtils.getVersionName(MainActivity.this); |
|
|
|
|
|
// |
|
|
|
|
|
// if (localversionname.equals(versionName)) { |
|
|
|
|
|
// } else { |
|
|
|
|
|
// Intent intent = new Intent(); |
|
|
|
|
|
// intent.setAction("android.intent.action.VIEW"); |
|
|
|
|
|
// Uri content_url = Uri.parse(downloadUrl); |
|
|
|
|
|
// intent.setData(content_url); |
|
|
|
|
|
// startActivity(intent); |
|
|
|
|
|
// } |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}).start(); |
|
|
}).start(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |