英文:
cannot resolve method 'getExternalStoragePublicDirectory'
问题
我尝试保存捕获的图像,但出现了类似标题的错误。
private File createPhotoFile(){
File storageDir = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES + "/sidentanpic/");
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(storageDir)));
try{
if(storageDir.exists()){
System.out.println("Folder tersedia");
}else{
storageDir.mkdir();
System.out.println("Folder telah dibuat");
}
}catch(Exception e){
e.printStackTrace();
}
String name = new SimpleDateFormat("yyyyMMddd_HHmmss").format(new Date());
File image =null;
try{
image = File.createTempFile(name,".jpg", storageDir);
}catch(Exception e){
Log.d("Failed","Gagal menyimpan "+ e.toString());
}
return image;
}
请问我是否需要在AndroidManifest中添加一些内容?
英文:
I try to save the captured image but got an error like the title.
private File createPhotoFile(){
File storageDir = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES +"/sidentanpic/");
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(storageDir)));
try{
if(storageDir.exists()){
System.out.println("Folder tersedia");
}else{
storageDir.mkdir();
System.out.println("Folder telah dibuat");
}
}catch(Exception e){
e.printStackTrace();
}
String name = new SimpleDateFormat("yyyyMMddd_HHmmss").format(new Date());
File image =null;
try{
image = File.createTempFile(name,".jpg", storageDir);
}catch(Exception e){
Log.d("Failed","Gagal menyimpan "+ e.toString());
}
return image;
}
should I add something in AndroidManifest?
答案1
得分: 1
getExternalStoragePublicDirectory()
是Environment
类中的静态方法。因此,请尝试如下:
Environment.getExternalStoragePublicDirectory()
但是,在Android Q版本中,此方法已被弃用。有关更多信息,请查阅文档。
英文:
getExternalStoragePublicDirectory()
is static method in Environment
class. So, please try as below:
Environment.getExternalStoragePublicDirectory()
But, This method is deprecated in Android Q version. Please check the documentation for more info on this.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论