Reputation: 83
I need to unserstand how I can record video programatically. Now I use this construction:
public class AndroidLearningActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
Intent captureVideoIntent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(captureVideoIntent, 100);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Uri uri=data.getData();
Log.e("result", "result:"+resultCode);
}
}
When the application is opened then the camera will be opened too. I have record some video, but if I press "back" button on the device then the application crushes. Please, explain me, how can I do it? Thank you.
Upvotes: 0
Views: 100
Reputation: 28093
You have problem in this statement
Uri uri=data.getData();
Log.e("result", "result:"+resultCode);
When you will press back button recording will be cancelled and you will get data.getData
as null since no recording is done.So change your code to following.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data != null) {
Uri uri = data.getData();
Log.e("result", "result:" + resultCode);
}
super.onActivityResult(requestCode, resultCode, data);
}
Upvotes: 1
Reputation: 15701
looks as you are pressing back key and data (intent) not get set.so data may be null here
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Uri uri=data.getData();
Log.e("result", "result:"+resultCode);
}
}
Upvotes: 1