5

I want to start camera activity in my android app and I know how to do that. I want to ask when the camera activity finishes, how can I check as if it was the picture or the video taken by the user?

UPDATED

I have a dialog where it asks 2 things.

  1. New Photo or Video
  2. Existing Photo or Video

If it's no. 1, it means camera will be started and user can either take a picture or the video and it will return to the activity.

If it's no.2, it mean gallery will be started having pictures and videos for a user to select one and will return back to the activity.

Umair A.
  • 6,690
  • 20
  • 83
  • 130
  • See this post on how to get the picture taken by the user: http://stackoverflow.com/questions/2314958/using-the-camera-activity-in-android – aKzenT Aug 21 '11 at 20:24
  • well the goal is to find whether it was picture or the video because the camera can do both. – Umair A. Aug 21 '11 at 20:33
  • Sorry, I misunderstood your question. I'm afraid I can't help. From the extras you don't get any hints? – aKzenT Aug 21 '11 at 20:40

1 Answers1

2

Hello Umair, I have done this type of application I searched many time but I didn't get any proper solution so I changed your my menu & they are now 1)Take New Photo 2)Take New Video 3)Existing Image/Video

Process will be like this 1)I use an global variable 2)So when user click on menu one I sets global variable value to 1 3) Start the activity for result like below

try{
   System.gc();
   String fileName = System.currentTimeMillis()+".jpg";
   String mPathImage = Environment.getExternalStorageDirectory()+ "/" + fileName;
   File file = new File(mPathImage);
   Uri outputFileUri = Uri.fromFile( file );
   Intent mIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
   mIntent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );
   startActivityForResult(mIntent, 1);
   mValue=1;

}catch(Exception e){

}

If User click on menu 2 I change value of global variable to 2 & starts the activity for result like below.

try {
    System.gc();
    Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
    startActivityForResult(intent, 1);
    mValue=2;
}catch(Exception e){}

If user click on 3rd menu I set value to 3 & start the activity for result like below.

try{
   System.gc();
   Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
   intent.setType("*/*");
   startActivityForResult(intent,1);
   mValue=3;
}catch(Exception e){}
}

This will show all the images & video's in mobile

Then finally when activity gets closed use global variable to check whether user want to new image or video or existing image/video.

Hope this will help you..

Sandip Jadhav
  • 7,377
  • 8
  • 44
  • 76
  • `System.gc()`? First of all invoking 'System.gc()' is not a guarantee of garbage collection actually being performed. Also it looks like you do not understand what you are doing, otherwise why this line of code? – user1991679 Sep 06 '15 at 13:40
  • @user1991679 -- Yes you are right System.gc() is not a guarantee of garbage collection actually being performed. Why you are focusing on that single line. If that line is not present still rest of code will work. Even though it doesn't give guarantee still it's not bad to use it. – Sandip Jadhav Sep 08 '15 at 05:36