当前位置: 首页 > news >正文

彩票网站 模块设计师如何注册个人网站

彩票网站 模块,设计师如何注册个人网站,南宁网站建设专家,许昌市住房和城乡建设部网站文章目录 前言一、效果图二、实现步骤1.AndroidManifest权限申请2.activity实现3.有版本更新弹框UpdateappUtilDialog4.下载弹框DownloadAppUtils5.弹框背景图 总结 前言 对于做Android的朋友来说#xff0c;APP更新功能再常见不过了#xff0c;因为平台更新审核时间较长APP更新功能再常见不过了因为平台更新审核时间较长所以现在很多都会通过接口更新这里就记录一下吧欢迎各位讨论。 一、效果图 二、实现步骤 1.AndroidManifest权限申请 !--外置存储卡写入权限--uses-permission android:nameandroid.permission.WRITE_EXTERNAL_STORAGE /!--请求安装APK的权限--uses-permission android:nameandroid.permission.REQUEST_INSTALL_PACKAGES /!--读取删除SD卡权限--uses-permission android:nameandroid.permission.READ_EXTERNAL_STORAGE /!--修改删除SD卡权限--uses-permissionandroid:nameandroid.permission.MOUNT_UNMOUNT_FILESYSTEMStools:ignoreProtectedPermissions /uses-permission android:nameandroid.permission.READ_PRIVILEGED_PHONE_STATE ///application标签下加如下代码!-- 安卓7.0安装时需要,拍照需要的临时权限 --providerandroid:nameandroidx.core.content.FileProviderandroid:authorities这里是applicationId也就是包名.fileproviderandroid:exportedfalseandroid:grantUriPermissionstruemeta-dataandroid:nameandroid.support.FILE_PROVIDER_PATHSandroid:resourcexml/provider_paths //provider//这里的provider_paths文件放在xml文件下代码如下 ?xml version1.0 encodingutf-8? paths!--拍照需要的路径--external-pathnamecomxf.activity.provider.downloadpath. /external-files-path nameextfiles pathautoupdatecache/ /external-cache-path nameextcachs pathautoupdatecache/ /cache-path nameintcachs pathautoupdatecache/ /pathsexternal-path path namedownload//paths/paths2.activity实现 1.通过接口获取Javabean对象 public Integer id;public String version_name;//App版本名public Integer version_code;//版本编号public String content;//版本更新内容public String is_must_update;//是否需要强更新(0:否1:是)public String file_url;//app包的下载地址Overridepublic String toString() {return VersionUpgradeBean{ id id , version_name version_name \ , version_code version_code , content content \ , is_must_update is_must_update \ , file_url file_url \ };}2.获取到版本号后判断是否高于当前版本 if (versionbean.version_code MyApplication.getVersionCode(thisSetUpActivity)) {val myDialog UpdateappUtilDialog()myDialog.initDialog(thisSetUpActivity, versionbean)myDialog.buttonClickEvent(object : UpdateappUtilDialog.DialogButtonClick {override fun cilckComfirmButton(view: View?) {myDialog.Dismiss()//6.0才用动态权限if (Build.VERSION.SDK_INT Build.VERSION_CODES.M) {if (ContextCompat.checkSelfPermission(thisSetUpActivity,Manifest.permission.WRITE_EXTERNAL_STORAGE) ! PackageManager.PERMISSION_GRANTED) {// 申请读写内存卡内容的权限ActivityCompat.requestPermissions(thisSetUpActivity, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 123)} else {//授权成功if (FileUtils.createOrExistsDir(NetConst.baseFileName)) {val mUpdateManger DownloadAppUtils(thisSetUpActivity, versionbean.file_url, versionbean)mUpdateManger.checkUpdateInfo()}}} else {//授权成功if (FileUtils.createOrExistsDir(NetConst.baseFileName)) {val mUpdateManger DownloadAppUtils(thisSetUpActivity, versionbean.file_url, versionbean)mUpdateManger.checkUpdateInfo()}}}override fun cilckCancleButton(view: View?) {//点击取消按钮myDialog.Dismiss()}})}3.用户权限结果处理 /*** todo 对用户权限授予结果处理** param requestCode 权限要求码即我们申请权限时传入的常量 如 TAKE_PHOTO_PERMISSION_REQUEST_CODE* param permissions 保存权限名称的 String 数组可以同时申请一个以上的权限* param grantResults 每一个申请的权限的用户处理结果数组(是否授权)*/override fun onRequestPermissionsResult(requestCode: Int,permissions: ArrayString?,grantResults: IntArray) {super.onRequestPermissionsResult(requestCode, permissions, grantResults)when (requestCode) {123 - {//授权成功if (FileUtils.createOrExistsDir(NetConst.baseFileName)) {val mUpdateManger DownloadAppUtils(thisSetUpActivity, versionbean.file_url, versionbean)mUpdateManger.checkUpdateInfo()}}}}3.有版本更新弹框UpdateappUtilDialog 1.util代码 /*** Created by caoliulang* ❤* Creation time :2025/2/24* ❤* Function 更新app的Dialog*/ public class UpdateappUtilDialog {private TextView secondBtn, textvs;private ImageView tv_cancel;private AlertDialog alertDialog;private DialogButtonClick mClick;private TextView tv_desc;public interface DialogButtonClick {void cilckComfirmButton(View view);void cilckCancleButton(View view);}public void buttonClickEvent(DialogButtonClick bc) {if (bc ! null) {mClick bc;cilckEvent();}}public void initDialog(Context context, VersionUpgradeBean upbean) {alertDialog new AlertDialog.Builder(context).create();alertDialog.show();alertDialog.setCancelable(false);//调用这个方法时按对话框以外的地方不起作用。返回键 不作用 // alertDialog.setCanceledOnTouchOutside(false);//调用这个方法时按对话框以外的地方不起作用。返回键 有作用Window window alertDialog.getWindow();window.setContentView(R.layout.fragment_update_app);window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));tv_desc window.findViewById(R.id.tv_desc);tv_desc.setText(upbean.content);secondBtn window.findViewById(R.id.tv_ok);textvs window.findViewById(R.id.textvs);textvs.setText(upbean.version_name);tv_cancel window.findViewById(R.id.tv_cancel);//1不强制更新 2 强制更新 // if(upbean.getUpdateType().equals(2)){ // firstBtn.setVisibility(View.GONE); // }// //不关闭弹窗也能点击外部事件 // alertDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);String isqg upbean.is_must_update ;if (isqg.equals(true)) {tv_cancel.setVisibility(View.GONE);} else {tv_cancel.setVisibility(View.VISIBLE);}}public void cilckEvent() { // if (firstBtn ! null) { // firstBtn.setOnClickListener(new View.OnClickListener() { // Override // public void onClick(View v) { // alertDialog.dismiss(); // mClick.cilckCancleButton(v); // } // });secondBtn.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) { // alertDialog.dismiss();mClick.cilckComfirmButton(v);}});tv_cancel.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View view) {mClick.cilckCancleButton(view);}}); // }}public void Dismiss() {if (null ! alertDialog) {alertDialog.dismiss();}}}2.xml布局 ?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:background#01000000android:gravitycenterandroid:orientationverticalRelativeLayoutandroid:layout_width301dpandroid:layout_height400dpandroid:orientationverticalImageViewandroid:idid/iv_topandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:srcmipmap/lib_update_app_top_bg /TextViewandroid:idid/textnameandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginLeft16dpandroid:layout_marginTop55dpandroid:textstring/Newversionfoundandroid:textColor#2e2e2eandroid:textSize18dpandroid:textStylebold /TextViewandroid:idid/textvsandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_belowid/textnameandroid:layout_marginLeft16dpandroid:layout_marginTop5dpandroid:text1.0.0android:textColor#2e2e2eandroid:textSize16dpandroid:textStylebold /LinearLayoutandroid:layout_widthmatch_parentandroid:layout_height210dpandroid:layout_marginTop180dpandroid:orientationvertical!--这个地方需要设置可以滚动--ScrollViewandroid:layout_widthmatch_parentandroid:layout_height0dpandroid:layout_weight1android:paddingTop18dpandroid:paddingBottom5dpandroid:scrollbarsnoneTextViewandroid:idid/tv_descandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginLeft20dpandroid:layout_marginRight20dpandroid:lineSpacingExtra5dpandroid:text1.已知bug修复\n2.新功能增加\n3.性能优化android:textColorandroid:color/blackandroid:textSize14dp //ScrollViewLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginLeft20dpandroid:layout_marginRight20dpandroid:layout_marginBottom20dpandroid:orientationhorizontalTextViewandroid:idid/tv_okandroid:layout_widthmatch_parentandroid:layout_height44dpandroid:backgrounddrawable/jianbianlanseandroid:gravitycenterandroid:textstring/UPDATENOWandroid:textColor#ffffffandroid:textSize18dp //LinearLayout/LinearLayout/RelativeLayoutImageViewandroid:idid/tv_cancelandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginTop15dpandroid:srcmipmap/ico_sjgb //LinearLayout4.下载弹框DownloadAppUtils 1.util代码如下 *** Created by caoliulang* ❤* Creation time :2024/2/24* ❤* Function APP更新下载*/ public class DownloadAppUtils {// 应用程序Contextpublic static Activity mContext;private static final String savePath Environment.getExternalStorageDirectory().getAbsolutePath() / tdzr/Download/;// 保存apk的文件夹///storage/emulated/0/tdzr/Download/aidigital1.0.4.apkprivate static final String saveFileName savePath aidigital MyApplication.versionname .apk;// 进度条与通知UI刷新的handler和msg常量private ProgressBar mProgress;private TextView text_progress, textvs;private static final int DOWN_UPDATE 1;private static final int DOWN_OVER 2;private static final int INT_NOT 9;private String downlogdurl;//下载地址private int progress 0;// 当前进度private Thread downLoadThread; // 下载线程private boolean interceptFlag false;// 用户取消下载private AlertDialog dialog;private VersionUpgradeBean upbean;// 通知处理刷新界面的handlerSuppressLint(HandlerLeak)private Handler mHandler new Handler() {SuppressLint(HandlerLeak)Overridepublic void handleMessage(Message msg) {switch (msg.what) {case DOWN_UPDATE:mProgress.setProgress(progress); //设置第一进度text_progress.setText(progress %);break;case DOWN_OVER: // //1不强制更新 2 强制更新 // if(upbean.getUpdateType().equals(1)){ // dialog.dismiss(); // }dialog.dismiss();installApk();break;case INT_NOT:dialog.dismiss();FileUtils.deleteFile(saveFileName);//删除文件ToastUtils.showToast(mContext.getResources().getString(R.string.Networkconnectionfailed));break;}super.handleMessage(msg);}};public DownloadAppUtils(Activity context, String downlogdurl, VersionUpgradeBean upbean) {this.mContext context;this.downlogdurl downlogdurl;this.upbean upbean;System.out.println(过来了--1);}// 显示更新程序对话框供主程序调用public void checkUpdateInfo() {//判断本地是否存在已下载的apk有bug // if (FileUtils.isFileExists(saveFileName) true) { // //安装 // installApk(); // } else { // //下载 // showDownloadDialog(); // }//判断本地是否存在已下载的apkif (FileUtils.isFileExists(saveFileName) true) {//删除DeletFile.delete(savePath);}//下载showDownloadDialog();}//弹出更新进度条private void showDownloadDialog() {dialog new AlertDialog.Builder(mContext).create();dialog.show();dialog.setCancelable(false);View viewt View.inflate(mContext, R.layout.xiazai_two_dialog, null);Window window dialog.getWindow();window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));dialog.setContentView(viewt);mProgress viewt.findViewById(R.id.upprogressBar);text_progress viewt.findViewById(R.id.text_progress);text_progress.setText(0%);textvs viewt.findViewById(R.id.textvs);textvs.setText(upbean.version_name);ImageView tv_cancel viewt.findViewById(R.id.tv_cancel);String isqg upbean.is_must_update ;if (isqg.equals(true)) {tv_cancel.setVisibility(View.GONE);} else {tv_cancel.setVisibility(View.VISIBLE);}tv_cancel.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {FileUtils.deleteFile(saveFileName);//删除文件dialog.dismiss();interceptFlag true;}});downloadApk();}//安装apkprivate static void installApk() {File apkfile new File(saveFileName);if (!apkfile.exists()) {return;}Intent intent new Intent(Intent.ACTION_VIEW);//版本在7.0以上是不能直接通过uri访问的if (Build.VERSION.SDK_INT Build.VERSION_CODES.N) {// 由于没有在Activity环境下启动Activity,设置下面的标签intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//参数1 上下文, 参数2 Provider主机地址 和配置文件中保持一致 参数3 共享的文件Uri apkUri FileProvider.getUriForFile(mContext, 这里是applicationId也就是包名.fileprovider, apkfile);//添加这一句表示对目标应用临时授权该Uri所代表的文件intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);intent.setDataAndType(apkUri, application/vnd.android.package-archive);} else {intent.setDataAndType(Uri.fromFile(new File(saveFileName)),application/vnd.android.package-archive);}mContext.startActivity(intent);}//下载apkprivate void downloadApk() {System.out.println(url打印 downlogdurl);downLoadThread new Thread(mdownApkRunnable);downLoadThread.start();}private Runnable mdownApkRunnable new Runnable() {Overridepublic void run() {System.out.println(打印路径 saveFileName);URL url;try {url new URL(downlogdurl);HttpURLConnection conn (HttpURLConnection) url.openConnection();conn.setConnectTimeout(15000); //设置连接超时为15sconn.setReadTimeout(15000); //读取数据超时也是15sint code conn.getResponseCode();System.out.println(code打印 code);if (code 200) {conn.connect();int length conn.getContentLength();InputStream ins conn.getInputStream();if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {Toast.makeText(mContext, SD卡不可用~, Toast.LENGTH_SHORT).show();return;}File file new File(savePath);if (!file.exists()) {file.mkdir();}String apkFile saveFileName;File ApkFile new File(apkFile);if (!ApkFile.exists()) {ApkFile.createNewFile();}FileOutputStream outStream new FileOutputStream(ApkFile);int count 0;byte buf[] new byte[1024];do {int numread ins.read(buf);count numread;int s (int) (((float) count / length) * 100);if (progress ! s) {progress (int) (((float) count / length) * 100);// 下载进度mHandler.sendEmptyMessage(DOWN_UPDATE);}if (numread 0) {// 下载完成通知安装mHandler.sendEmptyMessage(DOWN_OVER);break;}outStream.write(buf, 0, numread);} while (!interceptFlag);// 点击取消停止下载outStream.close();ins.close();} else {mHandler.sendEmptyMessage(INT_NOT);}} catch (Exception e) {//这里报错因为路径不对正确路径storage/emulated/0/tdzr/Download/aidigital1.0.4.apkSystem.out.println(code打印--- e.toString());mHandler.sendEmptyMessage(INT_NOT);}}};2.下载弹框xml布局 ?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:background#01000000android:gravitycenterandroid:orientationverticalRelativeLayoutandroid:layout_width301dpandroid:layout_height400dpandroid:orientationverticalRelativeLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentImageViewandroid:idid/topimgandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:srcmipmap/lib_update_app_top_bg /TextViewandroid:idid/textnameandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginLeft16dpandroid:layout_marginTop55dpandroid:textstring/Newversionfoundandroid:textColor#2E2E2Eandroid:textSize18dpandroid:textStylebold /TextViewandroid:idid/textvsandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_belowid/textnameandroid:layout_marginLeft16dpandroid:layout_marginTop5dpandroid:text1.0.0android:textColor#2E2E2Eandroid:textSize16dpandroid:textStylebold //RelativeLayoutLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginTop250dpandroid:gravitycenter_horizontalandroid:orientationverticalTextViewandroid:idid/text_progressandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_gravitycenterandroid:text0%android:textColor#2e2e2eandroid:textSize16dpandroid:textStylebold /ProgressBarandroid:idid/upprogressBarstylestyle/Base.Widget.AppCompat.ProgressBar.Horizontalandroid:layout_widthmatch_parentandroid:layout_height18dpandroid:layout_marginStart15dpandroid:layout_marginTop15dpandroid:layout_marginEnd15dpandroid:layout_marginBottom15dpandroid:max100android:progress0android:progressDrawabledrawable/progressbar_h //LinearLayout/RelativeLayoutImageViewandroid:idid/tv_cancelandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginTop15dpandroid:srcmipmap/ico_sjgb / /LinearLayout3.progressbar_h(在drawable下新建文件) ?xml version1.0 encodingutf-8? layer-list xmlns:androidhttp://schemas.android.com/apk/res/androiditemandroid:idandroid:id/backgroundandroid:gravitycenter_vertical|fill_horizontalshape android:shaperectanglesize android:height20dp /solid android:color#E4E4E4 /corners android:radius10dp //shape/item!--第二进度条--itemandroid:idandroid:id/secondaryProgressandroid:gravitycenter_vertical|fill_horizontalscale android:scaleWidth100%shape android:shaperectanglesize android:height20dp /solid android:color#E4E4E4 /corners android:radius10dp //shape/scale/item!--第一进度条--itemandroid:idandroid:id/progressandroid:gravitycenter_vertical|fill_horizontalscale android:scaleWidth100%shape android:shaperectanglesize android:height20dp /solid android:color#217FFD /corners android:radius10dp //shape/scale/item/layer-list5.弹框背景图 总结 其实这功能挺简单的就是里面细节太多首先AndroidManifest加权限还要加providerprovider里面记得更改包名下载util里面的报名也是一样。其次判断版本是否更新最后更新下载安装即可得吃。
http://www.hkea.cn/news/14287424/

相关文章:

  • 打开网站弹出广告代码棋牌软件开发平台
  • 盘锦如何做百度的网站网站建设分金手指专业
  • dedecms 网站还原数据之后 乱码长沙好的网站建设公司哪家好
  • 株洲网站建设和制作网站上写个招贤纳士怎么做
  • 木方东莞网站建设技术支持乐清开发网站公司
  • 百色建设局网站北京+网站建设
  • 吉林集安市建设局网站国家建筑规范标准
  • 国外上市公司网站建设网站建设教程流程图
  • 番禺网站开发哪里好商务网站的建设阶段包括
  • 网站后台怎么做友情链接代做网站排名
  • 麻章手机网站建设网站机房建设流程
  • 郑州做网站找赢博科技广东新闻联播直播在线观看
  • 网站建设合理性做网站运营还是翻译
  • 网站运营顾问乐都企业网站建设
  • 做网站建设涉及哪些算法成都专业网站建设价格
  • 中国建设部官方网站鲁班奖做网站用那种数据库
  • 如何用nat123做网站东台网站建设
  • 广州 网站建设友链之家
  • 惠州网站设计定制网络推广运营
  • 凉山州住房与城乡建设局网站做网站成功
  • 电子商务类网站建设普陀建设网站
  • 网站seo优化很好徐州百度网络点赞一个公司网站备案吗
  • 可以做物理题的网站网站创建域名
  • 有哪些做文创产品的网站怎样查找自己建设的网站
  • 如何做英文网站网络工程师培训大约多少钱
  • 用tomcat做网站网络推广竞价外包
  • 做暧在线观看网站wordpress 区块链媒体
  • 资金盘网站开发公司哪里好满洲里做网站
  • jsq项目做网站枣庄网站建设多少钱
  • 贵阳做网站公司看优秀摄影做品的网站