I am developing a simple app for videos by using android camera. In my app I have a button having name "Make Video " and a list view which is for to show the video name recorded by my app. Now as I click the button "Make Video " it opens my mobile camera for recording but when I complete my recording the camera gives me two options. "Save" and "Discard". Now by clicking the "Save" option, I want to add the name of the recorded video to my list view. I have developed some code in this respect and it works fine,but I am facing issue that how to add the name of recorded video in my listview in onActivityResult method and update my list view. Please help me I would be very thankful to you.
You can check my code below.
public class MainActivity extends ListActivity
{
private ArrayList<String> cameraVideoList = new ArrayList<String>();
Context ctx;
// Resources res;
int REQUEST_VIDEO_CAPTURED =1;
Uri uriVideo = null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ctx = getApplicationContext();
Button makeVideo = (Button) findViewById(R.id.button1);
makeVideo.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
//Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(intent, REQUEST_VIDEO_CAPTURED);
}
});
ListView videoList = getListView();
videoList.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,long arg3)
{
Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
setListAdapter(new ImageAndTextAdapter(ctx, R.layout.list_item_icon_text, cameraVideoList));
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK)
{
if (requestCode == REQUEST_VIDEO_CAPTURED)
{
uriVideo = data.getData();
// Toast.makeText(MainActivity.this, uriVideo.getPath(),
// Toast.LENGTH_LONG).show();
//
// Toast.makeText(MainActivity.this, uriVideo.toString(),
// Toast.LENGTH_LONG).show();
cameraVideoList.add(getFileNameFromUrl(uriVideo.getPath().toString()));
}
}
}
public String getFileNameFromUrl(String path)
{
String[] pathArray = path.split("/");
return pathArray[pathArray.length - 1];
}
public class ImageAndTextAdapter extends ArrayAdapter<String>
{
private LayoutInflater mInflater;
private ArrayList<String> mStrings;
private int mViewResourceId;
public ImageAndTextAdapter(Context context, int textViewResourceId,ArrayList<String> objects)
{
super(context, textViewResourceId, objects);
mInflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mStrings = objects;
mViewResourceId = textViewResourceId;
}
public View getView(int position, View convertView, ViewGroup parent)
{
convertView = mInflater.inflate(mViewResourceId, null);
ImageView iv = (ImageView)convertView.findViewById(R.id.icon);
iv.setImageResource(R.drawable.video_icon);
TextView tv = (TextView)convertView.findViewById(R.id.text);
tv.setText(mStrings.get(position));
return convertView;
}
}
}