public class VideoDemo extends Activity {
private VideoView video;
private MediaController ctlr;
File clip=new File(Environment.getExternalStorageDirectory();
{
if (clip.exists()) {
video=(VideoView)findViewById(R.id.videoGrdView);
video.setVideoPath(clip.getAbsolutePath());
ctlr=new MediaController(this);
ctlr.setMediaPlayer(video);
video.setMediaController(ctlr);
video.requestFocus();
video.start();
}
}};
}
}
So i've got a VideoGrdView of all videos on my sd card to display in a separate activity, now i need to know how to click a video from the grid and have it play through this media player. Any help is appreciated.
public class Menus extends Activity {
//set constants for MediaStore to query, and show videos
private final static Uri MEDIA_EXTERNAL_CONTENT_URI =
MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
private final static String _ID = MediaStore.Video.Media._ID;
private final static String MEDIA_DATA = MediaStore.Video.Media.DATA;
//flag for which one is used for images selection
private GridView _gallery;
private Cursor _cursor;
private int _columnIndex;
private int[] _videosId;
private Uri _contentUri;
protected Context _context;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
_context = getApplicationContext();
_gallery = (GridView) findViewById(R.id.videoGrdVw);
//set default as external/sdcard uri
_contentUri = MEDIA_EXTERNAL_CONTENT_URI;
//initialize the videos uri
//showToast(_contentUri.getPath());
initVideosId();
//set gallery adapter
setGalleryAdapter();
}
private void setGalleryAdapter() {
_gallery.setAdapter(new VideoGalleryAdapter(_context));
_gallery.setOnItemClickListener(_itemClickLis);
}
private AdapterView.OnItemClickListener _itemClickLis = new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
// Now we want to actually get the data location of the file
String [] proj={MEDIA_DATA};
// We request our cursor again
_cursor = managedQuery(_contentUri,
proj, // Which columns to return
null, // WHERE clause; which rows to return (all rows)
null, // WHERE clause selection arguments (none)
null); // Order-by clause (ascending by name)
// We want to get the column index for the data uri
int count = _cursor.getCount();
//
_cursor.moveToFirst();
//
_columnIndex = _cursor.getColumnIndex(MEDIA_DATA);
// Lets move to the selected item in the cursor
_cursor.moveToPosition(position);
startActivity(new Intent("com.ave"));
}
};
private void initVideosId() {
try
{
//Here we set up a string array of the thumbnail ID column we want to get back
String [] proj={_ID};
// Now we create the cursor pointing to the external thumbnail store
_cursor = managedQuery(_contentUri,
proj, // Which columns to return
null, // WHERE clause; which rows to return (all rows)
null, // WHERE clause selection arguments (none)
null); // Order-by clause (ascending by name)
int count= _cursor.getCount();
// We now get the column index of the thumbnail id
_columnIndex = _cursor.getColumnIndex(_ID);
//initialize
_videosId = new int[count];
//move position to first element
_cursor.moveToFirst();
for(int i=0;i<count;i++)
{
int id = _cursor.getInt(_columnIndex);
//
_videosId[i]= id;
//
_cursor.moveToNext();
//
}
}catch(Exception ex)
{
}
}
//
private class VideoGalleryAdapter extends BaseAdapter
{
public VideoGalleryAdapter(Context c)
{
_context = c;
}
public int getCount()
{
return _videosId.length;
}
public Object getItem(int position)
{
return position;
}
public long getItemId(int position)
{
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
ImageView imgVw= new ImageView(_context);;
try
{
if(convertView!=null)
{
imgVw= (ImageView) convertView;
}
imgVw.setImageBitmap(getImage(_videosId[position]));
imgVw.setLayoutParams(new GridView.LayoutParams(96, 96));
imgVw.setPadding(8, 8, 8, 8);
}
catch(Exception ex)
{
System.out.println("StartActivity:getView()-135: ex " + ex.getClass() +", "+ ex.getMessage());
}
return imgVw;
}
// Create the thumbnail on the fly
private Bitmap getImage(int id) {
Bitmap thumb = MediaStore.Video.Thumbnails.getThumbnail(
getContentResolver(),
id, MediaStore.Video.Thumbnails.MICRO_KIND, null);
return thumb;
}
}
}
Gallery, pretty much works the same way as a ListView. Inside the onItemClick method, you should be able to know which specific item was clicked. Get the Uri/absolute path for that item, and pass on that information to the next activity.
In the VideoDemo class, extract this Uri/path and set it to the VideoView.
Related
Hi can somebody help me with my code?? I have a class which should show me folders on my SD card+ folders name, but all folders have same name, but each should have different. How can i implement it??
public class ThumbnailAdapter extends BaseAdapter {
// Context required for performing queries
private final Context mContext;
// Cursor for thumbnails
private final Cursor cursor;
private final int count;
String bucket;
String id;
public ThumbnailAdapter(Context c) {
this.mContext = c;
// Get list of all images, sorted by last taken first
final String[] projection = {
MediaStore.Images.Media.BUCKET_ID,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME
};
String BUCKET_GROUP_BY =
"1) GROUP BY 1,(2";
String BUCKET_ORDER_BY = "MAX(datetaken) DESC";
cursor = mContext.getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection,
BUCKET_GROUP_BY,
null,
BUCKET_ORDER_BY
);
if (cursor.moveToFirst()) {
int bucketColumn = cursor.getColumnIndex(
MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
int idColumn = cursor.getColumnIndex(
MediaStore.Images.Media.BUCKET_ID);
do {
// Get the field values
bucket = cursor.getString(bucketColumn);
id = cursor.getString(idColumn);
} while (cursor.moveToNext());
}
count = cursor.getCount();
Log.d("ThumbnailAdapter", count + " images found");
}
#Override
public int getCount() {
return count;
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout ll = new LinearLayout(mContext);
ImageView imageView = new ImageView(mContext);
TextView mytext = new TextView(mContext);
mytext.setText(bucket);
imageView.setImageResource(R.drawable.your_folder_icon);
ll.addView(imageView);
ll.addView(mytext);
return ll;
}
You are probably not setting your TextView mytext to change the text it displays - try the line:
mytext.setText(projection[position]);
I'm not quite sure how you are indexing your projection String array, but by just providing the right index (using the position variable in the getView() method, you should be able to change the TextView name correctly.
I know that here are many answers how to delete items, but I can't make it work. It show errors. Can you look? I added in adapter remove(position), but I think it works wrongly.
So I want after using onItemLongClickListener to delete file and its thumbnail too.
Main:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final GridView grid = (GridView) findViewById(R.id.gridview);
final ThumbnailAdapter thumbnails = new ThumbnailAdapter(this);
grid.setAdapter(thumbnails);
grid.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener(){
#Override
public boolean onItemLongClick(AdapterView<?> parent, View v, int position,
long id) {
final String imgPath = thumbnails.getImagePath(position);
File file = new File(imgPath);
file.delete();
thumbnails.remove(position);
thumbnails.notifyDataSetChanged();
grid.invalidateViews();
grid.setAdapter(thumbnails);
return true;
}
});
Adapter:
public class ThumbnailAdapter extends BaseAdapter {
// Context required for performing queries
private final Context mContext;
// Cursor for thumbnails
private final Cursor cursor;
private final int imgId;
private final int imgData;
private final int count;
public ThumbnailAdapter(Context c) {
this.mContext = c;
// Get list of all images, sorted by last taken first
final String[] projection = {
MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATA
};
cursor = mContext.getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection,
null,
null,
MediaStore.Images.Media.DATE_TAKEN + " DESC"
);
imgId = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
imgData = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
count = cursor.getCount();
Log.d("ThumbnailAdapter", count + " images found");
}
#Override
public int getCount() {
return count;
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
} else {
imageView = (ImageView) convertView;
}
cursor.moveToPosition(position);
final Bitmap thumbnail = MediaStore.Images.Thumbnails.getThumbnail(
mContext.getContentResolver(),
cursor.getInt(imgId),
MediaStore.Images.Thumbnails.MICRO_KIND,
null
);
imageView.setImageBitmap(thumbnail);
Log.d("ThumbnailAdapter", "render: " + cursor.getString(imgData));
return imageView;
}
public String getImagePath(int position) {
cursor.moveToPosition(position);
return cursor.getString(imgData);
}
public void remove(int position) {
remove(position);
notifyDataSetChanged();
}
}
I guess its stack overflow. your remove method in the adapter is recursive forever.
Instead of deleting file youself ask content resolver to remove it. and the reload data.
you dont have to call grid.setAdapter(thumbnails) again in the click listner
Check this line please though :
file.delete();
thumbnails.remove(position);
You are deleting your file first and then removing it from adapter. It should be other way around. You reset your adapter then delete the actual file. Your thumbnail is deleted while still being attached to the adapter.
I have a gridview in one screen and in gridview i am displaying all the images which is present in SDCard this is working fine. Now what i want to do is when i click on any of gridview images it should go to next activity and should display that particular image in full screen. I have referred some other link and tried but not getting proper solution.
public class Gallary_Images extends Activity {
private Cursor cursor;
private int columnIndex;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery_images);
// Set up an array of the Thumbnail Image ID column we want
String[] projection = { MediaStore.Images.Thumbnails._ID };
// Create the cursor pointing to the SDCard
cursor = managedQuery(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, projection,
null, // Return all rows
null, MediaStore.Images.Thumbnails.IMAGE_ID);
// Get the column index of the Thumbnails Image ID
columnIndex = cursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
GridView sdcardImages = (GridView) findViewById(R.id.gridView1);
sdcardImages.setAdapter(new ImageAdapter(this));
// Set up a click listener
sdcardImages.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position,
long id) {
Intent i = new Intent(getApplicationContext(),
ViewGallery_Photo.class);
i.putExtra("id", position);
startActivity(i);
}
});
}
private class ImageAdapter extends BaseAdapter {
private Context context;
public ImageAdapter(Context localContext) {
context = localContext;
}
public int getCount() {
return cursor.getCount();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView picturesView;
if (convertView == null) {
picturesView = new ImageView(context);
// Move cursor to current position
cursor.moveToPosition(position);
// Get the current value for the requested column
int imageID = cursor.getInt(columnIndex);
// Set the content of the image based on the provided URI
picturesView.setImageURI(Uri.withAppendedPath(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, ""
+ imageID));
picturesView.setScaleType(ImageView.ScaleType.FIT_CENTER);
picturesView.setPadding(8, 8, 8, 8);
picturesView
.setLayoutParams(new GridView.LayoutParams(100, 100));
} else {
picturesView = (ImageView) convertView;
}
return picturesView;
}
}
}
This is my gridview class where i am calling next activity. Now i don't know how should i get the images in next activity. Please help...
First thing that you must try is a put an URi of image in your intent like this
intent.putExtra("imageUri", imageUri.toString());
where imageUri is Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, ""+ imageID));
but before this you must know your imageID, so the whole code must be like this
sdcardImages.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position,long id) {
Intent i = new Intent(getApplicationContext(),ViewGallery_Photo.class);
cursor.moveToPosition(position);
int imageID = cursor.getInt(columnIndex);
Uri imageUri = Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
""+ imageID));
intent.putExtra("imageUri", imageUri.toString());
startActivity(i);
}
});
Try out as below:
Add data filed in your projection string.
String[] columns = { MediaStore.Images.Media.DATA,
MediaStore.Images.Media._ID };
public void onItemClick(AdapterView<?> arg0, android.view.View v,
int position, long id) {
Intent i = new Intent(getApplicationContext(),ViewGallery_Photo.class);
cursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns,
null, null, null);
final int dataColumnIndex = cursor
.getColumnIndex(MediaStore.Images.Media.DATA);
final int idColumIndex = actualimagecursor
.getColumnIndex(MediaStore.Images.Media._ID);
cursor.moveToPosition(position);
filename = cursor.getString(dataColumnIndex);
i.putExtra("imagePath", filename );
startActivity(i);
Here is my image gallery code. So far, for testing purpose I directly used some manually stored images,
public class Photo_Gallery extends Activity
{
//---the images to display---
Integer[] imageIDs = {
R.drawable.a,
R.drawable.b,
R.drawable.c,
R.drawable.d,
R.drawable.e,
};
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.displayview);
Gallery gallery = (Gallery) findViewById(R.id.gallery1);
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView parent, View v, int position, long id)
{
//---display the images selected---
ImageView imageView = (ImageView) findViewById(R.id.image1);
imageView.setImageResource(imageIDs[position]);
}
});
}
public class ImageAdapter extends BaseAdapter
{
private Context context;
private int itemBackground;
public ImageAdapter(Context c)
{
context = c;
//---setting the style---
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
itemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
//---returns the number of images---
public int getCount() {
return imageIDs.length;
}
//---returns the ID of an item---
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
//---returns an ImageView view---
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(context);
imageView.setImageResource(imageIDs[position]);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setLayoutParams(new Gallery.LayoutParams(75, 60));
imageView.setBackgroundResource(itemBackground);
return imageView;
}
}
}
And here is the code I used to capture images.
case R.id.takeSnapBtn:
try {
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, imageData);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Following is the onActivityResult(),
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
bmp = (Bitmap) extras.get("data");
imageView.setImageBitmap(bmp);
}
}
I would be glad if some one provide me an example of how to dynamically update the gallery with images taken from the camera.
Store the images captured from app and read those images from sd card to gallery..
File sdDir = new File("/sdcard/Pictures/YOUR_DIR");
sdDirFiles = sdDir.listFiles();
for (i = 0; i < sdDirFiles.length; i++) {
//ADD to gallery HERE..
}
If u get all images under the sdcard of perticular Bucket(folder) then use this code...
public class SubGalleryView extends Activity {
private ArrayList<Integer> ImageIds = new ArrayList<Integer>();
private GridView subGalleryView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sub_gallery_view);
//Provide Bucket_Name/Folder_Name Using Bundle.
Bundle bundle = getIntent().getExtras();
Toast.makeText(this, bundle.getString("Bucket_Name"),
Toast.LENGTH_SHORT).show();
//Using Projection We get all images of all folder.
String[] projection = new String[] { MediaStore.Images.Media._ID,
MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME };
Cursor cursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null,
null, null);
cursor.moveToFirst();
if (cursor.getCount() > 0) {
//using this do{}while(); we get all image_id under perticular bucket. and strored in ArrayList of ImagesIds.
do {
int columnIndex = cursor
.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME);
if (cursor.getString(columnIndex).equalsIgnoreCase(
bundle.getString("Bucket_Name"))) {
columnIndex = cursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
int imageID = cursor.getInt(columnIndex);
ImageIds.add(imageID);
} else if (bundle.getString("Bucket_Name").equalsIgnoreCase(
"All Pictures")) {
columnIndex = cursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
int imageID = cursor.getInt(columnIndex);
ImageIds.add(imageID);
}
} while (cursor.moveToNext());
}
//Pass ImageIds arrayList to Adapter.
subGalleryAdapter imageAdapter = new subGalleryAdapter(
SubGalleryView.this, R.layout.sub_gallery_view_item, ImageIds);
subGalleryView = (GridView) findViewById(R.id.subGallery);
subGalleryView.setAdapter(imageAdapter);
}
public class subGalleryAdapter extends ArrayAdapter<Integer> {
private Context contex;
private int resourceId;
private LayoutInflater layoutInflater = null;
private ArrayList<Integer> mlist;
public subGalleryAdapter(Activity context, int resourceId,
ArrayList<Integer> list) {
super(context, resourceId, list);
this.mlist = list;
this.contex = context;
this.resourceId = resourceId;
this.layoutInflater = context.getLayoutInflater();
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView viewHolder;
if (convertView == null) {
viewHolder = new ImageView(contex);
convertView = layoutInflater.inflate(resourceId, parent, false);
viewHolder = (ImageView) convertView
.findViewById(R.id.imageView1);
} else {
viewHolder = (ImageView) convertView
.findViewById(R.id.imageView1);
}
viewHolder.setImageURI(Uri.withAppendedPath(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
"" + mlist.get(position)));
return convertView;
}
}
}
Using this code u get all images from perticular folder passing bucket display name in bundle. and if u get all images of all bucket(folder) form sdcard then use this code
public class SubGalleryViewy extends Activity {
private Cursor cursor;
private int columnIndex;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sdcard);
// Set up an array of the Thumbnail Image ID column we want
String[] projection = {MediaStore.Images.Thumbnails._ID};
// Create the cursor pointing to the SDCard
cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
projection, // Which columns to return
null, // Return all rows
null,
MediaStore.Images.Thumbnails.IMAGE_ID);
// Get the column index of the Thumbnails Image ID
columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
GridView sdcardImages = (GridView) findViewById(R.id.sdcard);
sdcardImages.setAdapter(new ImageAdapter(this));
// Set up a click listener
sdcardImages.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
// Get the data location of the image
String[] projection = {MediaStore.Images.Media.DATA};
cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection, // Which columns to return
null, // Return all rows
null,
null);
columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToPosition(position);
// Get image filename
String imagePath = cursor.getString(columnIndex);
// Use this path to do further processing, i.e. full screen display
}
});
}
/**
* Adapter for our image files.
*/
private class ImageAdapter extends BaseAdapter {
private Context context;
public ImageAdapter(Context localContext) {
context = localContext;
}
public int getCount() {
return cursor.getCount();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView picturesView;
if (convertView == null) {
picturesView = new ImageView(context);
// Move cursor to current position
cursor.moveToPosition(position);
// Get the current value for the requested column
int imageID = cursor.getInt(columnIndex);
// Set the content of the image based on the provided URI
picturesView.setImageURI(Uri.withAppendedPath(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, "" + imageID));
picturesView.setScaleType(ImageView.ScaleType.FIT_CENTER);
picturesView.setPadding(8, 8, 8, 8);
picturesView.setLayoutParams(new GridView.LayoutParams(100, 100));
}
else {
picturesView = (ImageView)convertView;
}
return picturesView;
}
}
}
Activity 2
public class Menus extends Activity {
//set constants for MediaStore to query, and show videos
private final static Uri MEDIA_EXTERNAL_CONTENT_URI = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
private final static String _ID = MediaStore.Video.Media._ID;
private final static String MEDIA_DATA = MediaStore.Video.Media.DATA;
//flag for which one is used for images selection
private GridView _gallery;
private Cursor _cursor;
private int _columnIndex;
private int[] _videosId;
private Uri _contentUri;
protected Context _context;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
_context = getApplicationContext();
_gallery = (GridView) findViewById(R.id.videoGrdVw);
//set default as external/sdcard uri
_contentUri = MEDIA_EXTERNAL_CONTENT_URI;
//initialize the videos uri
//showToast(_contentUri.getPath());
initVideosId();
//set gallery adapter
setGalleryAdapter();
}
private void setGalleryAdapter() {
_gallery.setAdapter(new VideoGalleryAdapter(_context));
_gallery.setOnItemClickListener(_itemClickLis);
}
private AdapterView.OnItemClickListener _itemClickLis = new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
// Now we want to actually get the data location of the file
String [] proj={MEDIA_DATA};
// We request our cursor again
_cursor = managedQuery(_contentUri,
proj, // Which columns to return
null, // WHERE clause; which rows to return (all rows)
null, // WHERE clause selection arguments (none)
null); // Order-by clause (ascending by name)
// We want to get the column index for the data uri
int count = _cursor.getCount();
//
_cursor.moveToFirst();
//
_columnIndex = _cursor.getColumnIndex(MEDIA_DATA);
// Lets move to the selected item in the cursor
_cursor.moveToPosition(position);
Intent data = new Intent(getBaseContext(), Editor.class); data.putExtra("mnt/sdcard-ext", _ID); startActivity(data);
}
};
private void initVideosId() {
try
{
//Here we set up a string array of the thumbnail ID column we want to get back
String [] proj={_ID};
// Now we create the cursor pointing to the external thumbnail store
_cursor = managedQuery(_contentUri,
proj, // Which columns to return
null, // WHERE clause; which rows to return (all rows)
null, // WHERE clause selection arguments (none)
null); // Order-by clause (ascending by name)
int count= _cursor.getCount();
// We now get the column index of the thumbnail id
_columnIndex = _cursor.getColumnIndex(_ID);
//initialize
_videosId = new int[count];
//move position to first element
_cursor.moveToFirst();
for(int i=0;i<count;i++)
{
int id = _cursor.getInt(_columnIndex);
//
_videosId[i]= id;
//
_cursor.moveToNext();
//
}
}catch(Exception ex)
{
}
}
//
private class VideoGalleryAdapter extends BaseAdapter
{
public VideoGalleryAdapter(Context c)
{
_context = c;
}
public int getCount()
{
return _videosId.length;
}
public Object getItem(int position)
{
return position;
}
public long getItemId(int position)
{
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
ImageView imgVw= new ImageView(_context);;
try
{
if(convertView!=null)
{
imgVw= (ImageView) convertView;
}
imgVw.setImageBitmap(getImage(_videosId[position]));
imgVw.setLayoutParams(new GridView.LayoutParams(96, 96));
imgVw.setPadding(8, 8, 8, 8);
}
catch(Exception ex)
{
System.out.println("StartActivity:getView()-135: ex " + ex.getClass() +", "+ ex.getMessage());
}
return imgVw;
}
// Create the thumbnail on the fly
private Bitmap getImage(int id) {
Bitmap thumb = MediaStore.Video.Thumbnails.getThumbnail(
getContentResolver(),
id, MediaStore.Video.Thumbnails.MICRO_KIND, null);
return thumb;
}
}
}
Activity 3
public class Editor extends Activity {
private VideoView video;
private MediaController ctlr;
ImageButton video1;
int isClicked = 0;
ImageButton audio;
int isClicked1 = 0;
int data = getIntent(data).getExtras()
.getInt("mnt/sdcard-ext");
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
setContentView(R.layout.editor);
video1 = (ImageButton) findViewById(R.id.video);
video1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (isClicked == 0) {
video1.setImageResource(R.drawable.video_pressed);
isClicked = 1;
} else {
video1.setImageResource(R.drawable.video1);
isClicked = 0;
}
}
});
audio = (ImageButton) findViewById(R.id.audio);
audio.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (isClicked1 == 0) {
audio.setImageResource(R.drawable.audio_pressed);
isClicked1 = 1;
} else {
audio.setImageResource(R.drawable.audio);
isClicked1 = 0;
}
}
});
if (clip.exists()) {
video=(VideoView)findViewById(R.id.video);
video.setVideoPath(clip.getAbsolutePath());
ctlr=new MediaController(this);
ctlr.setMediaPlayer(video);
video.setMediaController(ctlr);
video.requestFocus();
video.start();
}
}
}
I am never gonna be a programmer i'm just trying to pass this class. So don't worry. I need to know how to pass this intent data through to the third activity, but i'm not sure where to put the Extras and get extras.
Android Manifest
<activity
android:name=".Editor"
android:screenOrientation="landscape" >
<intent-filter>
<action
android:name="com.ave.Editor" />
<category
android:name="android.intent.category.DEFAULT" />
</intent-filter>
If you need anymore information let me know. I'm tried of messing with this confusing crap. And any help is appreciated.
Intent data = new Intent(getBaseContext(), Editor.class); data.putExtra("mnt/sdcard-ext", _ID); startActivity(data);
I find it to be easier to expand this.
Intent i=new Intent(this, Editor.class);
i.putExtra("data1", _ID);
startActivity(data);
In the other Activity:
public void onCreate(Bundle icicle)
{
//===setting content view, any other setup you wanna do
Intent i=getIntent();
String data=i.getStringExtra("data1");
if(data!=null)
//do something with it
else
//the data is null; don't do anything with it or you'll get a NullPointerException
}
I think this is what you wanna do. If not, tell me!
The line int data = getIntent(data).getExtras()
.getInt("mnt/sdcard-ext"); in Activity 3 should probably be moved to the onCreate() method.
Also, when you do putExtra("mnt/sdcard-ext", _ID) and getInt, instead of "mnt/sdcard-ext", you should probably use a package name such as com.example.appname.extraname, as referred to here:
http://developer.android.com/reference/android/content/Intent.html