Androidの日常知識収集と総括の呼び出しシステムカメラ撮影、原図獲得
1212 ワード
public class MainActivity extends Activity {
private String path = Environment.getExternalStorageDirectory() + "/Image/";
private String fileName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
File file = new File(path);
if (!file.exists()) {
file.mkdir();
}
fileName = String.valueOf(System.currentTimeMillis())+".jpg";
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(path + fileName)));
startActivityForResult(intent, Activity.DEFAULT_KEYS_DIALER);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case Activity.DEFAULT_KEYS_DIALER: {
File file = new File(path + fileName);
Log.e("mTag", file.length() / 1024 + "");
break;
}
}
}
}
,