private static void enqueueDownload(
      Context context,
      Uri uri,
      Uri destinationUri,
      String description,
      String mimeType,
      String mediaType,
      boolean wifiOnly) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      final DownloadManager dm =
          (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
      DownloadManager.Request request = new DownloadManager.Request(uri);

      request.setDestinationUri(destinationUri);
      request.setDescription(description);
      if (mediaType != null) {
        request.addRequestHeader("Accept", mediaType);
      }
      if (mimeType != null) {
        request.setMimeType(mimeType);
      }
      if (wifiOnly) {
        restrictDownloadToWifi(request);
      }
      request.setAllowedOverRoaming(false);

      dm.enqueue(request);
    } else {
      // HACK alert:
      // Gingerbread's DownloadManager needlessly rejected HTTPS URIs. Circumvent that
      // by building and enqueing the request to the provider by ourselves. This is safe
      // as we only rely on internal API that won't change anymore.
      ContentValues values = new ContentValues();
      values.put("uri", uri.toString());
      values.put("is_public_api", true);
      values.put("notificationpackage", context.getPackageName());
      values.put("destination", 4);
      values.put("hint", destinationUri.toString());
      if (mediaType != null) {
        values.put("http_header_0", "Accept:" + mediaType);
      }
      values.put("description", description);
      if (mimeType != null) {
        values.put("mimetype", mimeType);
      }
      values.put("visibility", 0);
      values.put("allowed_network_types", wifiOnly ? DownloadManager.Request.NETWORK_WIFI : ~0);
      values.put("allow_roaming", false);
      values.put("is_visible_in_downloads_ui", true);

      context.getContentResolver().insert(Uri.parse("content://downloads/my_downloads"), values);
    }
  }
示例#2
1
 /**
  * Download a file using Android download manager.
  *
  * @param url URL to download
  * @param fileName Destination file name
  * @param title Notification title
  * @param description Notification description
  */
 public static void downloadFile(
     Context context, String url, String fileName, String title, String description) {
   String authToken = PreferenceUtil.getAuthToken(context);
   DownloadManager downloadManager =
       (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
   DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
   request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
   request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
   request.addRequestHeader("Cookie", "auth_token=" + authToken);
   request.setTitle(title);
   request.setDescription(description);
   downloadManager.enqueue(request);
 }
 public void updateIitc(final String url) {
   final DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
   request.setDescription(getString(R.string.download_description));
   request.setTitle("IITCm Update");
   request.allowScanningByMediaScanner();
   final Uri fileUri =
       Uri.parse("file://" + getExternalFilesDir(null).toString() + "/iitcUpdate.apk");
   request.setDestinationUri(fileUri);
   // remove old update file...we don't want to spam the external storage
   deleteUpdateFile();
   // get download service and enqueue file
   final DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
   manager.enqueue(request);
 }
 @SuppressLint("NewApi")
 public static void download(
     Context context, String url, String savedFileName, String title, String desc) {
   DownloadManager downloadManager =
       (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
   String apkUrl =
       url; // "http://img.meilishuo.net/css/images/AndroidShare/Meilishuo_3.6.1_10006.apk";
   DownloadManager.Request request = new DownloadManager.Request(Uri.parse(apkUrl));
   request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, savedFileName);
   request.setTitle(title);
   request.setDescription(desc); // "餐厅管家,绿色免费"
   // request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
   request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
   // request.setMimeType("application/com.trinea.download.file");
   long downloadId = downloadManager.enqueue(request);
 }
示例#5
1
  public void enqueueFile(Uri fileUri) {
    String scheme = fileUri.getScheme();
    if (!"http".equals(scheme) && !"https".equals(scheme)) {
      Log.w(TAG, String.format("Ignoring not HTTP/HTTPS uri: %s", fileUri));
      return;
    }

    DownloadManager.Request request = new DownloadManager.Request(fileUri);
    String localFileName = fileUri.getLastPathSegment();
    request.setDescription(String.format("Downloading file %s...", localFileName));
    request.setTitle(localFileName);
    request.allowScanningByMediaScanner();
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, localFileName);

    downloadManager.enqueue(request);
  }
 @SuppressLint("NewApi")
 public void download(VersionInfo version) {
   initDownload();
   AppLog.out(TAG, "更新地址:" + HttpUrl.OSS + version.getSourceUrl(), AppLog.LEVEL_INFO);
   DownloadManager.Request request =
       new DownloadManager.Request(Uri.parse(HttpUrl.OSS + version.getSourceUrl()));
   request.setDestinationInExternalPublicDir(DOWNLOAD_FOLDER_NAME, version.getVersionName());
   request.setTitle(version.getVersionName());
   request.setDescription(getString(R.string.app_name));
   request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
   request.setVisibleInDownloadsUi(false);
   //        request.setMimeType(MMIMETYPE);
   downloadId = downloadManager.enqueue(request);
   /** save download id to preferences * */
   PreferencesUtils.putLong(getBaseContext(), KEY_NAME_DOWNLOAD_ID, downloadId);
   //        finish();
 }
    protected void doDownload(String url, String filename) {
      // String url = "url you want to download";
      DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
      request.setDescription(filename);
      request.setTitle("Stream Downloader");

      // in order for this if to run, you must use the android 3.2 to compile your app
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        request.allowScanningByMediaScanner();
        request.setNotificationVisibility(
            DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
      }
      request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);

      // get download service and enqueue file
      DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
      manager.enqueue(request);
    }
示例#8
1
  public static long requestDownload(Context context, String url) {
    Uri uri = Uri.parse(url);
    DownloadManager.Request request = new DownloadManager.Request(uri);
    request.setTitle(uri.getLastPathSegment());
    request.setDescription(context.getString(R.string.app_name));
    request.setVisibleInDownloadsUi(true);

    // in order for this if to run, you must use the android 3.2 to compile your app
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      request.allowScanningByMediaScanner();
      request.setNotificationVisibility(
          DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    }
    request.setDestinationInExternalPublicDir(
        Environment.DIRECTORY_DOWNLOADS, uri.getLastPathSegment());

    // get download service and enqueue file
    DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    return manager.enqueue(request);
  }
  private void downloadApk(VersionInfo info) {
    Log.d(TAG, "download apk:" + info.url);
    DownloadManager downloadManager;
    downloadManager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);

    Uri uri = Uri.parse(info.url);
    DownloadManager.Request request = new Request(uri);
    File downloadDir = new File(mDownloadPath);
    if (!downloadDir.exists()) {
      downloadDir.mkdirs();
    }

    request.setTitle(mContext.getString(R.string.app_name));
    request.setDescription(info.versionName);
    request.setNotificationVisibility(Request.VISIBILITY_VISIBLE);
    request.setDestinationUri(Uri.fromFile(new File(mDownloadPath, info.versionCode + ".apk")));
    mDownloadReference = downloadManager.enqueue(request);
    IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
    mContext.registerReceiver(mReceiver, filter);
  }
 @SuppressLint("NewApi")
 private void startDownload() {
   downloadId = PreferencesUtils.getLong(mContext, DOWNLOAD_KEY, DEFAULT_DOWNLOAD_ID);
   if (downloadId == DEFAULT_DOWNLOAD_ID) {
     DownloadManager.Request request = new DownloadManager.Request(Uri.parse(apkUrl));
     // 获取apk名称
     String apkName =
         mContext.getApplicationInfo().loadLabel(mContext.getPackageManager()).toString();
     // 设置下载地址
     request.setDestinationInExternalPublicDir(
         Constants.UPDATE_FILE_DIR, Constants.UPDATE_FILE_NAME);
     request.setTitle(apkName);
     request.setDescription("正在下载...");
     // 提示一直显示,下载完成后点击则消失
     request.setNotificationVisibility(
         DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
     request.setVisibleInDownloadsUi(false);
     // 加入下载队列
     downloadId = mDownloadManager.enqueue(request);
     PreferencesUtils.putLong(mContext, DOWNLOAD_KEY, downloadId);
   }
 }
示例#11
1
  public static long requestDownload(Context context, SermonItem item) {
    Uri downloadUri = Uri.parse(Const.BASE_URL + item.audioUrl);
    DownloadManager.Request request = new DownloadManager.Request(downloadUri);
    request.setTitle("설교 다운로드");
    request.setDescription(item.titleWithDate);
    request.setDestinationInExternalPublicDir(
        Environment.DIRECTORY_DOWNLOADS, item.titleWithDate + StringUtils.FILE_EXTENSION_MP3);
    //        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
    //            request.setShowRunningNotification(true);
    //        } else {
    //
    // request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    //        }

    DownloadManager downloadManager =
        (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    long downloadQueryId = downloadManager.enqueue(request);
    int res =
        DBManager.getInstance(context)
            .updateSermonDownloadStatus(
                item._id, downloadQueryId, SermonItem.DownloadStatus.DOWNLOAD_START);
    Logger.i(TAG, "update current item's download status result : " + res);
    return downloadQueryId;
  }
  @Override
  public void onCourseModuleSelected(final CourseModule module) {
    List<ModuleContent> contents = module.getContents();
    ModuleContent content = new ModuleContent();

    if (!contents.isEmpty()) {
      content = contents.get(0);
    }

    if ("resource".equalsIgnoreCase(module.getModname())) {

      /**
       * Files are stored in the folder /Ourvle/courses/Modified Course Name-COurse Id/files/ The
       * modified course name removes any uneccesary whitespace from the name along with some course
       * names may contain the colon The colon is a reserved character in the android library and
       * causes an illegal state exception when explicitly creating a file with that in the name
       *
       * <p>The android reserved characters for file names are {"|", "\\", "?", "*", "<", "\"", ":",
       * ">"};
       */
      String folderLocation =
          "/OurVLE/courses/"
              + mCourse.getShortname().trim().replaceAll(":", "-")
              + "-"
              + mCourse.getId()
              + "/files/"; // sub-folder definition

      File location = new File(Environment.getExternalStorageDirectory(), folderLocation);

      if (!location.exists()) {
        if (!location.mkdirs())
          Toast.makeText(this, "Error making directory to store file", Toast.LENGTH_LONG)
              .show(); // makes the subfolder
      }

      String fileLocation = location + "/" + content.getFilename();
      courseFile = new File(fileLocation);

      if (!courseFile.exists()) // checks if the file is not already present
      {
        Toast.makeText(
                getApplicationContext(), "Downloading File: " + module.getName(), Toast.LENGTH_LONG)
            .show();
        String token = SiteInfo.listAll(SiteInfo.class).get(0).getToken();
        final String url = content.getFileurl() + "&token=" + token;
        final DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));

        request.setDescription("Course file download");
        request.setTitle(module.getName());
        // in order for this if to run, you must use the android 3.2 to compile your app
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
          request.allowScanningByMediaScanner();
          request.setNotificationVisibility(
              DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        }
        request.setDestinationInExternalPublicDir(folderLocation, content.getFilename());

        // get download service and enqueue file
        final DownloadManager manager =
            (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
        manager.enqueue(request);

        // registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
      } else // open the file that is already present
      {
        openFile(courseFile);
      }
    } else if (module.getUrl() != null) {

      String url = module.getUrl();

      if (!url.startsWith("http://") && !url.startsWith("https://")) url = "http://" + url;

      url += ("?wstoken=" + siteInfo.getToken());

      Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
      startActivity(browserIntent);
    } else //noinspection StatementWithEmptyBody
    if ("label".equalsIgnoreCase(module.getModname())) {
      // do nothing
    } else {
      Log.d("resource", "invalid");
      Toast.makeText(
              getApplicationContext(),
              "This resource is not yet supported by OurVLE Mobile",
              Toast.LENGTH_SHORT)
          .show();
    }
  }
示例#13
1
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //    overridePendingTransition(R.anim.fadeinanimation, 0);
    setContentView(R.layout.activity_main);

    Backendless.setUrl(Defaults.SERVER_URL);
    Backendless.initApp(this, Defaults.APPLICATION_ID, Defaults.SECRET_KEY, Defaults.VERSION);

    mainScreen = findViewById(R.id.mainscreen);

    mlbbutton = findViewById(R.id.button1);
    nflbutton = findViewById(R.id.button2);
    nhlbutton = findViewById(R.id.button3);
    nbabutton = findViewById(R.id.button4);
    cfbbutton = findViewById(R.id.button5);
    cbbbutton = findViewById(R.id.button6);
    olybutton = findViewById(R.id.button7);

    //    String uri =
    // "https://api.backendless.com/B40D13D5-E84B-F009-FF57-3871FCA5AE00/v1/files/sportsreflinks.db";

    android.support.v7.app.ActionBar bar = getSupportActionBar();

    if (bar != null) {
      bar.setTitle("Sports Reference");
    }

    //  detector = new GestureDetector(this);

    prefs =
        this.getSharedPreferences("comapps.com.thenewsportsreference.app", Context.MODE_PRIVATE);

    boolean hasVisited = prefs.getBoolean("HAS_VISISTED_BEFORE", false);

    if (!hasVisited) {

      mlbbutton.setVisibility(View.INVISIBLE);
      nhlbutton.setVisibility(View.INVISIBLE);
      nbabutton.setVisibility(View.INVISIBLE);
      nflbutton.setVisibility(View.INVISIBLE);
      cfbbutton.setVisibility(View.INVISIBLE);
      cbbbutton.setVisibility(View.INVISIBLE);
      olybutton.setVisibility(View.INVISIBLE);

      /* //    Toast instructions = Toast.makeText(MainActivity.this,
      //            "Click for search.", Toast.LENGTH_LONG);
      //    instructions.setGravity(Gravity.CENTER, 0, -250);
      //    instructions.show();

      Toast instructions2 = Toast.makeText(MainActivity.this,
              "Click enter with no text in search box \n " +
                      "         to go to the main site.", Toast.LENGTH_LONG);
      instructions2.setGravity(Gravity.CENTER, 0, -200);
      instructions2.show();

      //   Toast instructions3 = Toast.makeText(MainActivity.this,
      //           "Touch above search box to close keyboard.", Toast.LENGTH_LONG);
      //   instructions3.setGravity(Gravity.CENTER, 0, -150);
      //   instructions3.show();*/

      prefs.edit().putBoolean("HAS_VISISTED_BEFORE", true).commit();

      downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);

      DownloadManager.Request request = new DownloadManager.Request(Uri.parse(downloadFileUrl));
      request.setTitle("Suggestions download.");
      request.setDescription("Suggestions database being downloaded...");

      request.setDestinationInExternalFilesDir(
          getApplicationContext(), "/dbase", "sportsreflinks.db");
      request.setNotificationVisibility(
          DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
      request.allowScanningByMediaScanner();
      // request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,
      // "sportsreflinks.db");

      /*  if (!hasVisited) {

           request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
           request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE);

      } else {

          request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);

      }*/

      String filePath = prefs.getString("filepath", "");

      Log.i(TAG, "file path is " + filePath);

      fileExist = doesFileExist(filePath);
      Log.i(TAG, "file exists is " + fileExist.toString());

      if (fileExist == true) {

        deleteFileIfExists(filePath);
      }

      myDownloadReference = downloadManager.enqueue(request);

      intentFilter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);

      receiverDownloadComplete =
          new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
              long reference = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);

              if (myDownloadReference == reference) {
                DownloadManager.Query query = new DownloadManager.Query();
                query.setFilterById(reference);
                Cursor cursor = downloadManager.query(query);

                cursor.moveToFirst();
                int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
                int status = cursor.getInt(columnIndex);
                int fileNameIndex = cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME);
                String saveFilePath = cursor.getString(fileNameIndex);

                fileExist = doesFileExist(saveFilePath);

                Log.i(TAG, "file exists download complete " + saveFilePath);

                prefs.edit().putString("filepath", saveFilePath).commit();

                int columnReason = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
                int reason = cursor.getInt(columnReason);

                mlbbutton.setVisibility(View.VISIBLE);
                nhlbutton.setVisibility(View.VISIBLE);
                nbabutton.setVisibility(View.VISIBLE);
                nflbutton.setVisibility(View.VISIBLE);
                cfbbutton.setVisibility(View.VISIBLE);
                cbbbutton.setVisibility(View.VISIBLE);
                olybutton.setVisibility(View.VISIBLE);

                //     mainScreen.setEnabled(true);

                //     mainScreen.setClickable(true);

              }
            }
          };
    }

    mlbbutton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            Intent intentbaseballsearch = new Intent();
            intentbaseballsearch.setClass(getApplicationContext(), MLBsearch.class);
            startActivity(intentbaseballsearch);
          }
        });

    nflbutton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            Intent intentfootballsearch = new Intent();
            intentfootballsearch.setClass(getApplicationContext(), NFLsearch.class);
            startActivity(intentfootballsearch);
          }
        });

    nhlbutton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            Intent intenthockeysearch = new Intent();
            intenthockeysearch.setClass(getApplicationContext(), NHLsearch.class);
            startActivity(intenthockeysearch);
          }
        });

    nbabutton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            Intent intentbasketballsearch = new Intent();
            intentbasketballsearch.setClass(getApplicationContext(), NBAsearch.class);
            startActivity(intentbasketballsearch);
          }
        });

    cfbbutton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            Intent intentcollegefootballsearch = new Intent();
            intentcollegefootballsearch.setClass(getApplicationContext(), CFBsearch.class);
            startActivity(intentcollegefootballsearch);
          }
        });

    cbbbutton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            Intent intentcollegebasketballsearch = new Intent();
            intentcollegebasketballsearch.setClass(getApplicationContext(), CBBsearch.class);
            startActivity(intentcollegebasketballsearch);
          }
        });

    olybutton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            Intent intentolympicssearch = new Intent();
            intentolympicssearch.setClass(getApplicationContext(), OLYsearch.class);
            startActivity(intentolympicssearch);
          }
        });
  }
  @SuppressLint("NewApi")
  private static void downloadMedia(Object sourceButton, Object mMedia) {
    Field contextField =
        XposedHelpers.findFirstFieldByExactType(sourceButton.getClass(), Context.class);
    if (mContext == null) {
      try {
        mContext = (Context) contextField.get(sourceButton);
      } catch (Exception e) {
        e.printStackTrace();
        log("Failed to get Context");
        return;
      }
    }

    log("Downloading media...");
    Object mMediaType = getObjectField(mMedia, "b");

    Field[] mMediaFields = mMedia.getClass().getDeclaredFields();
    for (Field iField : mMediaFields) {
      String fieldType = iField.getClass().getName();
      if (fieldType.contains("com.instagram.model") && !fieldType.contains("people")) {
        try {
          mMediaType = iField.get(mMedia);
        } catch (Exception e) {
          log("Failed to get MediaType class");
          Toast.makeText(
                  mContext,
                  ResourceHelper.getString(mContext, R.string.mediatype_error),
                  Toast.LENGTH_LONG)
              .show();
          e.printStackTrace();
          return;
        }
      }
    }

    Object videoType = getStaticObjectField(mMediaType.getClass(), "b");

    String linkToDownload;
    String filenameExtension;
    String descriptionType;
    int descriptionTypeId = R.string.photo;
    if (mMediaType.equals(videoType)) {
      linkToDownload = (String) getObjectField(mMedia, "E");
      filenameExtension = "mp4";
      descriptionType = "video";
      descriptionTypeId = R.string.video;
    } else {
      linkToDownload = (String) getObjectField(mMedia, "s");
      filenameExtension = "jpg";
      descriptionType = "photo";
      descriptionTypeId = R.string.photo;
    }

    // Construct filename
    // username_imageId.jpg
    descriptionType = ResourceHelper.getString(mContext, descriptionTypeId);
    String toastMessage = ResourceHelper.getString(mContext, R.string.downloading, descriptionType);
    Toast.makeText(mContext, toastMessage, Toast.LENGTH_SHORT).show();
    Object mUser = getObjectField(mMedia, "p");
    String userName = (String) getObjectField(mUser, "b");
    String userFullName = (String) getObjectField(mUser, "c");
    String itemId = (String) getObjectField(mMedia, "t");
    String fileName = userName + "_" + itemId + "." + filenameExtension;

    if (TextUtils.isEmpty(userFullName)) {
      userFullName = userName;
    }

    File directory =
        new File(
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
                    .getAbsolutePath()
                + "/Instagram");
    if (!directory.exists()) directory.mkdirs();

    String notificationTitle =
        ResourceHelper.getString(mContext, R.string.username_thing, userFullName, descriptionType);
    String description =
        ResourceHelper.getString(mContext, R.string.instagram_item, descriptionType);

    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(linkToDownload));
    request.setTitle(notificationTitle);
    request.setDescription(description);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
      request.allowScanningByMediaScanner();
      request.setNotificationVisibility(
          DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    }
    request.setDestinationInExternalPublicDir(
        Environment.DIRECTORY_DOWNLOADS, "Instagram/" + fileName);

    DownloadManager manager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
    manager.enqueue(request);
  }
示例#15
0
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    // TODO Auto-generated method stub
    Uri uri =
        Uri.parse(
            moeapk.ApkDownloadUrl(
                app_package,
                moeapk.current_apklist_vcode[position],
                moeapk.current_apklist_special[position]));
    // Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    // startActivity(intent);

    DownloadManager mgr = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
    DownloadManager.Request request = new DownloadManager.Request(uri);
    request.setDestinationInExternalPublicDir(
        "MoeApk",
        moeapk.current_apklist_appname[position]
            + "_"
            + moeapk.current_apklist_vname[position]
            + "_"
            + moeapk.current_apklist_sname[position]
            + ".apk");
    request.setAllowedNetworkTypes(
        DownloadManager.Request.NETWORK_MOBILE
            | DownloadManager.Request.NETWORK_WIFI); // 允许流量和wifi使用
    request.setAllowedOverRoaming(false); // 不允许在漫游时下载
    request.setMimeType("application/vnd.android.package-archive");
    request.setTitle(moeapk.current_apklist_appname[position]);
    request.setDescription("来自萌萌安卓的下载");
    request.setVisibleInDownloadsUi(true);
    long downloadid = mgr.enqueue(request);
    Toast.makeText(
            getApplicationContext(), "文件将保存在" + fileUtils.SDCARD + "MoeApk下", Toast.LENGTH_LONG)
        .show();
  }
示例#16
0
  public long downLoadFile(String httpUrl, String dir, String fileName) {
    mDir = dir;
    mFileName = fileName;

    File filePath = new File(dir);
    if (!filePath.exists()) {
      filePath.mkdirs();
    }

    File file = new File(dir + "/" + fileName);
    if (file.exists()) file.delete();

    DownloadManager manager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(httpUrl));
    request.setDestinationInExternalPublicDir(dir, fileName);

    request.setTitle("setTitle");
    request.setDescription("setDescription");

    /*android.permission.DOWNLOAD_WITHOUT_NOTIFICATION*/
    //
    // request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    //        request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
    //        request.setMimeType("application/cn.trinea.download.file");
    register(mContext);
    return manager.enqueue(request);
  }
 private void createRequest() {
   Uri uri = Uri.parse("http://www.inf.ufpr.br/vignatti/grade_2015-2-v1.pdf");
   mRequest = new DownloadManager.Request(uri);
   mRequest.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
   mRequest.setTitle("Grade BCC UFPR");
   mRequest.setDescription("Arquivo: grade_2015-2-v1.pdf");
   mRequest.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "grade_2015.pdf");
 }