简体   繁体   中英

Saving and hiding data in android app

i am creating app which would download and save files, than user could use them not being online. So i need place where i could save for example music downloaded from web.

User could listen to it, but user can't get that music. I need place where i could store that files which user wouldn't see.

Maybe someone can help me how can i do this ? Also i need place to save my sqlite database.

Thanks.

PS i am also now searching examples how could i call setSomething to Activity class before i call that activity.

Now i am calling like this:

Thread my_files_thread = new Thread(){

    //start thread
    public void run (){
        try{

            startActivity(new Intent("android.app.reader.FILES"));

        }catch (Exception e) {
                // TODO: handle exception
            e.printStackTrace();
            }finally{

                //finish();
            }
    }

};// Brackets means that thread is closing

From your activity use this to save:

try {
        FileOutputStream fos = openFileOutput("file.mp3", Context.MODE_PRIVATE);
        fos.write(...) // etc
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Then use this to open:

    FileInputStream fis = context.openFileInput("file.mp3");

Files will only be visible to your app then and you won't be clogging up the SD card with clutter. When the user goes to your app settings and presses "Clear app Data" your files will be lost however.

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM