亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

APP更新

2019-11-09 17:25:08
字體:
來源:轉載
供稿:網友

import android.app.DownloadManager; import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.database.Cursor; import android.net.Uri;

import java.io.File;

public class DownloadManagerHelp {

// http://dworkstudio.com/xalbums/update/update.xmlpublic static final String BASE_PATH = "/xalbums/download/";PRivate static final String TAG = DownloadManagerHelp.class.getSimpleName();public String getUri() { return uri;}public void setUri(String uri) { this.uri = uri;}private String filename = "xalbums.apk";//UpdateVersionTask.APK_NAME;private Context context;private DownloadManager downloadManager;private String uri;private long downloadId = 0;private DownloadManagerHelp(Context c) { this.context = c; downloadManager = (DownloadManager) c .getSystemService(Context.DOWNLOAD_SERVICE);}private static DownloadManagerHelp instance;public static DownloadManagerHelp getInstance(Context c) { if (instance == null) { instance = new DownloadManagerHelp(c); } return instance;}private long getDownloadId(String dirType) { downloadId = 0; try { downloadId = downloadManager.enqueue(new DownloadManager.Request( Uri.parse(uri)) .setAllowedNetworkTypes( DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI) .setAllowedOverRoaming(false) .setTitle(context.getString(R.string.app_name)) .setVisibleInDownloadsUi(true) .setDestinationInExternalPublicDir(dirType, filename)); } catch (Exception e) { // download failed when download manager was disable, so we need create download thread by us. FileDownloadThread.getInstance(context).setUrl(uri); FileDownloadThread.getInstance(context).startDownload(); FLog.i(TAG, "getDownloadId throw error,create download thread by us to try again"); } return downloadId;}private void enableDownloadManager() { try { //Open the specific App Info page: Intent intent = new Intent(android.provider.Settings.ACTION_application_DETAILS_SETTINGS); intent.setData(Uri.parse("package:" + "com.android.providers.downloads")); context.startActivity(intent); } catch (ActivityNotFoundException ex) { ex.printStackTrace(); //Open the generic Apps page: Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS); context.startActivity(intent); }}public void startDownload() { if (downloadManager != null) { FLog.i(TAG, "downlaod strat."); UserSetting.setBoolean(context, Constants.DOWNLOAD_START, true); // 解決K900無法自動升級問題 downloadId = getDownloadId(BASE_PATH); context.registerReceiver(downloadReceiver, new IntentFilter( DownloadManager.ACTION_DOWNLOAD_COMPLETE)); }}public String getFilename() { return filename;}public void setFilename(String filename) { this.filename = filename;}private BroadcastReceiver downloadReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(downloadId); Cursor c = downloadManager.query(query); if (c != null && c.moveToFirst()) { int status = c.getInt(c .getColumnIndex(DownloadManager.COLUMN_STATUS)); String filename = c.getString(c .getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME)); switch (status) { case DownloadManager.STATUS_PAUSED: case DownloadManager.STATUS_PENDING: case DownloadManager.STATUS_RUNNING: case DownloadManager.STATUS_SUCCESSFUL: File file = new File(filename); FLog.i("download", "filename:" + filename); installApk(file); break; case DownloadManager.STATUS_FAILED: stopDownload(); break; } } if (c != null) { c.close(); } }};protected void installApk(File file) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); FLog.i(TAG, "downlaod ok ,and install the application.");}public void stopDownload() { if (downloadId != 0) { downloadManager.remove(downloadId); context.unregisterReceiver(downloadReceiver); downloadId = 0; }}

}

2: import android.annotation.SuppressLint; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.view.View; import android.widget.RemoteViews;

import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.text.SimpleDateFormat; import java.util.Date;

@SuppressLint(“NewApi”) public class FileDownloadThread extends Thread {

private String url;private String path = Constants.ROOT_PATH;private String savePath = path + "xalbums.apk";private boolean run = false;private final static int DOWNLOAD_ID = 201;private Context mContext;private Notification.Builder builder;private NotificationManager manager;private FileDownloadThread(Context context) { this.mContext = context; manager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); builder = new Notification.Builder(mContext);}private static FileDownloadThread instance = null;public static FileDownloadThread getInstance(Context context) { if (instance == null) { instance = new FileDownloadThread(context); } return instance;}public void sendNotification(int progress, boolean isSuccess) { RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.download_notification); SimpleDateFormat format = new SimpleDateFormat("HH:mm"); Date d1 = new Date(); String t1 = format.format(d1); Intent appIntent = new Intent(Intent.ACTION_MAIN); appIntent.addCategory(Intent.CATEGORY_LAUNCHER); appIntent.setComponent(new ComponentName(mContext.getPackageName(), "com.lenovo.linkit.HomeActivity")); appIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent mainPiIntent = PendingIntent.getActivity(mContext, 0, appIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(mainPiIntent); builder.setContentTitle(mContext .getString(R.string.update_download_title)); builder.setSmallIcon(R.drawable.ic_launcher); String text = String.format("%2d", progress) + "%"; rv.setTextViewText(R.id.notification_desc, text); builder.setContentText(text); builder.setWhen(System.currentTimeMillis()); builder.setOngoing(false); rv.setTextViewText(R.id.notification_title, mContext.getString(R.string.update_download_title)); if (progress != 100 && isSuccess) { rv.setViewVisibility(R.id.content_view_progress, View.VISIBLE); rv.setViewVisibility(R.id.notification_desc, View.GONE); builder.setOngoing(true); rv.setProgressBar(R.id.content_view_progress, 100, progress, false); } else if (isSuccess) { rv.setViewVisibility(R.id.notification_desc, View.VISIBLE); rv.setViewVisibility(R.id.content_view_progress, View.GONE); rv.setTextViewText(R.id.notification_desc, mContext.getString(R.string.update_download_ok_start_install)); } else { rv.setViewVisibility(R.id.notification_desc, View.VISIBLE); rv.setViewVisibility(R.id.content_view_progress, View.GONE); rv.setTextViewText(R.id.notification_desc, mContext.getString(R.string.update_download_faile_please_retry)); } rv.setTextViewText(R.id.notification_time, t1); builder.setContent(rv); builder.setTicker(mContext.getString(R.string.update_download_title)); Notification notification = builder.build(); notification.contentView = rv; manager.notify(DOWNLOAD_ID, notification);}public void startDownload() { if (run == false) { new Thread(this).start(); }}@Overridepublic void run() { super.run(); URL u; try { run = true; sendNotification(0, true); u = new URL(url); HttpURLConnection conn = (HttpURLConnection) u.openConnection(); conn.setConnectTimeout(5000); double fileSize = conn.getContentLength(); InputStream is = conn.getInputStream(); File pathFile = new File(path); if (!pathFile.exists()) { pathFile.mkdir(); } File file = new File(savePath); if (!file.exists()) { file.createNewFile(); } FileOutputStream fos = new FileOutputStream(file); BufferedInputStream bis = new BufferedInputStream(is); byte[] buffer = new byte[1024]; int len; double total = 0; double pcent = 0; while ((len = bis.read(buffer)) != -1) { fos.write(buffer, 0, len); total += len; double percent = (int) ((total * 100 / fileSize)); if (percent - pcent >= 1.0) { pcent = percent; sendNotification((int) percent, true); } } sendNotification(100, true); fos.close(); bis.close(); is.close(); installApk(file); manager.cancel(DOWNLOAD_ID); run = false; } catch (Exception e) { run = false; sendNotification(0, false); }}public String getUrl() { return url;}public void setUrl(String url) { this.url = url;}protected void installApk(File file) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); mContext.startActivity(intent);}

}

public class Constants {

public static final String ENTRY_ALL_PHOTO_FRAGMENT_NULL = "entry_all_photo_fragment_null" ;public static final String ENTRY_ALL_PHOTO_FRAGMENT_BIG_SIZE = "entry_all_photo_fragment_big_size" ;public static final String ENTRY_ALL_PHOTO_FRAGMENT_SIMILAR = "entry_all_photo_fragment_similar" ;public static final String ENTRY_ALL_PHOTO_FRAGMENT_NO_USE = "entry_all_photo_fragment_no_use" ;public static final String FULL_REMIND_CLOSED = "full_remind_closed";public static final String RIGHT_REMIND_CLOSED = "right_remind_closed";public static final String FULL_REMIND_FIRST_SHOW = "full_remind_first_show";public static final String RIGHT_REMIND_FIRST_SHOW = "right_remind_first_show";public static final String APPLICATION_FRIST_ARRANGE = "application_frist_arrange";

}

重點內容


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
色伦专区97中文字幕| 亚洲一区二区三区乱码aⅴ| 精品偷拍一区二区三区在线看| 欧美日韩性生活视频| 亚洲免费精彩视频| 亚洲三级黄色在线观看| 欧美麻豆久久久久久中文| 国产成人小视频在线观看| 97精品久久久中文字幕免费| 在线观看日韩www视频免费| 亚洲欧洲国产精品| 亚洲国产小视频在线观看| 欧美肥臀大乳一区二区免费视频| 中文字幕亚洲第一| 亚洲第一福利在线观看| 亚洲精品中文字| 黄色成人av在线| 国产综合视频在线观看| 国产精品久久久久久超碰| 日韩欧美精品免费在线| 欧美精品videos性欧美| 国产一区二区三区免费视频| 亚洲片国产一区一级在线观看| 日韩精品欧美国产精品忘忧草| 欧美日本黄视频| 深夜福利亚洲导航| 91免费的视频在线播放| 国产精品成人av在线| 日韩av电影院| 欧美成人精品在线观看| 91免费视频国产| 久久精品夜夜夜夜夜久久| 国产精品1区2区在线观看| 九九精品在线播放| 欧美激情视频一区二区| 国产精品久久久久99| 亚洲国产精品悠悠久久琪琪| 日韩电影免费在线观看中文字幕| 久久天天躁日日躁| 国产欧美日韩视频| 国产91精品在线播放| 日韩美女在线播放| 欧美大尺度激情区在线播放| 亚洲欧洲日产国码av系列天堂| 国产精品小说在线| 久久久久久国产精品三级玉女聊斋| 久久久久久久久久久网站| 亚洲视频在线免费看| 亚洲精品福利资源站| 亚洲人成网站在线播| 上原亚衣av一区二区三区| 久久亚洲成人精品| 91在线国产电影| 欧美成人午夜免费视在线看片| 国产精品中文字幕在线| 国产精品免费一区| 日韩av在线看| 91精品国产综合久久香蕉的用户体验| 久久久久久久成人| 91午夜在线播放| 国产精品av在线播放| 欧美日韩亚洲一区二区| 日韩美女视频在线观看| 亚洲人免费视频| 精品久久久久久久久久| 久久成人精品一区二区三区| 国产自摸综合网| 国产精品v日韩精品| 日韩亚洲国产中文字幕| 一区二区三区亚洲| 欧美精品国产精品日韩精品| 欧美性猛交xxxx富婆弯腰| 韩国三级日本三级少妇99| 久久久爽爽爽美女图片| 午夜精品久久久久久久男人的天堂| 国产成人一区三区| 亚洲精品98久久久久久中文字幕| 国产性色av一区二区| 欧美又大又硬又粗bbbbb| 成人免费xxxxx在线观看| 欧美成人小视频| 国产亚洲欧洲高清一区| 97欧美精品一区二区三区| 97久久精品国产| 96精品视频在线| 亚洲国产欧美在线成人app| 色播久久人人爽人人爽人人片视av| 91精品国产自产在线| 久久精品视频免费播放| 91青草视频久久| 亚洲精品电影久久久| 在线亚洲欧美视频| 久久久这里只有精品视频| 亚洲视频在线播放| 色偷偷噜噜噜亚洲男人| 日韩国产在线看| 91中文精品字幕在线视频| 欧美综合第一页| 欧美国产日韩xxxxx| 国产精品国产三级国产专播精品人| 精品国偷自产在线视频99| 亚洲天堂免费观看| 精品视频久久久久久久| 日韩精品999| 欧美疯狂xxxx大交乱88av| 国产亚洲欧洲黄色| 九色精品免费永久在线| 亚洲欧美日韩中文在线| 中文字幕亚洲第一| 日本亚洲精品在线观看| 亚洲视频电影图片偷拍一区| 97精品久久久| 久久久久久91香蕉国产| 久久久久久久久久婷婷| 久久精品91久久香蕉加勒比| 国产精品18久久久久久麻辣| 一区二区欧美亚洲| 精品调教chinesegay| 国产精品久久久| 欧美大片免费观看| 亚洲视频axxx| 国产精品私拍pans大尺度在线| 日韩大片免费观看视频播放| 69久久夜色精品国产69乱青草| 精品人伦一区二区三区蜜桃网站| 亚洲综合精品伊人久久| 亚洲欧美国产制服动漫| 亚洲系列中文字幕| 中文字幕在线观看日韩| 中文字幕亚洲天堂| 日韩激情在线视频| 日韩中文字幕在线| 91成人在线观看国产| 成人在线中文字幕| 俺去了亚洲欧美日韩| 亚洲国产小视频在线观看| 亚洲综合一区二区不卡| 日韩有码在线视频| 欧美另类在线播放| 国产精品综合不卡av| 亚洲国产精品高清久久久| 国产一区二区三区免费视频| 亚洲香蕉伊综合在人在线视看| 亚洲精品v欧美精品v日韩精品| 欧美高清视频免费观看| 欧美成人精品在线视频| 国产视频精品免费播放| 97久久精品人人澡人人爽缅北| 欧美国产日本高清在线| 欧美激情在线有限公司| 一区三区二区视频| 亚洲综合自拍一区| 国产精品第七十二页| 亚洲视频第一页| 国产深夜精品福利| 日韩av电影免费观看高清| 97**国产露脸精品国产| 国产中文欧美精品| 久久久久国色av免费观看性色| 国模叶桐国产精品一区| 国产精品一区二区女厕厕| 国产欧美精品一区二区三区-老狼| 北条麻妃一区二区在线观看| 欧美一区视频在线|