public void isFirstEntry(int year, int month, int day) {
    String today = Tools.getToday();
    String[] ymd = today.split("-");
    int currYear = Integer.parseInt(ymd[0]);
    int currMonth = Integer.parseInt(ymd[1]);
    int currDay = Integer.parseInt(ymd[2]);

    if (currYear != year || currMonth != month || currDay != day) {
      sp.update("year", currYear);
      sp.update("month", currMonth);
      sp.update("day", currDay);

      this.runAlertDialog();
    }
  }
Example #2
0
 /** 下载apk */
 public void getApk() {
   String downloadPath = Environment.getExternalStorageDirectory().getPath() + "/download";
   String fileName = url.substring(url.lastIndexOf("/"));
   Log.i("fileName", fileName);
   File file = new File(downloadPath);
   if (!file.exists()) {
     file.mkdir(); // 创建目录
   }
   HttpGet httpGet = new HttpGet(url);
   try {
     HttpResponse httpResponse = new DefaultHttpClient().execute(httpGet);
     if (httpResponse.getStatusLine().getStatusCode() == 200) {
       InputStream is = httpResponse.getEntity().getContent();
       FileOutputStream fos = new FileOutputStream(downloadPath + fileName);
       byte[] buffer = new byte[8192];
       int count = 0;
       while ((count = is.read(buffer)) != -1) {
         fos.write(buffer, 0, count);
       }
       fos.close();
       is.close();
       sp.update("guide", 0); // 重置新手指引
       sp.update(Constant.UNINSTALL, 1);
       Log.i("filelength", file.length() + "");
       //				if(file.length()){
       //					file.delete();
       //					Toast.makeText(context, "下载失败", 1).show();
       //				}else{
       installApk(downloadPath + fileName);
       //				}
       // MainActivityGroup.instance.showNotification("下载完成","下载完成","文件完成...",R.drawable.download,R.drawable.download);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  public void runAlertDialog() {
    final String downloadUrl = sp.get("url", "");
    // String strNetworkVersion = sp.get("network_version", "");
    String description = sp.get("description", "");
    if (description.contains("wr")) {
      description = description.replace("wr", "\n");
    }
    if (AppUtils.getFramework().getService(IUserUsageDataRecorder.class) != null) {
      AppUtils.getFramework()
          .getService(IUserUsageDataRecorder.class)
          .doRecord(ActivityID.UPDATEDIALOG.ordinal());
    }

    Intent t = new Intent(context, ConfirmDialogActivity.class);
    ClientInfo clientInfo = new ClientInfo();

    clientInfo.setDescription(description);
    clientInfo.setUrl(downloadUrl);

    t.putExtra(Constant.DIALOG_KEY, Constant.VERSION);
    t.putExtra(Constant.CLIENT_INFO, clientInfo);
    t.putExtra(Constant.PUSH_IN, "iampush");
    context.startActivity(t);

    // new AlertDialog.Builder(context)
    // // .setIcon(R.drawable.ic_launcher)
    // .setTitle("发现新版本!")
    // .setMessage(
    // "\n更新内容:\n" + description)
    // .setPositiveButton("立即升级",
    // new DialogInterface.OnClickListener() {
    // public void onClick(DialogInterface dialog,
    // int which) {
    // // sd卡是否可用,并且,是否为可读写
    // if (Environment.getExternalStorageState()
    // .equals(Environment.MEDIA_MOUNTED)) {
    //
    // if (!TextUtils.isEmpty(downloadUrl)) {
    // // ApkInstall install = new ApkInstall(
    // // context);
    // if (AppUtils.getFramework().getService(IUserUsageDataRecorder.class)
    // != null) {
    // AppUtils.getFramework().getService(IUserUsageDataRecorder.class).doRecord(ActivityID.UPDATENOW.ordinal());
    // }
    // Intent t = new Intent(context,
    // DownAPK.class);
    // t.putExtra("downurl", downloadUrl);
    // context.startService(t);
    // // if(Tools.hasNetwork(context)){
    // // install.start(downloadUrl);
    // // Tools.showToast(context,
    // // "正在下载,请稍候...");
    // // }else{
    // // Tools.showToast(context, "请检查网络...");
    // // }
    // } else {
    // Tools.showToast(context, "未获取到下载地址!");
    // Log.v("downloadUrl", "下载地址为空");
    // }
    //
    // } else {
    // Tools.showToast(context, "请检查SD卡是否可用后重试!");
    // }
    //
    // }
    // })
    // .setNegativeButton("稍候升级",
    // new DialogInterface.OnClickListener() {
    // public void onClick(DialogInterface dialog,
    // int which) {
    // }
    // }).show();
  }
 public MyAlertDialog(Context context) {
   this.sp = ManagerSP.getInstance(context);
   this.context = context;
 }
Example #5
0
 public ApkInstall(Context context) {
   this.context = context;
   sp = ManagerSP.getInstance(context);
 }