android - How to select picture from gallery? -
iam trying select picture gallery in emulator. when clicks browse eclipse shows w/iinputconnectionwrapper: showstatusicon on inactive inputconnection
in logcat emulator takes me gallery. when chose 1 picture not getting selected.iam using below code:
package com.textapi; import android.app.activity; import android.content.intent; import android.database.cursor; import android.net.uri; import android.os.bundle; import android.provider.mediastore; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.toast; public class sendmmsactivity extends activity { private static final int select_picture = 1; private string selectedpath, extension = ""; uri selectedvideouri; button btnbrowse; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.send_mms); btnbrowse=(button)findviewbyid(r.id.bnbrowse); btnbrowse.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { // todo auto-generated method stub intent intent = new intent(); intent.settype("image/*"); intent.setaction(intent.action_get_content); startactivityforresult( intent.createchooser(intent,"select picture"), select_picture); } }); } public void onactivityresult(int requestcode, int resultcode, final intent data) { if (resultcode == result_ok) { if (requestcode == select_picture) { selectedvideouri = data.getdata(); selectedpath = getpath(selectedvideouri); system.out.println("path--->>"+selectedpath); int pos = selectedpath.lastindexof("."); if (pos > 0) { extension = selectedpath.substring(pos + 1); } } } } // can path of video using method. public string getpath(uri uri) { string[] projection = { mediastore.images.media.data }; cursor cursor = managedquery(uri, projection, null, null, null); int column_index = cursor .getcolumnindexorthrow(mediastore.images.media.data); cursor.movetofirst(); return cursor.getstring(column_index); } }
please me select picture. , need send picture gallery mobile number using mvaayoo
api. please me if knows.
public class mainactivity extends activity { private static int result_load_image = 1; uri mypicture = null; button buttonloadimage; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); //getting view buttonloadimage = (button) findviewbyid(r.id.button2); buttonloadimage.setonclicklistener(new view.onclicklistener() { @override public void onclick(view arg0) { intent = new intent( intent.action_pick, android.provider.mediastore.images.media.external_content_uri); startactivityforresult(i, result_load_image); } }); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); if (requestcode == result_load_image && resultcode == result_ok && null != data) { uri selectedimage = data.getdata(); string[] filepathcolumn = { mediastore.images.media.data }; cursor cursor = getcontentresolver().query(selectedimage, filepathcolumn, null, null, null); cursor.movetofirst(); int columnindex = cursor.getcolumnindex(filepathcolumn[0]); string picturepath = cursor.getstring(columnindex); cursor.close(); imageview imageview = (imageview) findviewbyid(r.id.imageview1); imageview.setimagebitmap(bitmapfactory.decodefile(picturepath)); } } }
Comments
Post a Comment