步骤:
1)调用系统相机。
2)获取刚刚拍摄的照片。
3)拿着照片改变世界。
photo = (Button) findViewById(R.id.photo);
photo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub 启动相机
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(new File("/sdcard/comfish.photo")));
startActivityForResult(intent, 0);
}
});
点击 photo 按钮后便启动相机,拍照结束后会调用 onActivityResult 方法。
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0) {
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inTempStorage = new byte[1024 * 1024 * 2];
options.inSampleSize = 2;
bitmap = BitmapFactory.decodeFile(PATH, options);
if (bitmap != null) {
//拿着bitmap去改变世界吧。
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
发送带图片的微博是用 upload 方法。
StatusesAPI statusAPI = new StatusesAPI(AccessTokenKeeper.readAccessToken(this));
statusAPI.upload(weibo_content.getText().toString(), bitmap, "0.0","0.0", listener);