版本升级的修改
This commit is contained in:
parent
4de8757925
commit
f54db83131
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
package="com.navinfo.outdoor">
|
package="com.navinfo.outdoor">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
@ -9,6 +10,13 @@
|
|||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.CAMERA" /> <!-- <uses-sdk android:minSdkVersion="8"></uses-sdk> -->
|
<uses-permission android:name="android.permission.CAMERA" /> <!-- <uses-sdk android:minSdkVersion="8"></uses-sdk> -->
|
||||||
|
|
||||||
|
<!-- 在SDCard中创建与删除文件权限 -->
|
||||||
|
<uses-permission
|
||||||
|
android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
|
||||||
|
tools:ignore="ProtectedPermissions" />
|
||||||
|
<!-- 安装APK权限 -->
|
||||||
|
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||||
<!-- 友盟检测bug -->
|
<!-- 友盟检测bug -->
|
||||||
<!-- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />-->
|
<!-- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />-->
|
||||||
<!-- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />-->
|
<!-- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />-->
|
||||||
@ -89,6 +97,21 @@
|
|||||||
android:screenOrientation="portrait"/>
|
android:screenOrientation="portrait"/>
|
||||||
<activity android:name=".activity.UserActivity"
|
<activity android:name=".activity.UserActivity"
|
||||||
android:screenOrientation="portrait"/>
|
android:screenOrientation="portrait"/>
|
||||||
|
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="androidx.core.content.FileProvider"
|
||||||
|
android:authorities="com.navinfo.outdoor.fileprovider"
|
||||||
|
android:grantUriPermissions="true"
|
||||||
|
android:exported="false"
|
||||||
|
>
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
android:resource="@xml/file_paths" />
|
||||||
|
</provider>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -4,6 +4,7 @@ import android.app.ProgressDialog;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.CountDownTimer;
|
import android.os.CountDownTimer;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -13,6 +14,7 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.core.content.FileProvider;
|
||||||
|
|
||||||
import com.hjq.permissions.OnPermissionCallback;
|
import com.hjq.permissions.OnPermissionCallback;
|
||||||
import com.hjq.permissions.Permission;
|
import com.hjq.permissions.Permission;
|
||||||
@ -47,18 +49,30 @@ public class MainActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean handleMessage(@NonNull Message msg) {
|
public boolean handleMessage(@NonNull Message msg) {
|
||||||
if (msg.what==0){
|
if (msg.what==0){
|
||||||
|
Toast.makeText(MainActivity.this, "下载完成", Toast.LENGTH_SHORT).show();
|
||||||
//将下载进度对话框取消
|
//将下载进度对话框取消
|
||||||
pBar.cancel();
|
pBar.cancel();
|
||||||
//安装apk,也可以进行静默安装
|
//调用系统安装程序
|
||||||
|
//安装apk,也可以进行静默安装
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
intent.setDataAndType(Uri.fromFile(new File(Constant.NAVINFO_APk, "navinfo.apk")),
|
File file = new File(Constant.NAVINFO_APk+"DTXB.apk");
|
||||||
"application/vnd.android.package-archive");
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
startActivityForResult(intent, 10);
|
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
|
Uri contentUri = FileProvider.getUriForFile(MainActivity.this, "com.navinfo.outdoor.fileprovider", file);
|
||||||
|
intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
|
||||||
|
} else {
|
||||||
|
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
}
|
||||||
|
startActivity(intent);
|
||||||
|
}else if (msg.what==1){
|
||||||
|
pBar.setProgress(progress);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
private ProgressDialog pBar;
|
private ProgressDialog pBar;
|
||||||
|
private int progress;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getLayout() {
|
protected int getLayout() {
|
||||||
@ -91,6 +105,7 @@ public class MainActivity extends BaseActivity {
|
|||||||
.permission(Permission.MANAGE_EXTERNAL_STORAGE/*, Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE*/)
|
.permission(Permission.MANAGE_EXTERNAL_STORAGE/*, Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE*/)
|
||||||
// 申请相机权限
|
// 申请相机权限
|
||||||
.permission(Permission.CAMERA)
|
.permission(Permission.CAMERA)
|
||||||
|
.permission(Permission.REQUEST_INSTALL_PACKAGES)
|
||||||
// 位置权限
|
// 位置权限
|
||||||
.permission(Permission.ACCESS_FINE_LOCATION)
|
.permission(Permission.ACCESS_FINE_LOCATION)
|
||||||
//.permission(Permission.ACCESS_BACKGROUND_LOCATION)
|
//.permission(Permission.ACCESS_BACKGROUND_LOCATION)
|
||||||
@ -143,7 +158,7 @@ public class MainActivity extends BaseActivity {
|
|||||||
dismissLoadingDialog();
|
dismissLoadingDialog();
|
||||||
if (response.getCode() == 200) {
|
if (response.getCode() == 200) {
|
||||||
int version = response.getBody().getVersion();
|
int version = response.getBody().getVersion();
|
||||||
if (versionCode < version) {
|
if (versionCode <version) {//TODO 改成<
|
||||||
//升级
|
//升级
|
||||||
ApkVersionBean.bodyBean body = response.getBody();
|
ApkVersionBean.bodyBean body = response.getBody();
|
||||||
showUpdateDialog(body);
|
showUpdateDialog(body);
|
||||||
@ -193,6 +208,7 @@ public class MainActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
//用户点击了取消
|
//用户点击了取消
|
||||||
|
initTime();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}else{//强制更新
|
}else{//强制更新
|
||||||
@ -208,6 +224,14 @@ public class MainActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
//用户点击了取消
|
||||||
|
initTime();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
@ -246,18 +270,23 @@ public class MainActivity extends BaseActivity {
|
|||||||
try {
|
try {
|
||||||
URL url = new URL(path);
|
URL url = new URL(path);
|
||||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||||
con.setReadTimeout(5000);
|
con.setReadTimeout(60000);
|
||||||
con.setConnectTimeout(5000);
|
con.setConnectTimeout(15000);
|
||||||
con.setRequestProperty("Charset", "UTF-8");
|
con.setRequestProperty("Charset", "UTF-8");
|
||||||
con.setRequestMethod("GET");
|
con.setRequestMethod("GET");
|
||||||
|
con.connect();
|
||||||
if (con.getResponseCode() == 200) {
|
if (con.getResponseCode() == 200) {
|
||||||
|
File files = new File(Constant.NAVINFO_APk);
|
||||||
|
if (!files.exists()){
|
||||||
|
files.mkdir();
|
||||||
|
}
|
||||||
int length = con.getContentLength();// 获取文件大小
|
int length = con.getContentLength();// 获取文件大小
|
||||||
InputStream is = con.getInputStream();
|
InputStream is = con.getInputStream();
|
||||||
pBar.setMax(length); // 设置进度条的总长度
|
pBar.setMax(100); // 设置进度条的总长度
|
||||||
FileOutputStream fileOutputStream = null;
|
FileOutputStream fileOutputStream = null;
|
||||||
if (is != null) {
|
if (is != null) {
|
||||||
//对apk进行保存
|
//对apk进行保存
|
||||||
File file = new File(Constant.NAVINFO_APk, "navinfo.apk");
|
File file = new File(Constant.NAVINFO_APk+"DTXB.apk");
|
||||||
fileOutputStream = new FileOutputStream(file);
|
fileOutputStream = new FileOutputStream(file);
|
||||||
byte[] buf = new byte[1024];
|
byte[] buf = new byte[1024];
|
||||||
int ch;
|
int ch;
|
||||||
@ -265,7 +294,8 @@ public class MainActivity extends BaseActivity {
|
|||||||
while ((ch = is.read(buf)) != -1) {
|
while ((ch = is.read(buf)) != -1) {
|
||||||
fileOutputStream.write(buf, 0, ch);
|
fileOutputStream.write(buf, 0, ch);
|
||||||
process += ch;
|
process += ch;
|
||||||
pBar.setProgress(process); // 实时更新进度了
|
progress = (int) (((float) process / length) * 100);
|
||||||
|
handler.sendEmptyMessage(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fileOutputStream != null) {
|
if (fileOutputStream != null) {
|
||||||
@ -283,6 +313,8 @@ public class MainActivity extends BaseActivity {
|
|||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initView() {
|
protected void initView() {
|
||||||
super.initView();
|
super.initView();
|
||||||
|
@ -36,7 +36,7 @@ public class Constant {
|
|||||||
public static final String VIDEOS_ = BASE_FOLDER + "/videos";
|
public static final String VIDEOS_ = BASE_FOLDER + "/videos";
|
||||||
public static final String POI_DAO = BASE_FOLDER + "/BaseDao/";
|
public static final String POI_DAO = BASE_FOLDER + "/BaseDao/";
|
||||||
//下载文件
|
//下载文件
|
||||||
public static final String NAVINFO_APk = BASE_FOLDER + "/apk";
|
public static final String NAVINFO_APk = BASE_FOLDER + "/apk/";
|
||||||
// 申请权限的RequestCode
|
// 申请权限的RequestCode
|
||||||
public static final int PERMISSION_REQUEST_CODE = 0x100;
|
public static final int PERMISSION_REQUEST_CODE = 0x100;
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -17,7 +17,7 @@ public class HttpInterface {
|
|||||||
//dtxbmaps.navinfo.com/dtxb/m4/user/appVersion/checkVersion?version=155&operationType=android
|
//dtxbmaps.navinfo.com/dtxb/m4/user/appVersion/checkVersion?version=155&operationType=android
|
||||||
//172.23.139.4:8001/appVersion/checkVersion?version=155&operationType=android version是版本 operationType固定值 安卓 get
|
//172.23.139.4:8001/appVersion/checkVersion?version=155&operationType=android version是版本 operationType固定值 安卓 get
|
||||||
public static final String APKIP="http://172.23.139.4:8001/";
|
public static final String APKIP="http://172.23.139.4:8001/";
|
||||||
public static final String APP_CHECK_VERSION = IP+"appVersion/checkVersion"; //版本升级
|
public static final String APP_CHECK_VERSION = IP+USER_PATH+"appVersion/1/checkVersion"; //版本升级
|
||||||
/**
|
/**
|
||||||
* 我的
|
* 我的
|
||||||
* Path=/m4/user/*
|
* Path=/m4/user/*
|
||||||
@ -31,7 +31,7 @@ public class HttpInterface {
|
|||||||
public static final String USER_AUTH_ADD = IP+USER_PATH+ "userAuth/add"; //实名认证
|
public static final String USER_AUTH_ADD = IP+USER_PATH+ "userAuth/add"; //实名认证
|
||||||
//172.23.139.4:9999/m4/user/userLocation/1/userLocation post 参数 geom:geohash加密
|
//172.23.139.4:9999/m4/user/userLocation/1/userLocation post 参数 geom:geohash加密
|
||||||
public static final String geomIP="http://172.23.139.4:9999/m4";
|
public static final String geomIP="http://172.23.139.4:9999/m4";
|
||||||
public static final String USER_LOCATION = geomIP+USER_PATH+ "userLocation/"+USERID+"/userLocation"; //上传用户坐标
|
public static final String USER_LOCATION = IP+USER_PATH+ "userLocation/"+USERID+"/userLocation"; //上传用户坐标
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发现
|
* 发现
|
||||||
|
@ -13,8 +13,7 @@ public class APKVersionCodeUtils {
|
|||||||
int versionCode = 0;
|
int versionCode = 0;
|
||||||
try {
|
try {
|
||||||
//获取软件版本号,对应AndroidManifest.xml下android:versionCode
|
//获取软件版本号,对应AndroidManifest.xml下android:versionCode
|
||||||
versionCode = mContext.getPackageManager().
|
versionCode = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionCode;
|
||||||
getPackageInfo(mContext.getPackageName(), 0).versionCode;
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
5
app/src/main/res/xml/file_paths.xml
Normal file
5
app/src/main/res/xml/file_paths.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<paths>
|
||||||
|
<external-path path="Android/data/com.navinfo.outdoor/" name="files_root" />
|
||||||
|
<external-path path="." name="external_storage_root" />
|
||||||
|
</paths>
|
Loading…
x
Reference in New Issue
Block a user