import java.io.File;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class OpenCamera extends Activity {
private static int REQUEST_VIDEO_CAPTURED = 2;
Uri uriVideo = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_screen);
Button b = (Button) findViewById(R.id.btn_end);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 120);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
startActivityForResult(intent, REQUEST_VIDEO_CAPTURED);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_VIDEO_CAPTURED) {
uriVideo = data.getData();
if (uriVideo != null) {
Log.e("---------VIDEO PATH", uriVideo.getPath().toString());
String videoPath = convertMediaUriToPath(uriVideo);
//you can move the file to desired location
String targetPath = "sdcard/a/b/c/";
File sourceFile = new File(videoPath);
String targetDir = targetPath;
// Move file to new directory
String sourceFileName = sourceFile.getName();
/*
* For renaming the file String new_File1 =
* String.valueOf(System.currentTimeMillis() ); String new_File
* = fileName.substring(0, fileName.indexOf(".")) +
* new_File1+".3gp";
*/
boolean success = sourceFile.renameTo(new File(targetDir,sourceFileName));
if (!success) {
// File was not successfully moved
System.out.println("not Succesful");
}
System.out.println("File move Successfully");
}
}
}
protected String convertMediaUriToPath(Uri uri) {
String path=null;
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(uri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
if(cursor.getCount()!=0){
cursor.moveToFirst();
path = cursor.getString(column_index);
}
cursor.close();
return path;
}
}
No comments:
Post a Comment