版本升级的修改
This commit is contained in:
parent
4de8757925
commit
f54db83131
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.navinfo.outdoor">
|
||||
|
||||
<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.WRITE_EXTERNAL_STORAGE" />
|
||||
<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 -->
|
||||
<!-- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />-->
|
||||
<!-- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />-->
|
||||
@ -89,6 +97,21 @@
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity android:name=".activity.UserActivity"
|
||||
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>
|
||||
|
||||
|
||||
|
||||
|
||||
</manifest>
|
@ -4,6 +4,7 @@ import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
@ -13,6 +14,7 @@ import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.FileProvider;
|
||||
|
||||
import com.hjq.permissions.OnPermissionCallback;
|
||||
import com.hjq.permissions.Permission;
|
||||
@ -47,18 +49,30 @@ public class MainActivity extends BaseActivity {
|
||||
@Override
|
||||
public boolean handleMessage(@NonNull Message msg) {
|
||||
if (msg.what==0){
|
||||
Toast.makeText(MainActivity.this, "下载完成", Toast.LENGTH_SHORT).show();
|
||||
//将下载进度对话框取消
|
||||
pBar.cancel();
|
||||
//调用系统安装程序
|
||||
//安装apk,也可以进行静默安装
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(Uri.fromFile(new File(Constant.NAVINFO_APk, "navinfo.apk")),
|
||||
"application/vnd.android.package-archive");
|
||||
startActivityForResult(intent, 10);
|
||||
File file = new File(Constant.NAVINFO_APk+"DTXB.apk");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
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;
|
||||
}
|
||||
});
|
||||
private ProgressDialog pBar;
|
||||
private int progress;
|
||||
|
||||
@Override
|
||||
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.CAMERA)
|
||||
.permission(Permission.REQUEST_INSTALL_PACKAGES)
|
||||
// 位置权限
|
||||
.permission(Permission.ACCESS_FINE_LOCATION)
|
||||
//.permission(Permission.ACCESS_BACKGROUND_LOCATION)
|
||||
@ -143,7 +158,7 @@ public class MainActivity extends BaseActivity {
|
||||
dismissLoadingDialog();
|
||||
if (response.getCode() == 200) {
|
||||
int version = response.getBody().getVersion();
|
||||
if (versionCode < version) {
|
||||
if (versionCode <version) {//TODO 改成<
|
||||
//升级
|
||||
ApkVersionBean.bodyBean body = response.getBody();
|
||||
showUpdateDialog(body);
|
||||
@ -193,6 +208,7 @@ public class MainActivity extends BaseActivity {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
//用户点击了取消
|
||||
initTime();
|
||||
}
|
||||
});
|
||||
}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();
|
||||
@ -246,18 +270,23 @@ public class MainActivity extends BaseActivity {
|
||||
try {
|
||||
URL url = new URL(path);
|
||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||
con.setReadTimeout(5000);
|
||||
con.setConnectTimeout(5000);
|
||||
con.setReadTimeout(60000);
|
||||
con.setConnectTimeout(15000);
|
||||
con.setRequestProperty("Charset", "UTF-8");
|
||||
con.setRequestMethod("GET");
|
||||
con.connect();
|
||||
if (con.getResponseCode() == 200) {
|
||||
File files = new File(Constant.NAVINFO_APk);
|
||||
if (!files.exists()){
|
||||
files.mkdir();
|
||||
}
|
||||
int length = con.getContentLength();// 获取文件大小
|
||||
InputStream is = con.getInputStream();
|
||||
pBar.setMax(length); // 设置进度条的总长度
|
||||
pBar.setMax(100); // 设置进度条的总长度
|
||||
FileOutputStream fileOutputStream = null;
|
||||
if (is != null) {
|
||||
//对apk进行保存
|
||||
File file = new File(Constant.NAVINFO_APk, "navinfo.apk");
|
||||
File file = new File(Constant.NAVINFO_APk+"DTXB.apk");
|
||||
fileOutputStream = new FileOutputStream(file);
|
||||
byte[] buf = new byte[1024];
|
||||
int ch;
|
||||
@ -265,7 +294,8 @@ public class MainActivity extends BaseActivity {
|
||||
while ((ch = is.read(buf)) != -1) {
|
||||
fileOutputStream.write(buf, 0, ch);
|
||||
process += ch;
|
||||
pBar.setProgress(process); // 实时更新进度了
|
||||
progress = (int) (((float) process / length) * 100);
|
||||
handler.sendEmptyMessage(1);
|
||||
}
|
||||
}
|
||||
if (fileOutputStream != null) {
|
||||
@ -283,6 +313,8 @@ public class MainActivity extends BaseActivity {
|
||||
}.start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
super.initView();
|
||||
|
@ -36,7 +36,7 @@ public class Constant {
|
||||
public static final String VIDEOS_ = BASE_FOLDER + "/videos";
|
||||
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
|
||||
public static final int PERMISSION_REQUEST_CODE = 0x100;
|
||||
|
||||
|
@ -57,6 +57,7 @@ import com.navinfo.outdoor.room.InsertAndUpdateUtils;
|
||||
import com.navinfo.outdoor.room.PoiDao;
|
||||
import com.navinfo.outdoor.room.PoiDatabase;
|
||||
import com.navinfo.outdoor.room.PoiEntity;
|
||||
import com.navinfo.outdoor.util.Base64;
|
||||
import com.navinfo.outdoor.util.Geohash;
|
||||
import com.navinfo.outdoor.util.GeometryTools;
|
||||
import com.navinfo.outdoor.util.MyTecentLocationSource;
|
||||
@ -235,8 +236,10 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
// 移动到当前位置后,开始请求地图数据
|
||||
initList(Constant.currentLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {}
|
||||
public void onCancel() {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
dismissLoadingDialog();
|
||||
@ -339,9 +342,13 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
}
|
||||
|
||||
private void iniUserLocation() {
|
||||
String encode = Geohash.getInstance().encode(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude());
|
||||
Geometry geometry = GeometryTools.createGeometry(new LatLng(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude()));
|
||||
try {
|
||||
String encode = Base64.desEncrypt(geometry.toString());
|
||||
HttpParams httpParams = new HttpParams();
|
||||
httpParams.put("geom", encode);
|
||||
long time = System.currentTimeMillis();
|
||||
httpParams.put("datetime", time);
|
||||
OkGoBuilder.getInstance().Builder(getActivity())
|
||||
.url(HttpInterface.USER_LOCATION)
|
||||
.cls(UserBean.class)
|
||||
@ -366,8 +373,10 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
Log.d("TAG", "onSuccess: sss********sssssssssssss 成功" + e.getMessage() + "");
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void initList (TencentLocation tencentLocation){
|
||||
int task_type = Constant.TASK_TYPE;
|
||||
int limit_type = Constant.LIMIT_TTPE;
|
||||
@ -540,6 +549,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
obtain.obj = response;
|
||||
EventBus.getDefault().post(obtain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e, int id) {
|
||||
dismissLoadingDialog();
|
||||
@ -1233,8 +1243,10 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
markerPoi.setFixingPoint(screenPosition.x, screenPosition.y);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {}
|
||||
public void onCancel() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -1255,8 +1267,10 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
markerPile.setFixingPoint(screenPosition.x, screenPosition.y);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {}
|
||||
public void onCancel() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ public class HttpInterface {
|
||||
//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
|
||||
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/*
|
||||
@ -31,7 +31,7 @@ public class HttpInterface {
|
||||
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加密
|
||||
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;
|
||||
try {
|
||||
//获取软件版本号,对应AndroidManifest.xml下android:versionCode
|
||||
versionCode = mContext.getPackageManager().
|
||||
getPackageInfo(mContext.getPackageName(), 0).versionCode;
|
||||
versionCode = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionCode;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
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