开发者

How to store file/responses if user does not have SDcard?

I have written code which saves a user's answers as well as a recorded audio piece (.3gp) to their SDcard, which then gets uploaded to a server. I know this probably is not the best way to go about this because a user may not have an SDcard. I know I can put code in to check to see if the user has an SDcard but that wont help much. Is there an alternative way to store info or files on a device which doesnt have an sdcard or better way to go about this? Thanks for the help!

EDIT: Code below was working solution

try{
File pathCacheDir = getCacheDir();
System.out.println("Got the Cache directory");
File newCacheFile = new File(pathCacheDir, cacheFileName);
newCacheFile.createNewFile();
FileOutputStream stream = new FileOutputStream (newCacheFil开发者_如何学Pythone.getAbsolutePath());


You should be able to create a database for your app and store the file in a blob.


The normal way is to hold large files on server, with your application loading them when needed. Economize the memory! :-)


You should store some temporary data in the row folder of the project.

if (android.os.Environment.getExternalStorageState()
                                            .equals(android.os.Environment.MEDIA_MOUNTED))
                                            cacheDir = new File(android.os.Environment.getExternalStorageDirectory(),
                                                            "LazyList");
                                        else
                                            cacheDir = Login.this.getCacheDir();
                                        if (!cacheDir.exists())
                                            cacheDir.mkdirs();
                                        File f = new File(cacheDir,"profileimage.jpg");
                                        try 
                                        {
                                            InputStream is = new URL(userImageurl).openStream();
                                            OutputStream os = new FileOutputStream(f);
                                            Utils.CopyStream(is, os);
                                            os.close();
                                        } catch (Exception ex) 
                                        {
                                        }

Read care fully my above code in this code i have sore a picture file in the row folder of the project then upload to server.

I hope this is help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜