无法在Android中以Android Q版本存储PDF

问题描述

当我在Android Studio中开发一个android应用程序时,我给了READ_STORAGEWRITE_STORAGE权限,但无法将pdf存储在android Q版本中,比Q版本小,它工作正常。 请帮我。我已经提到了代码

@SuppressLint("StaticFieldLeak")
private class API_DownloadStateapi extends AsyncTask < String,Void,String > {
  final String url;
  API_DownloadStateapi(String url) {
    this.url = url;
  }

  @Override
  protected String doInBackground(String...params1) {
    try {
      JSONObject jsonObject_sendingparams = new JSONObject();
      try {
        jsonObject_sendingparams.put("accountNumber",str_acc_number);
        jsonObject_sendingparams.put("cifNumber",str_cifnumber);

      } catch(JSONException ignored) {

}

      String str_jsonparams = String.valueOf(jsonObject_sendingparams.toString().replace("\\",""));
      RestTemplate restTemplate = new RestTemplate();
      restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
      restTemplate.getMessageConverters().add(new StringHttpMessageConverter());

      restTemplate.getMessageConverters().add(new ResourceHttpMessageConverter());
      HttpHeaders headers = RestTemplateHeaders.createHttpHeaders("downloadStatement_MOB",ctx);
      httpentity < String > entity = new httpentity < >(str_jsonparams,headers);
      response = restTemplate.postForEntity(url,entity,byte[].class);
      respo = new String(response.getBody());

    } catch(Exception eek) {

}
    return respo;
  }

  @Override
  protected void onPostExecute(String str) {
    CommonDialog.onProgressdismiss();
    try {

      InputStream input = new ByteArrayInputStream(response.getBody());
      File path = new File(Environment.getExternalStorageDirectory() + "/Download");
      photoName = "Statement.pdf";
      int num = 0;
      File file = new File(path,photoName);
      while (file.exists()) {
        num++;
        photoName = "Statement(" + num + ").pdf";
        file = new File(path,photoName);
      }
      bufferedoutputstream output = new bufferedoutputstream(new FileOutputStream(file));
      byte data[] = new byte[1024];
      long total = 0;
      int count;
      while ((count = input.read(data)) != -1) {
        total += count;
        output.write(data,count);
      }

      output.flush();
      output.close();
      input.close();
    } catch(IOException ignored) {}

  }

}

请帮助我解决此问题。这是路径:File path = new File(Environment.getExternalStorageDirectory() + "/Download");,但不能在Q版本中使用

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)