public class MainActivity extends Activity { |
private String path = Environment.getExternalStorageDirectory() + "/aImage/" ; |
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 ; |
} |
} |
} |
} |
by: 发表于:2017-12-21 09:49:57 顶(0) | 踩(0) 回复
??
回复评论