AvosCloud的文件存储 Demo
时间戳:201310142227
废话少说,直接上代码:
package com.dannalapp.main; import com.avos.avoscloud.GetCallback; import com.avos.avoscloud.GetDataCallback; import com.avos.avoscloud.ParseException; import com.avos.avoscloud.ParseFile; import com.avos.avoscloud.ParseObject; import com.avos.avoscloud.ParseQuery; import com.avos.avoscloud.SaveCallback; import android.app.Activity; import android.os.Bundle; import android.os.Environment; public class TestActivity extends Activity { ParseFile file; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); try { file = ParseFile.parseFileWithAbsoluteLocalPath("test.jpg", Environment.getExternalStorageDirectory() + "/test.jpg"); file.saveInBackground(new SaveCallback() { @Override public void done(ParseException arg0) { saveObject(); } }); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ParseQuery<ParseObject> query = ParseQuery.getQuery("MyObject"); query.getInBackground("525bd3ade4b0d1da567d970c", new GetCallback<ParseObject>() { public void done(ParseObject object, ParseException e) { if (e == null) { getParseObject(object); System.err.println("qs"); } else { System.err.println("qf"); } } }); } ParseObject mParseObject; ParseFile mParseFile; public void getParseObject(ParseObject parseObject) { mParseObject = parseObject; mParseFile = mParseObject.getParseFile("file"); mParseFile.getDataInBackground(new GetDataCallback() { @Override public void done(byte[] arg0, ParseException arg1) { // TODO Auto-generated method stub } }); String str = mParseFile.getName(); System.err.println("getParseObject - " + str); } ParseObject object = new ParseObject("MyObject"); public void saveObject() { object.put("file", file); object.saveInBackground(); } }
原创作者:http://www.cnblogs.com/huangsheng/