Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to select video from gallery in Android

    • 0
    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 9.23k
    Comment on it

    How to select video from gallery through intent?

    Step 1: Declare the variables on the activity from where you want to hit the intent

     int SELECT_VIDEO_REQUEST=100;
     String selectedVideoPath;
    

    Step 2: Selecting Video from gallery by intent hit

    public void selectVideoFromGallery() 
      {
       Intent intent;
       if(android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
        {
         intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
         }
        else
        {
         intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.INTERNAL_CONTENT_URI);
        }
        intent.setType("video/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.putExtra("return-data", true);
        startActivityForResult(intent,SELECT_VIDEO_REQUEST);
         }
    

    Step3: OnActivity result you can get the path of the video you have just selected*/

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
         {
        if(requestCode == SELECT_VIDEO_REQUEST && resultCode == RESULT_OK)
             {
           if(data.getData()!=null)
            {
             String selectedVideoPath = getPath(data.getData(),activity );
                }
                else
            {
             Toast.makeText(getApplicationContext(), "Failed to select video" , Toast.LENGTH_LONG).show();
            }
          }
         }
    

 2 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: