大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 站长CLUB -> 游戏攻略 -> 怎样禁止安卓app强制更新,禁止app强制更新方法

怎样禁止安卓app强制更新,禁止app强制更新方法

时间: 2021-07-31 作者:daque

安卓手性能遏止某个app机动革新吗,安卓软硬件如何遏止强迫机动革新?本篇作品重要引见了android中强迫革新app范例代码,小编感触挺不错的,此刻瓜分给大师,也给大师做个参考。一道伴随小编过来看看吧

有些运用的有功夫须要强迫革新,这功夫运用只能革新要不就不许用了(开拓者为了建设少许需要的bug)。

如许的话,只能乖乖晋级大概卸载。

那些是不受android体例牵制的,没法遏止掉。

android中强迫革新app范例代码

本篇作品重要引见了android中强迫革新app范例代码,小编感触挺不错的,此刻瓜分给大师,也给大师做个参考。一道伴随小编过来看看吧

引荐第三种办法,大略赶快不卡。

第一种:jjdxm_update

github地方:jjdxmashl/jjdxm_update

功效图:

点击登时革新,步调会在后盾载入,报告栏有载入进度。这个功夫手机体例很卡,大概因为是载入app的因为吧。载入实行后弹出安置界面

简介:

怎样禁止安卓app强制更新,禁止app强制更新方法图1

这是大神jjdxmashl的开源名目,载入地方见上方。有本子革新、手动革新、寂静革新、机动革新4种情景。运用内革新,实行类是友盟机动革新sdk的形式,用户运用前只须要摆设本人的效劳器革新查看接口即可(必需接口),也不妨扩充介入一个接口动作在线参数摆设来实行,不妨实行底下的4种2革新办法和能否强迫革新拉拢运用,扶助get、post办法乞求搜集,默许是get乞求。

4种革新查看典型

手动革新:手动检验和测定革新(一切搜集典型情况检验和测定并提醒重要用来点击检验和测定运用)

机动革新:机动检验和测定革新(一切搜集典型情况检验和测定并提醒)

仅wifi机动检验和测定革新(惟有wifi搜集典型情况检验和测定并提醒)

寂静革新:仅wifi机动检验和测定载入(惟有wifi搜集典型情况检验和测定、载入完才提醒)

2种强迫革新办法

在革新查看归来后,径直树立update.setforce(true)

共同在线参数运用,经过在线参数归来的数据树立updatehelper.getinstance().setforced(true)

上述4中革新查看 贯串 2种强迫革新,实用于:上一个app本子有宏大缺点,窜改在线 参数一致遏制一切的app用户,不革新就不不妨运用app。

重要道理:效劳器上窜改参数值,app端获得保守行确定,即使是强迫革新,则在翻开运用时就提醒有新本子的app,革新实行后才不妨运用该app;革新为实行,则提醒框不消逝,点击back键则退出运用。

强迫革新的运用

底下演练的是强迫革新的情景,

step1:增添依附库

在主步调的build.gradle文献的dependencies属性中增添依附库

?

1

2

3

4

5

6

dependencies {

...

1.update:jjdxm-update:1.0.5'

1.download:jjdxm-download:1.0.3'

...

}

step2:摆设革新接口参数消息,初始化参数接口妥协析参数

必需摆设的是在线革新接口和该接口归来数据的领会 可选的是在线参数接口和该接口归来数据的领会(普遍用不到),在线参数不妨随机设置零个或多个不承诺义的参数来到达在线窜改apk的局部个性。

step2-1 创造一个机动革新的摆设类

本领+参数

含意

setcheckurl(checkurl)

checkurl:革新app的接口

setcheckjsonparser(new parsedata() {return update;}

只能归来update典型,领会不妨随意领会,但要把领会到的数据赋值给update,再把update归来

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

publicclassupdateconfig {

privatestaticfinalstring tag ="updateconfig";

privatestaticstring checkurl ="http://192.168.1.11:8080/cmcc/jsoninfo";

publicstaticvoidinit(context context) {

updatehelper.init(context);

updatehelper.getinstance()

.setmethod(requesttype.get)// 可填:乞求办法,默许为get乞求

.setcheckurl(checkurl)// 必填:数据革新接口,本领有重载带参数的setcheckurl(checkurl, params)

.setdialoglayout(r.layout.custom_update_dialog)//自设置的革新dialog

.setcheckjsonparser(newparsedata() {// 必填:用来从数据革新接口获得的数据response中。领会出update范例。再不框架里面处置

@override

publicupdate parse(string response) {

log.d(tag,"response="+ response);

//领会json数据

gson gson =newgson();

updatebean updatebean = gson.fromjson(response, updatebean.class);

updatebean.databean data = updatebean.getdata();

update update =newupdate();

update.setforce(data.isforce());

update.setapksize(data.getv_size());

update.setupdatecontent(data.getupdate_content());

update.setupdateurl(data.getdownload_url());

update.setversioncode(integer.parseint(data.getv_code()));

update.setversionname(data.getv_name());

returnupdate;//只能归来update典型,要不报错,以是咱们要把领会的javabean数据赋值给update,而后将update归来

}

});

}

}

checkurl:是放在tomcat中的

复制代码 代码如次:

private static string checkurl = "http://192.168.1.11:8080/cmcc/jsoninfo";

jsoninfo:

?

1

2

3

4

5

6

7

8

9

10

11

12

{

"code": 0,

"data": {

"download_url":"http://192.168.1.11:8080/cmcc/demo.apk ",

"force":false,

"update_content":"尝试革新接口",

"v_code": 10,

"v_name":"v1.1",

"v_sha1":"7db76e18ac92bb29ff0ef012abfe178a78477534",

"v_size": 12365909

}

}

step2-2 领会革新接口归来的数据

上头我用的是gson.jar,以是module的build.gradle还须要增添gson

?

1

2

3

4

5

6

7

dependencies {

...

1.update:jjdxm-update:1.0.5'

1.download:jjdxm-download:1.0.3'

compile 'com.google.code.gson:gson:2.7'

...

}

javabean类updatebean,径直创造这个类,右键generate—>gsonformat—>将json数据复制到编纂框中—>ok—>选中那些参数,即可天生set()

+ get()本领。

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

怎样禁止安卓app强制更新,禁止app强制更新方法图2

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

publicclassupdatebean {

/**

* code : 0

* data : {"download_url":"http://115.159.45.251/software/feibei_live1.0.0.16070810_zs.apk ","force":false,"update_content":"尝试革新接口","v_code":"10","v_name":"v1.0.0.16070810","v_sha1":"7db76e18ac92bb29ff0ef012abfe178a78477534","v_size":12365909}

*/

privateintcode;

/**

* download_url : http://115.159.45.251/software/feibei_live1.0.0.16070810_zs.apk

* force : false

* update_content : 尝试革新接口

* v_code : 10

* v_name : v1.0.0.16070810

* v_sha1 : 7db76e18ac92bb29ff0ef012abfe178a78477534

* v_size : 12365909

*/

privatedatabean data;

publicintgetcode() {

returncode;

}

publicvoidsetcode(intcode) {

this.code = code;

}

publicdatabean getdata() {

returndata;

}

publicvoidsetdata(databean data) {

this.data = data;

}

publicstaticclassdatabean {

privatestring download_url;

privatebooleanforce;

privatestring update_content;

privatestring v_code;

privatestring v_name;

privatestring v_sha1;

privateintv_size;

publicstring getdownload_url() {

returndownload_url;

}

publicvoidsetdownload_url(string download_url) {

this.download_url = download_url;

}

publicbooleanisforce() {

returnforce;

}

publicvoidsetforce(booleanforce) {

this.force = force;

}

publicstring getupdate_content() {

returnupdate_content;

}

publicvoidsetupdate_content(string update_content) {

this.update_content = update_content;

}

publicstring getv_code() {

怎样禁止安卓app强制更新,禁止app强制更新方法图3

returnv_code;

}

publicvoidsetv_code(string v_code) {

this.v_code = v_code;

}

publicstring getv_name() {

returnv_name;

}

publicvoidsetv_name(string v_name) {

this.v_name = v_name;

}

publicstring getv_sha1() {

returnv_sha1;

}

publicvoidsetv_sha1(string v_sha1) {

this.v_sha1 = v_sha1;

}

publicintgetv_size() {

returnv_size;

}

publicvoidsetv_size(intv_size) {

this.v_size = v_size;

}

}

}

step3:在application中oncreate()本领中挪用

1

updateconfig.init(this);

step4:在mainactivity的oncrete()中查看革新

1

2

3

4

5

6

7

8

9

10

11

updatehelper.getinstance()

.setupdatetype(updatetype.autoupdate)//机动查看革新

.setforcelistener(newforcelistener() {//强迫革新监听,true则退出app

@override

publicvoidonusercancel(booleanforce) {

if(force) {

finish();

}

}

})

.check(mainactivity.this);

源码载入:updatedemo2

第二种:

确定versioncode,xutils实行载入

按照versioncode确定能否弹出革新dialog,须要革新的话,用户点击“决定”,运用xutils实行载入,progressdialog表露载入进度,载入实行后,弹出能否安置的dialog,是:安置app,否:退出(mainactivity.this.finish())。

功效图

step1: 乞求革新接口,按照versioncode确定能否革新

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

// 获得当地本子号

packagemanager packagemanager = getpackagemanager();

try{

packageinfo = packagemanager.getpackageinfo(getpackagename(),0);

}catch(namenotfoundexception e) {

e.printstacktrace();

}finally{

nativevversioncode = packageinfo.versioncode;

}

// 获得效劳器本子号

httputils http =newhttputils();

string url ="http://192.168.8.101:8080/qq/jsoninfo";

http.send(httpmethod.post, url,newrequestcallback<string>() {

@override

publicvoidonfailure(httpexception exception, string msg) {

toastutil.showshorttoast(getbasecontext(),"获得效劳器本子波折,请查看搜集,\n app5秒后将退出");

handler.sendemptymessagedelayed(123,5000);

}

@override

publicvoidonsuccess(responseinfo<string> respinseinfo) {

try{

jsonobject obj =newjsonobject(respinseinfo.result);

remoteversioncode = obj.getint("versioncode");

if(remoteversioncode > nativevversioncode) {

toastutil.showlongtoast(getbasecontext(),"慰问装最新的本子");

downloadapp();

}

}catch(jsonexception e) {

e.printstacktrace();

}

}

});

privatehandler handler =newhandler(){

publicvoidhandlemessage(message msg) {

if(msg.what ==123) {

mainactivity.this.finish();

}

};

};

step2: 载入最新本子

怎样禁止安卓app强制更新,禁止app强制更新方法图4

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

protectedvoiddownloadapp() {

target = environment.getexternalstoragedirectory().getabsolutepath() +"/qq.apk";

string url ="http://192.168.8.101:8080/qq/qq.apk";

httputils http =newhttputils();

http.download(url, target,newrequestcallback<file>() {

@override

publicvoidonfailure(httpexception exception, string msg) {

toastutil.showshorttoast(getbasecontext(),"载入波折");

}

@override

publicvoidonsuccess(responseinfo<file> responseinfo) {

dialog.dismiss();

toastutil.showshorttoast(getbasecontext(),"载入胜利");

// 安置apk

installapk();

}

@override

publicvoidonloading(longtotal,longcurrent,booleanisuploading) {

super.onloading(total, current, isuploading);

initprogressdialog(total,current);

}

});

}

step3: 安置apk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

protectedvoidinstallapk() {

newalertdialog.builder(mainactivity.this)

.settitle("本子革新")

.setmessage("最新本子正在革新中...")

.setcancelable(false)

.setpositivebutton("决定",newdialoginterface.onclicklistener() {

@override

publicvoidonclick(dialoginterface dialog,intwhich) {

怎样禁止安卓app强制更新,禁止app强制更新方法图5

//安置app

intent intent =newintent();

intent.setaction("android.intent.action.view");

intent.addcategory("android.intent.category.default");

uri data = uri.parse("file://"+ target);

intent.setdataandtype(data,"application/vnd.android.package-archive");

startactivity(intent);

mainactivity.this.finish();

}

})

怎样禁止安卓app强制更新,禁止app强制更新方法图6

.setnegativebutton("退出",newdialoginterface.onclicklistener() {

@override

publicvoidonclick(dialoginterface dialog,intwhich) {

mainactivity.this.finish();

}

}).show();

}

step4: 挪用体例安置界面

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.