找传奇、传世资源到传世资源站!

android APP版本更新(科大讯飞)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

android APP版本更新(科大讯飞) Android平台开发-第1张android APP版本更新(科大讯飞) Android平台开发-第2张android APP版本更新(科大讯飞) Android平台开发-第3张
package com.test.sample;import java.io.File;import android.annotation.SuppressLint;import android.app.Activity;import android.content.Context;import android.content.pm.PackageInfo;import android.content.pm.PackageManager;import android.content.pm.PackageManager.NameNotFoundException;import android.os.Bundle;import android.os.Environment;import android.text.TextUtils;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;import android.widget.Toast;import com.iflytek.autoupdate.IFlytekUpdate;import com.iflytek.autoupdate.IFlytekUpdateListener;import com.iflytek.autoupdate.UpdateConstants;import com.iflytek.autoupdate.UpdateErrorCode;import com.iflytek.autoupdate.UpdateInfo;import com.iflytek.autoupdate.UpdateType;public class MainActivity extends Activity implements OnClickListener {private Button diag;private Button noti;private Button deleteBtn;Context mContext;private IFlytekUpdate updManager;private Toast mToast;@SuppressLint("ShowToast")@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mContext = this.getApplicationContext();diag = (Button) findViewById(R.id.diaglog);diag.setOnClickListener(this);noti = (Button) findViewById(R.id.noti);noti.setOnClickListener(this);deleteBtn = (Button) findViewById(R.id.btn_delete);deleteBtn.setOnClickListener(this);TextView tx = (TextView)findViewById(R.id.textView1);try {PackageManager manager = mContext.getPackageManager();PackageInfo info = manager.getPackageInfo(mContext.getPackageName(), 0);tx.setText("" info.versionCode);} catch (NameNotFoundException e) {e.printStackTrace();}updManager = IFlytekUpdate.getInstance(mContext);updManager.setDebugMode(true);updManager.setParameter(UpdateConstants.EXTRA_WIFIONLY, "true");// 设置通知栏icon,默认使用SDK默认updManager.setParameter(UpdateConstants.EXTRA_NOTI_ICON, "false");mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);}@Overridepublic void onClick(View arg0) {switch (arg0.getId()) {case R.id.diaglog:updManager.setParameter(UpdateConstants.EXTRA_STYLE, UpdateConstants.UPDATE_UI_DIALOG);updManager.autoUpdate(MainActivity.this, updateListener);break;case R.id.noti:updManager.setParameter(UpdateConstants.EXTRA_STYLE, UpdateConstants.UPDATE_UI_NITIFICATION);updManager.autoUpdate(MainActivity.this, updateListener);break;case R.id.btn_delete:// 删除已下载的更新文件String path = "";if(Environment.MEDIA_MOUNTED.equalsIgnoreCase(Environment.getExternalStorageState())) {path = Environment.getExternalStorageDirectory() "/download/iFlyUpdate"; }if(TextUtils.isEmpty(path)) {showTip("文件路径不正确!");return;}File file = new File(path);delFile(file);showTip("文件已删除!");default:break;}}private IFlytekUpdateListener updateListener = new IFlytekUpdateListener() {@Overridepublic void onResult(int errorcode, UpdateInfo result) {if(errorcode == UpdateErrorCode.OK && result!= null) {if(result.getUpdateType() == UpdateType.NoNeed) {showTip("已经是最新版本!");return;}updManager.showUpdateInfo(MainActivity.this, result);}else{showTip("请求更新失败!\n更新错误码:" errorcode);}}};private void delFile(File deleteFile) {if(!deleteFile.exists()) {return;}if(!deleteFile.isDirectory()) {deleteFile.delete();} else {File[] fileList = deleteFile.listFiles();if(null == fileList || fileList.length<=0) {deleteFile.delete();return;}for(File file : fileList) {delFile(file);}deleteFile.delete();}}private void showTip(final String str) {runOnUiThread(new Runnable() {@Overridepublic void run() {mToast.setText(str);mToast.show();}});}}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复