。什么时候getExternalStorageDirectory()的getPath()返回的东西比&QUOT别人; / SD卡/"? [英] When does getExternalStorageDirectory().getPath() return something else than "/sdcard/"?
问题描述
我从Android的皮棉警告:
不要硬code/ SD卡/;使用Environment.getExternalStorageDirectory()的getPath()代替
我会解决这个问题,但仍需要知道:
在其中(例如)设备,这是一个问题,其他什么(例如)路径可以从这个调用得到什么?如果不涉及到具体的器件,它是什么具体的或者会发生?
在什么情况下是有我的应用程序可以写什么?没有 / SD卡/
目录
该应用程序所拥有的权利。
<使用许可权的android:NAME =android.permission.WRITE_INTERNAL_STORAGE/>
<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAGE/>
你可以从这个调用得到什么其他的(例如)路径?
块引用>晴,这是无论制造商希望。
晴,它会根据运行你的应用程序的用户帐户而有所不同。请记住,对于一个几年(由于Android 4.2的版本),Android设备可以有多个用户帐户(从4.2粒,从5.0的手机)。每个用户得到的内部和外部存储一个独特的位置,并没有保证,以什么实际的文件系统路径那些将指向。
永远难以code,根路径以内部或外部存储。始终使用合适的方法获得一个根目录,然后使用适当的
文件
构造指向任何你想要在那里。
该应用程序所拥有的权利。
块引用>由于在Android的任何
WRITE_INTERNAL_STORAGE
许可,请删除它。I get a warning from android lint:
Do not hardcode "/sdcard/"; use Environment.getExternalStorageDirectory().getPath() instead
I will fix this, but still would need to know:
On which (example) devices is this a problem, what other (example) paths can you get from this call? If this is not related to specific devices, to what is it specific or when would it happen?
Under what circumstances is there no
/sdcard/
directory that my app could write to?The app has the rights
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
解决方案what other (example) paths can you get from this call?
Partly, it is whatever the manufacturer wants.
Partly, it will vary based on the user account that is running your app. Please bear in mind that for a few years (since the release of Android 4.2), Android devices can have multiple user accounts (tablets starting with 4.2, phones starting with 5.0). Each user gets a distinct location for internal and external storage, and there is no guarantee as to what actual filesystem paths those will point to.
NEVER HARDCODE ROOT PATHS to internal or external storage. Always use an appropriate method for getting a root location, then use the appropriate
File
constructor to point to whatever you want within there.The app has the rights
Since there is no
WRITE_INTERNAL_STORAGE
permission in Android, please remove it.这篇关于。什么时候getExternalStorageDirectory()的getPath()返回的东西比&QUOT别人; / SD卡/&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!