Exemplo n.º 1
0
 @Override
 public void onProgressUpdate(Integer... percentDownloaded) {
   LogUtil.e(TAG, "onProgressUpdate lengthDownloaded =" + (int) percentDownloaded[0]);
   mBuilder.setProgress(100, percentDownloaded[0], false);
   mBuilder.setContentText(
       mContext.getString(R.string.msg_update_version) + "(" + percentDownloaded[0] + "%)");
   mNotificationManager.notify(id, mBuilder.build());
 }
Exemplo n.º 2
0
  /** 安装apk */
  private void installApk() {
    String fileAbsolutePath = null;
    File apkfile = null;
    //        LogUtil.e(TAG, " Environment.getExternalStorageDirectory() = "+
    // Environment.getExternalStorageDirectory());
    //        LogUtil.e(TAG, " Environment.getDownloadCacheDirectory() = "+
    // Environment.getDownloadCacheDirectory());
    //        LogUtil.e(TAG, " Environment.getDataDirectory() = "+ Environment.getDataDirectory());

    if (Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
      fileAbsolutePath =
          Environment.getExternalStorageDirectory()
              + File.separator
              + filePath
              + File.separator
              + fileName;
      LogUtil.e(TAG, "MEDIA_MOUNTED + fileAbsolutePath = " + fileAbsolutePath);
    } else if (Environment.getDataDirectory() != null) {
      String dataDir = Environment.getDataDirectory().toString();
      fileAbsolutePath = dataDir + File.separator + fileName;
    } else if (Environment.getDownloadCacheDirectory() != null) {
      String downloadCacheDir = Environment.getDownloadCacheDirectory().toString();
      fileAbsolutePath = downloadCacheDir + File.separator + fileName;
    } else {
      LogUtil.e(TAG, mContext.getString(R.string.error_no_usable_storage));
    }

    // LogUtil.e(TAG, "fileAbsolutePath = " + fileAbsolutePath);
    if (fileAbsolutePath != null) apkfile = new File(fileAbsolutePath);
    if (apkfile != null && !apkfile.exists()) {
      return;
    }
    // LogUtil.e(TAG, "apkfile.getAbsolutePath() = " + apkfile.getAbsolutePath());
    Intent i = new Intent(Intent.ACTION_VIEW);
    // 安装,如果签名不一致,可能出现程序未安装提示
    i.setDataAndType(
        Uri.fromFile(new File(apkfile.getAbsolutePath())),
        "application/vnd.android.package-archive");
    mContext.startActivity(i);
  }
Exemplo n.º 3
0
 @Override
 public void onPostExecute(Boolean isDownloadSuccess) {
   if (isDownloadSuccess) installApk();
   else LogUtil.e(TAG, "download update apk file failed");
 }