无法解决方法 ‘getExternalStoragePublicDirectory’。

huangapple go评论108阅读模式
英文:

cannot resolve method 'getExternalStoragePublicDirectory'

问题

  1. 我尝试保存捕获的图像但出现了类似标题的错误
  2. private File createPhotoFile(){
  3. File storageDir = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES + "/sidentanpic/");
  4. sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(storageDir)));
  5. try{
  6. if(storageDir.exists()){
  7. System.out.println("Folder tersedia");
  8. }else{
  9. storageDir.mkdir();
  10. System.out.println("Folder telah dibuat");
  11. }
  12. }catch(Exception e){
  13. e.printStackTrace();
  14. }
  15. String name = new SimpleDateFormat("yyyyMMddd_HHmmss").format(new Date());
  16. File image =null;
  17. try{
  18. image = File.createTempFile(name,".jpg", storageDir);
  19. }catch(Exception e){
  20. Log.d("Failed","Gagal menyimpan "+ e.toString());
  21. }
  22. return image;
  23. }

请问我是否需要在AndroidManifest中添加一些内容?

英文:

I try to save the captured image but got an error like the title.

  1. private File createPhotoFile(){
  2. File storageDir = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES +"/sidentanpic/");
  3. sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(storageDir)));
  4. try{
  5. if(storageDir.exists()){
  6. System.out.println("Folder tersedia");
  7. }else{
  8. storageDir.mkdir();
  9. System.out.println("Folder telah dibuat");
  10. }
  11. }catch(Exception e){
  12. e.printStackTrace();
  13. }
  14. String name = new SimpleDateFormat("yyyyMMddd_HHmmss").format(new Date());
  15. File image =null;
  16. try{
  17. image = File.createTempFile(name,".jpg", storageDir);
  18. }catch(Exception e){
  19. Log.d("Failed","Gagal menyimpan "+ e.toString());
  20. }
  21. return image;
  22. }

should I add something in AndroidManifest?

答案1

得分: 1

getExternalStoragePublicDirectory()Environment类中的静态方法。因此,请尝试如下:

  1. Environment.getExternalStoragePublicDirectory()

但是,在Android Q版本中,此方法已被弃用。有关更多信息,请查阅文档

英文:

getExternalStoragePublicDirectory() is static method in Environment class. So, please try as below:

  1. Environment.getExternalStoragePublicDirectory()

But, This method is deprecated in Android Q version. Please check the documentation for more info on this.

huangapple
  • 本文由 发表于 2020年7月26日 21:25:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/63100749.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定