我正在尝试制作一个简单的注册页面,该页面从 Android 库中获取图像并将它们保存到 Parse.com 云以供进一步参考。这是代码:
这是在点击浏览按钮时执行的方法...
public void choosePic(View v)
{
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
此方法在选择图像时执行:
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
byte[] image = bos.toByteArray();
profilePic = new ParseFile("image2.jpg", image);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
}
}
这是在点击注册按钮时执行的方法
public void signupClicked(View arg0)
{
// Retrieve the text entered from the EditText
usernametxt = username.getText().toString();
passwordtxt = password.getText().toString();
addresstxt = address.getText().toString();
emailtxt = email.getText().toString();
// Force user to fill up the form
if (usernametxt.equals("") && passwordtxt.equals("")) {
Toast.makeText(getApplicationContext(),
"Please complete the sign up form",
Toast.LENGTH_LONG).show();
} else {
// Save new user data into Parse.com Data Storage
ParseUser user = new ParseUser();
user.setUsername(usernametxt);
user.setPassword(passwordtxt);
user.setEmail(emailtxt);
// other fields can be set just like with ParseObject
user.put("address", addresstxt);
user.put("photo", profilePic);
user.signUpInBackground(new SignUpCallback() {
@Override
public void done(com.parse.ParseException e) {
// TODO Auto-generated method stub
if (e == null) {
// Show a simple Toast message upon successful registration
Toast.makeText(getApplicationContext(),
"Successfully Signed up, please log in.",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),
"Sign up Error", Toast.LENGTH_LONG)
.show();
}
}
});
}
Intent intent = new Intent(this,MainActivity.class);
startActivity(intent);
}
这是我在 Parse.com 云中单击照片数据对象时遇到的错误
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>534755F82D0FFA4C</RequestId>
<HostId>
tPHdYj7iVHL67mYKoyXwf6GtbzQr6TO5r5Xfmj3usbA5HQcGd/vEpnr3DGDaAhac
</HostId>
</Error>