Environment.getExternalStorageDirectory().getAbsolutePath() not working and giving /storage

倖福魔咒の 提交于 2019-12-05 18:25:58
String dbPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "FashionGirl/ImagesDB.db";
myDb = openOrCreateDatabase(dbPath, Context.MODE_PRIVATE, null);

Please do not use concatenation for constructing file paths. Try:

File dbPath = new File(Environment.getExternalStorageDirectory(), "FashionGirl/ImagesDB.db");
myDb = openOrCreateDatabase(dbPath.getAbsolutePath(), Context.MODE_PRIVATE, null);

But strangely, its not working, where Environment.getExternalStorageDirectory().getAbsolutePath() has value /storage

That is because /sdcard has been deprecated for nearly three years.

Add / before Fashiongirl

String dbPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/FashionGirl/ImagesDB.db";
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

listView = (ListView) findViewById(R.id.list);
List<Employee> employees = null;
try {
    XMLPullParserHandler parser = new XMLPullParserHandler();

    File f = new File("/mnt/extsd/kmls/mykml.kml");

    InputStream is = new FileInputStream(f);

            employees = parser.parse(is);

       ArrayAdapter<Employee> adapter = new ArrayAdapter<Employee>     

this,R.layout.list_item, employees);

    listView.setAdapter(adapter);

    } catch (IOException e) {
        e.printStackTrace();
    }
}

Note : "/mnt/extsd/kmls/mykml.kml" this is the complete path to reach my kml fiel.
   for this first you need to open your sdcard in your device then you find the path   
then the path need to insert into your app.

thanks
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!