Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 946541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:56:04+00:00 2026-05-15T22:56:04+00:00

[UPDATE 2]: Hi there again, after still trying to attach a video to an

  • 0

[UPDATE 2]: Hi there again,

after still trying to attach a video to an email, I think (not sure though!) that I am a little closer to my goal, but I discovered two problems…

PROBLEM 1: FILENAME DOESN’T SHOW PROPERLY: what I was trying was to toast the name of the video I clicked on to see how I can get the name. This is what I have done…

vGrid.setOnItemClickListener(new OnItemClickListener() {

    @Override // click on item and open options menu
    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

        String [] proj={MediaStore.Video.Media.DATA};
        videocursor = managedQuery( MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj, null,null,null); 
        video_column_index = videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
        videocursor.moveToPosition((int) vGrid.getSelectedItemId());
        // And here we get the filename
        String filename = videocursor.getString(video_column_index);
        Toast.makeText(ShareGalleryView.this, filename, Toast.LENGTH_SHORT).show();

        openOptionsMenu(); //Opens Options Menu by clicking on an item


        }
    });

…but instead of only displaying the filename I get sdcard/filename.mp4, so my first question is how to get rid of the “sdcard/” part because if I use

videocursor.getString(video_column_index) in

i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(Environment.getExternalStorageDirectory(),videocursor.getString(video_column_index))));

for attaching the video to the mail, I get the following Logcat output:

07-18 18:53:47.518: ERROR/Mms/media(179): java.io.FileNotFoundException: /sdcard/sdcard/Video0004.mp4

That was problem 1…now Problem 2

[PROBLEM 2] I also discovered that no matter on which button I click the filename output is always the same and only shows the “sdcard/Video0004.mp4”, so when I click on Video0010 it also shows “sdcard/Video0004.mp4”, thus my second problem is how do I make sure in my code that the item that was clicked on is shown and also attached to the email and always the first video.

Please, please, help me…This is really confusing me…and I have no Idea right now, how to solve these problems.

I will post the entire code below…Thank you

package com.mobilevideoeditor.moved;

import java.io.File;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;


public class ShareGalleryView extends Activity {
    private Cursor videocursor;
    private int video_column_index;
    GridView vGrid;
    int count;


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.videogrid);

        //create new Grid View
        vGrid=(GridView) findViewById(R.id.vgrid);
        registerForContextMenu(vGrid);
        vGrid.setAdapter(new VideoAdapter(this));

        init_phone_video_grid();

        vGrid.setOnItemClickListener(new OnItemClickListener() {

        @Override // click on item and open options menu
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

            String [] proj={MediaStore.Video.Media.DATA};
            videocursor = managedQuery( MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj, null,null,null); 
            video_column_index = videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
            videocursor.moveToPosition((int) vGrid.getSelectedItemId());
            // And here we get the filename
            String filename = videocursor.getString(video_column_index);
            Toast.makeText(ShareGalleryView.this, filename, Toast.LENGTH_SHORT).show();

            openOptionsMenu(); //Opens Options Menu by clicking on an item


            }
        });

    }

    private void init_phone_video_grid() {
        System.gc();
        String[] proj = {
                MediaStore.Video.Media._ID,
                MediaStore.Video.Media.DISPLAY_NAME,
                MediaStore.Video.Media.DATA
        };

        videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj, null, null, null);
        count = videocursor.getCount();

        GridView vGrid=(GridView) findViewById(R.id.vgrid);
        vGrid.setAdapter(new VideoAdapter(this));

        }

    @Override //creates options menu with menu-items
    public boolean onCreateOptionsMenu(Menu menu) {

      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.menu_gallery_share, menu);
      return super.onCreateOptionsMenu(menu);
    }
    @Override //what happens when a menu item is clicked
    public boolean onOptionsItemSelected (MenuItem item){

         try{    
    //Facebook        
    if (item.getItemId() == R.id.menu_facebook)
        {
         //TODO open fb
        new AlertDialog.Builder(this)
          .setTitle("No Service")
          .setMessage("Sorry, Facebook is not supported yet!")
          .setNeutralButton("Close", new DialogInterface.OnClickListener() {                
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
            }}).show();
            return true;

        }
       //YouTube
        else if (item.getItemId() == R.id.menu_youtube)
        {
            //TODO open YouTube

            new AlertDialog.Builder(this)
              .setTitle("No Service")
              .setMessage("Sorry, YouTube is not supported yet!")
              .setNeutralButton("Close", new DialogInterface.OnClickListener() {                
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                }}).show();

              return  true;
        }
        else if (item.getItemId() == R.id.menu_email)
        {

            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("text/plain");
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            i.setType("video/mp4");
            i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(Environment.getExternalStorageDirectory(),videocursor.getString(video_column_index))));
            startActivity(i);

            return true;

        }
        else if (item.getItemId() == R.id.menu_bluetooth)
        {
            // TODO send via bluetooth
            new AlertDialog.Builder(this)
              .setTitle("No Service")
              .setMessage("Sorry, Bluetooth is not supported yet!")
              .setNeutralButton("Close", new DialogInterface.OnClickListener() {                
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                }}).show();
            return true;

        }

            }
         catch(Exception e)
            {
            e.printStackTrace();
            } 
              return super.onContextItemSelected(item);
    }


    public class VideoAdapter extends BaseAdapter {
        private Context vContext;

        public VideoAdapter(Context c) {
            vContext = c;
        }

        public int getCount() {
            return count;
        }

        public Object getItem(int position) {
            return null;
        }

        public long getItemId(int position) {
            return 0;
        }

        // create a new ImageView for each item referenced by the Adapter
        public View getView(int position, View convertView, ViewGroup parent) {
            System.gc();
              TextView tv = new TextView(vContext.getApplicationContext());
              String id = null;

              if (convertView == null) {
                    video_column_index = 
                    videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);
                    videocursor.moveToPosition(position);
                    id = videocursor.getString(video_column_index);
                    tv.setText(id);
              } else
                    tv = (TextView) convertView;
              return tv;    
            }
        }  

}

Hi everyone,

I am working on a Video App, where you can click on a video from the sdcard. This click event opens a menu (I used a options menu) that provides the user with different sharing options, e.g. email, bluetooth etc. This part works fine so far… What I am now trying to do is, when the user chooses “email” the app should open the email app of the phone via an intent (this also works fine) and should directly attach the video he clicked before to the new email .

[UPDATE] The last part is, where I am stuck because I don’t know how to get the image filename that was clicked to open the image. This is the part in my code, where I got the problem (see “DON’T KNOW WHAT TO PUT HERE”)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:56:05+00:00Added an answer on May 15, 2026 at 10:56 pm

    You’re not keeping track of which video ID is being clicked on.

    Once you have that, you can (presumably) get the path to the video by querying the ContentProvider (like you do in VideoAdapter). Or, simpler — since you’re already querying for MediaStore.Video.Media.DATA — attach the URL to the view with convertView.setTag().

    You could store this in a local variable during the onItemClick call — the URI should be available directly by calling String uri = (String) v.getTag().

    Some further notes:

    • Don’t call System.gc(), especially not in a getView() method. That will cause a huge number of unnecessary slowdowns.
    • Don’t call vContext.getApplicationContext(); just use vContext.
    • You’re not recycling views properly. Your getView should look more like below:

    private static int displayNameIndex = -1;
    
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView tv;
    
        if (convertView == null) {
            // Need to create a new view
            tv = new TextView(context);
        } else {
            // Otherwise, we can recycle the one given to us
            tv = (TextView) convertView;
        }
    
        // Bind cursor data to UI
        videocursor.moveToPosition(position);
        id = videocursor.getString(1); // column index of Media.DISPLAY_NAME
        tv.setText(id);
    
        // Bundle video URI into the view
        String videoUri = videocursor.getString(2); // column index of Media.DATA
        tv.setTag(videoUri);
    
        return tv;
    }
    

    I would also look at CursorAdapter, rather than having to do cursor stuff yourself (moving the cursor to the right position etc.).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My requirement is that I want an object (tee) to update if there have
Is there a way to get an update by email when a user updates
Update: I figured it out! Kind of... I'm not sure how this fixed it,
Update 2022 There is cloud sql proxy now: https://cloud.google.com/sql/docs/mysql/sql-proxy#how-works Old Question I am currently
UPDATE Guid.TryParse is available in .NET 4.0 END UPDATE Obviously there is no public
I want to interrupt some specific grails domain class events(read,write,delete,update).Is there any hibernate eventlistner
Update: This question is a duplicate of Are there any programming languages targeting PHP,
Is there an easy way to update the data source for multiple pivot tables
Is there any way to set/update values in the settings.bundle from within your app.
Is there a way to update only the parent UpdatePanel without updating the child

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.