java - Copy fileto SD Card from Raw folder after context-menu selection? -
i'm (slowly) making app displays list of tones , lets user "long press" 1 brings context menu asking if you'd copy sd card. problem last part, need help. tones stored in raw folder, , need it copies selected tone file sd card, preferably in notifications folder.
just wondering if give me example of how go because i'm absolutely lost?
here's code
import java.util.arraylist; import android.app.listactivity; import android.media.mediaplayer; import android.os.bundle; import android.view.contextmenu; import android.view.contextmenu.contextmenuinfo; import android.view.menuinflater; import android.view.menuitem; import android.view.view; import android.widget.adapterview.adaptercontextmenuinfo; import android.widget.listview; import android.widget.toast; public class mainactivity extends listactivity { private arraylist<sound> msounds = null; private soundadapter madapter = null; static mediaplayer mmediaplayer = null; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); registerforcontextmenu(getlistview()); this.getlistview().setselector(r.drawable.selector); //create simple list msounds = new arraylist<sound>(); sound s = new sound(); s.setdescription("anjels"); s.setsoundresourceid(r.raw.anjels); msounds.add(s); s = new sound(); s.setdescription("fizz"); s.setsoundresourceid(r.raw.fizz); msounds.add(s); s = new sound(); s.setdescription("flipper"); s.setsoundresourceid(r.raw.flipper); msounds.add(s); s = new sound(); s.setdescription("glass key"); s.setsoundresourceid(r.raw.glasskey); msounds.add(s); s = new sound(); s.setdescription("halo"); s.setsoundresourceid(r.raw.halo); msounds.add(s); madapter = new soundadapter(this, r.layout.list_row, msounds); setlistadapter(madapter); } @override public void onlistitemclick(listview parent, view v, int position, long id){ sound s = (sound) msounds.get(position); mediaplayer mp = mediaplayer.create(this, s.getsoundresourceid()); mp.start(); }@override public void oncreatecontextmenu(contextmenu menu, view v, contextmenuinfo menuinfo) { super.oncreatecontextmenu(menu, v, menuinfo); menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.context_menu, menu); } @override public boolean oncontextitemselected(menuitem item) { adaptercontextmenuinfo info = (adaptercontextmenuinfo) item.getmenuinfo(); int length = msounds.size(); // length of msounds object string[] names = new string[length]; // creates fixed array strings for(int = 0; < length; i++) { // add sound name string array names[i] = msounds.get(i).getdescription(); // returns string name } switch(item.getitemid()) { case r.id.copytosd: toast.maketext(this, "applying " + getresources().getstring(r.string.copy) + " " + names[(int)info.id], toast.length_short).show(); return true; default: return super.oncontextitemselected(item); } }}
refer below links. you..
Comments
Post a Comment