[英]getExternalFilesDir alternative in android 2.1
I built an android app on android 2.2 , for saving files into the SD card I use the following:我在android 2.2上构建了一个 android 应用程序,用于将文件保存到 SD 卡中,我使用以下内容:
context.getExternalFilesDir(null).getAbsolutePath();
returning a string like:返回一个字符串,如:
/mnt/sdcard/Android/data/com.hello.example1/files
Now I need to make my app compatible with android 2.1 , what method do I need to use to get the external files directory?现在我需要使我的应用程序与android 2.1兼容,我需要使用什么方法来获取外部文件目录?
public static String sTellMeWhereToSaveMyData(Context context)
{
String packageName = context.getPackageName();
File externalPath = Environment.getExternalStorageDirectory();
File appFiles = new File(externalPath.getAbsolutePath() + "/Android/data/" + packageName+ "/");
if (appFiles.exists() && appFiles.isDirectory())
{
return appFiles.getAbsolutePath();
}
else
{
if(appFiles.exists())
{
Log.v("File Manager","not exists");
}
if (!appFiles.mkdir())
{
Log.v("File Manager","Could not create");
}
}
return appFiles.getAbsolutePath();
}
You should compose the path yourself:您应该自己编写路径:
String packageName = context.getPackageName();
File externalPath = Environment.getExternalStorageDirectory();
File appFiles = new File(externalPath.getAbsolutePath() +
"/Android/data/" + packageName + "/files");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.