bmob的自动升级报空指针

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/yuzui0810/article/details/52992744

bmob自然是很好的东西,但是如果你遇到这个,

11-01 09:22:20.880: E/AndroidRuntime(8102): Caused by: java.lang.NullPointerException

11-01 09:22:20.880: E/AndroidRuntime(8102): at cn.bmob.v3.update.UpdateResponse.Code(SourceFile:134)

但是你有没有什么好的解决思路,不如仅仅只是把AppVersion当做一个普通数据,自己做版本对比,利用BmobFile类的下载方法,下载好后自己去安装就好了。

				private void testUpdate() {
<span style="white-space:pre">		</span>PackageManager manager;
<span style="white-space:pre">		</span>PackageInfo info = null;
<span style="white-space:pre">		</span>manager = this.getPackageManager();
<span style="white-space:pre">		</span>try {
<span style="white-space:pre">			</span>info = manager.getPackageInfo(this.getPackageName(), 0);
<span style="white-space:pre">		</span>} catch (Exception e) {
<span style="white-space:pre">			</span>Log.e(TAG, e.getMessage());
<span style="white-space:pre">		</span>}
<span style="white-space:pre">		</span>BmobQuery<AppVersion> query = new BmobQuery<AppVersion>();
<span style="white-space:pre">		</span>query.addWhereGreaterThan("version_i", info.versionCode);
<span style="white-space:pre">		</span>query.findObjects(this, new FindListener<AppVersion>() {


<span style="white-space:pre">			</span>@Override
<span style="white-space:pre">			</span>public void onError(int arg0, String arg1) {
<span style="white-space:pre">				</span>// TODO Auto-generated method stub


<span style="white-space:pre">			</span>}


<span style="white-space:pre">			</span>@Override
<span style="white-space:pre">			</span>public void onSuccess(List<AppVersion> arg0) {
<span style="white-space:pre">				</span>AppVersion av = arg0.get(0);
<span style="white-space:pre">				</span>BmobFile file = av.getPath();
<span style="white-space:pre">				</span>LogUtil.e(TAG, file.getFilename());
<span style="white-space:pre">				</span>file.download(LauncherActivity.this,new File("/mnt/sdcard/xxx.apk"),
<span style="white-space:pre">						</span>new DownloadFileListener() {


<span style="white-space:pre">							</span>@Override
<span style="white-space:pre">							</span>public void onFailure(int arg0, String arg1) {
<span style="white-space:pre">								</span>LogUtil.e(TAG, "新版本下载失败:"+arg1);
<span style="white-space:pre">							</span>}


<span style="white-space:pre">							</span>@Override
<span style="white-space:pre">							</span>public void onSuccess(String arg0) {
<span style="white-space:pre">								</span>LogUtil.e(TAG, arg0);
<span style="white-space:pre">								</span>installApk();
<span style="white-space:pre">							</span>}


<span style="white-space:pre">						</span>});
<span style="white-space:pre">			</span>}
<span style="white-space:pre">		</span>});
<span style="white-space:pre">		</span>
<span style="white-space:pre">	</span>}

private void installApk() {
		String fileName = "/mnt/sdcard/xxx.apk"; 
		Intent intent = new Intent(Intent.ACTION_VIEW); 
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//		 intent.setDataAndType(Uri.parse("file://"+fileName), "application/vnd.android.package-archive"); 
		intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive"); 
		startActivityForResult(intent, 1);
	}


展开阅读全文

没有更多推荐了,返回首页