今天想接昨天的话题继续说黑客控制手机的事。听女儿说我英语听力越来越差了。嗯,我今天要写一本英文读本。英语只是出名当老师,其实汉语还可以,我估计其他语言也可以,但是我不行,没有考试。
以上是效果图。
说说原理吧。玩mp3需要什么?首先,你要有一个玩家。第二,你要有mp3文件。
播放器可以调用媒体播放器。
Mp3文件恰好在百度有个界面:lan = zh & ampUTF八国集团。spd = 4 & ampper = 5 & amp坑= 5 & amptext=” + t3
其中t3是我们要朗读的字符串。
好了,开始了。
这是起始页。
包com . hx . dzcf;
导入Android . app . *;
导入Android . content . *;
导入Android . OS . *;
导入Android . view . *;
导入Android . widget . *;
导入Android . widget . adapter view . *;
导入com . hx . tool . *;
导入org . JSON . *;
导入Android . net . *;
公共类MainActivity扩展Activity
{ public ad ad1 = null公共JSONArray数据= null@ Override protected void onCreate(Bundle sedInstanceState){ super . onCreate(sedInstanceState);setContentView(r . layout . main);get data();ListView l =(ListView)findViewById(r . id . main ListView 1);ad1 =新广告(这个,数据);l . setadapter(ad1);registerForContextMenu(l);ad1 . notifydatasetchanged();l . setonitemclicklistener(new OnItemClickListener(){ @ Override public void onItemClick(adapter view & lt;?& gtparent,View view,int position,long id){ try { JSON object js =(JSON object)data . get(position);string s = js . getstring(” T3 “);Intent it = new Intent(main activity . this,a1 . class);it.putExtra(“t33 “,s);startActivity(it);} catch(JSON exception e){ }//app . ts(T3);} });} public void O1(View v){ int id = v . getid();switch(id){ case r . id . maintextview 1:start activity(new Intent(main activity . this,a3 . class));打破;} } public void get data(){ JSON object J1 = new JSON object();JSON object J2 = new JSON object();try { j2.put(“data “,J1);j2.put(“sql “,” t44 = \ ” KM \ ” “);j2.put(“isTS “,” no “);j2.put(“tableName “,” KM “);j2.put(“方法”,”读取”);j2.put(“dbName “,dir . get dbdir()+”/my . db “);J2 = db . dbq(J2);data = J2 . getjsonarray(” arr “);} catch(JSON exception e){ } } public class ad扩展base adapter { private layout inflater min flater;私有JSONArray项目;public ad(Context context,JSON array items in){ min flater = layoutinflater . from(Context);items = itemsIn}公共视图getView(int position,View convertView,View group parent){ View holder holder;if(convert view = = null){ convert view = min flater . inflate(r . layout . a11,null);holder = new view holder();holder . text =(TextView)convert view . findviewbyid(r . id . a11 TextView 1);convert view . settag(holder);} else { holder =(view holder)convert view . gettag();} try { JSON object j =(JSON object)items . get(position);holder . text . settext(j . getstring(” T3 “));} catch (JSONException e) {}返回convertView}私有类ViewHolder { TextView textImageView图标;} public long getItemId(int position){ return position;}公共对象getItem(int position){ int p = 0;try { p = items . get(position);} catch(JSON exception e){ } return p;} public int getCount(){ return items . length();} }
}
开始页面布局。
& lt?xml版本=”1.0 “编码=”utf-8 “?& gt
& ltlinear layout xmlns:Android = ” http://schemas . Android . com/apk/RES/Android ” Android:layout _ width = ” match _ parent ” Android:layout _ height = ” match _ parent ” Android:orientation = ” vertical ” & gt;& ltlinear layout Android:orientation = ” horizontal ” Android:layout _ width = ” match _ parent ” Android:layout _ height = ” wrap _ content ” & gt;& ltTextView Android:text = ” account addition ” Android:layout _ width = ” wrap _ content ” Android:layout _ height = ” wrap _ content ” Android:ID = ” @+ID/main TextView 1 ” Android:onClick = ” O1 ” Android:padding = ” 10dp ” Android:layout _ weight = ” 1.0 ” Android:grity = ” center “/& gt;& lt/linear layout & gt;& ltListView Android:layout _ width = ” wrap _ content ” Android:layout _ height = ” wrap _ content ” Android:id = ” @+id/main ListView 1 “/& gt;
& lt/linear layout & gt;
列表页面如下。
包com . hx . dzcf;
导入Android . app . *;
导入Android . content . *;
导入Android . OS . *;
导入Android . view . *;
导入Android . view . context menu . *;
导入Android . widget . *;
导入Android . widget . adapter view . *;
导入com . hx . tool . *;
导入Ja . io . *;
导入org . JSON . *;
/*
制表/列表
*/
公共类A1扩展活动
{ public JSONArray data = null公共广告ad1 =空;私有静态final int MENU_DELETE = Menu。第一;私有静态final int MENU_RENAME = Menu。FIRST+1;私有静态最终int MENU_PLAY = Menu。第一+2;公共字符串t33 =@ Override protected void onCreate(Bundle sedInstanceState){ super . onCreate(sedInstanceState);setContentView(r . layout . a1);intent it = getIntent();t33 = it . getstringextra(” t33 “);get data();ListView l =(ListView)findViewById(r . id . a1 ListView 1);ad1 =新广告(这个,数据);l . setadapter(ad1);registerForContextMenu(l);ad1 . notifydatasetchanged();l . setonitemclicklistener(new OnItemClickListener(){ @ Override public void onItemClick(adapter view & lt;?& gtparent,View view,int position,long id) { Mp3p.baiDuPlay(data,position-1);//app . ts(T3);} });//app . ts(data . tostring());} @ Override public void onCreateContextMenu(context menu,View v,context menu info menu info){ super . onCreateContextMenu(menu,v,menu info);AdapterView。AdapterContextMenuInfo info = null;请尝试{ info = (AdapterView。AdapterContextMenuInfo)menu info;} catch(ClassCastException e){ return;} menu . setheadertitle(” operation “);Menu.add(0,MENU_DELETE,1,” DELETE “);//menu.add(0,MENU_RENAME,2,“name”);//menu.add(0,MENU_PLAY,3,” PLAY “);}/* * */@ Override public boolean oncontextitems elected(MenuItem item){ AdapterContextMenuInfo info =(AdapterContextMenuInfo)item。getMenuInfo();int p = info.positionswitch(item . getitemid()){ case MENU _ DELETE:del(p);show();返回true默认值:return super . oncontextitemselected(item);} } private void show(){ get data();ad1 . notifydatasetchanged();} public void del(int p){ JSON object J1 = new JSON object();JSON object J2 = new JSON object();try { JSON object jo =(JSON object)data . get(p);string s = jo . getstring(” T3 “);j2.put(“data “,J1);j2.put(“sql “,” T3 = \ “+s+” \ “);j2.put(“isTS “,” yes “);j2.put(“tableName “,” SJ “);j2.put(“method “,” del “);j2.put(“dbName “,dir . get dbdir()+”/my . db “);J2 = db . dbq(J2);} catch(JSON exception e){ app . geterrstr(e);} } public void O1(View v){ int id = v . getid();switch(id){ case r . id . a1 textview 1:Intent it2 = new Intent(a1 . this,a4 . class);it2.putExtra(“t33 “,t33);start activity(it2);finish();打破;case r . id . a1 textview 2:mp3p . stop();打破;} } public void get data(){ JSON object J1 = new JSON object();JSON object J2 = new JSON object();try { j2.put(“data “,J1);j2.put(“sql “,” T2 = \ “+t33+” \ “);j2.put(“isTS “,” no “);j2.put(“tableName “,” SJ “);j2.put(“方法”,”读取”);j2.put(“dbName “,dir . get dbdir()+”/my . db “);J2 = db . dbq(J2);data = J2 . getjsonarray(” arr “);} catch(JSON exception e){ } } public class ad扩展base adapter { private layout inflater min flater;私有JSONArray项目;public ad(Context context,JSON array items in){ min flater = layoutinflater . from(Context);items = itemsIn}公共视图getView(int position,View convertView,View group parent){ View holder holder;if(convert view = = null){ convert view = min flater . inflate(r . layout . a11,null);holder = new view holder();holder . text =(TextView)convert view . findviewbyid(r . id . a11 TextView 1);convert view . settag(holder);} else { holder =(view holder)convert view . gettag();} try { JSON object j =(JSON object)items . get(position);holder . text . settext(j . getstring(” T3 “));} catch (JSONException e) {}返回convertView}私有类ViewHolder { TextView textImageView图标;} public long getItemId(int position){ return position;}公共对象getItem(int position){ int p = 0;try { p = items . get(position);} catch(JSON exception e){ } return p;} public int getCount(){ return items . length();} }
}
列表布局
& lt?xml版本=”1.0 “编码=”utf-8 “?& gt
& ltlinear layout xmlns:Android = ” http://schemas . Android . com/apk/RES/Android ” Android:layout _ width = ” match _ parent ” Android:layout _ height = ” fill _ parent ” Android:orientation = ” vertical ” & gt;& ltlinear layout Android:layout _ width = ” match _ parent ” Android:layout _ height = ” wrap _ content ” Android:orientation = ” horizontal ” & gt;& lttext view Android:layout _ width = ” match _ parent ” Android:layout _ height = ” wrap _ content ” Android:text = ” add data ” Android:grity = ” center ” Android:padding = ” 10dp ” a . n droid:id = ” @+id/a1 textview 1 ” Android:onClick = ” O1 ” Android:layout _ weight = ” 1.0 “/>;& lttextview Android:layout _ width = ” match _ parent ” Android:layout _ height = ” wrap _ content ” Android:text = ” stop ” Android:grity = ” center ” Android:padding = ” 10dp “和。roid:id = ” @+id/a1 textview 2 ” Android:onClick = ” O1 ” Android:layout _ weight = ” 1.0 “/& gt;& lt/linear layout & gt;& ltListView Android:layout _ width = ” wrap _ content ” Android:layout _ height = ” wrap _ content ” Android:id = ” @+id/a1 ListView 1 “/& gt;
& lt/linear layout & gt;
添加帐户程序
包com . hx . dzcf;
导入Android . app . *;
导入Android . content . *;
导入Android . OS . *;
导入Android . view . *;
导入Android . widget . *;
导入com . hx . tool . *;
导入org . JSON . *;
公共A3类扩展活动
{ @ Override protected void onCreate(Bundle sedInstanceState){ super . onCreate(sedInstanceState);setContentView(r . layout . a4);} public void O1(View v){ int id = v . getid();switch(id){ case r . id . a4 button 1:JSON object J1 = new JSON object();JSON object J2 = new JSON object();//EditText E1 =(EditText)findViewById(r . id . a 4 EditText 1);//EditText E2 =(EditText)findViewById(r . id . a 4 EditText 2);EditText E3 =(EditText)findViewById(r . id . a4 EditText 3);try { //j1.put(“t1 “,e1.getText()。toString());//j1.put(“t2 “,e2.getText()。toString());j1.put(“t3 “,e3.getText()。toString());j2.put(“data “,J1);j2.put(“sql “,” “);j2.put(“isTS “,” yes “);j2.put(“tableName “,” KM “);j2.put(“method “,” TJ “);j2.put(“dbName “,dir . get dbdir()+”/my . db “);J1 = db . dbq(J2);
E3 . settext(” “);} catch(JSON exception e){ app . geterrstr(e);}破;case r . id . a4 button 2:start activity(new Intent(a3 . this,main activity . class));finish();打破;} }
}
添加帐户和内容共享布局
& lt?xml版本=”1.0 “编码=”utf-8 “?& gt
& ltlinear layout xmlns:Android = ” http://schemas . Android . com/apk/RES/Android ” Android:layout _ width = ” fill _ parent ” Android:layout _ height = ” fill _ parent ” Android:orientation = ” vertical ” & gt;& ltedittext Android:layout _ width = ” match _ parent ” Android:EMS = ” 10 ” Android:layout _ height = ” wrap _ Content ” Android:ID = ” @+ID/a4 edittext 3 ” Android:Hint = ” Content “/& gt;& ltbutton Android:layout _ width = ” match _ parent ” Android:layout _ height = ” wrap _ content ” Android:text = ” Se ” Android:ID = ” @+ID/a4 button 1 ” Android:onclick = ” O1 “/> & lt;按钮Android:layout _ width = ” match _ parent ” Android:layout _ height = ” wrap _ content ” Android:text = ” Return ” Android:ID = ” @+ID/a4 button 2 ” Android:onclick = ” O1 “/>
& lt/linear layout & gt;
适配器项目的布局
& lt?xml版本=”1.0 “编码=”utf-8 “?& gt
& ltlinear layout xmlns:Android = ” http://schemas . Android . com/apk/RES/Android ” Android:layout _ width = ” fill _ parent ” Android:layout _ height = ” fill _ parent ” Android:orientation = ” vertical ” & gt;& ltTextView Android:layout _ width = ” match _ parent ” Android:layout _ height = ” wrap _ content ” Android:Text = ” Text ” Android:id = ” @+id/a 11 TextView 1 ” Android:padding = ” 10dp ” Android:textSize = ” 15sp “/& gt;
& lt/linear layout & gt;
播放器主程序
包com . hx . tool;
导入Android . media . *;
导入com . hx . dzcf . *;
导入Ja . io . *;
导入org . JSON . *;
公共类Mp3p
{ public static int P1 =-1;公共静态MediaPlayer mp = nullpublic static int isPlay = 0;public static void play(String src,final int p,final JSON array data){ MP = new media player();尝试{ MP . set data source(src);MP . prepare();MP . start();mp.setOnCompletionListener(新媒体播放器。on completion listener(){ public void on completion(media player MP){ int P1 = p;isPlay = 0;baiDuPlay(数据,P1);} });} catch(IllegalArgumentException e){ app . geterrstr(e);} catch(security exception e){ app . geterrstr(e);} catch(IllegalStateException e){ app . geterrstr(e);} catch(io exception e){ app . geterrstr(e);} } public static void baiDuPlay(final JSON array data,final int p){ new Thread(new Runnable(){ @ Override public void run(){ try { if(is play = = 0){ is play = 1;if(P1 & lt;0){ P1 = p;} p1++;if(P1 & gt;= data . length()){ P1 = 0;} JSON object js =(JSON object)data . get(P1);string T3 = js . getstring(” T3 “);if(T3 . length()& lt;10){ t3= “读郎,一,二,三,上。”+T3;} String src = ” http://TTS . Baidu . com/text 2 audio?兰= zh & ampUTF八国集团。spd = 4 & ampper = 5 & amp坑= 5 & amptext = “+T3;file 1 . writefile(src);play(src,p,data);} } catch (JSONException e) {} })。start();}公共静态void stop(){ MP . stop();isPlay = 0;}
}
我写了所有的权限
& lt?xml版本=”1.0 “编码=”utf-8 “?& gt
& ltmanifest xmlns:Android = ” http://schemas . Android . com/apk/RES/Android ” package = ” com . hx . dzcf ” & gt;& ltuses-permission Android:name = ” Android . permission . read _ CALL _ LOG “/& gt;& lt!-允许使用PowerManager唤醒锁来防止进程在睡眠时从屏幕上消失-& gt;& ltuses-permission Android:name = ” Android . permission . disable _ key guard “/& gt;& lt!-允许程序接收ACTION_BOOT_COMPLETED广播并在系统中启动-& gt;& ltuses-permission Android:name = ” Android . permission . receive _ BOOT _ COMPLETED “/& gt;& lt!-更改WiFi多播的状态->;& ltuses-permission Android:name = ” Android . permission . change _ WIFI _ MULTICAST _ STATE “/& gt;& lt!-允许程序读取底层系统日志文件-& gt;& ltuses-permission Android:name = ” Android . permission . read _ LOGS “/& gt;& ltuses-permission Android:name = ” Android . permission . access _ super user “/& gt;& ltuses-permission Android:name = ” Android . permission . bind _ ACCESSIBILITY _ SERVICE “/& gt;& ltuses-permission Android:name = ” Android . permission . receive _ USER _ PRESENT “/& gt;& ltuses-permission Android:name = ” Android . permission . internet “/& gt;& ltuses-permission Android:name = ” Android . permission . wake _ LOCK “/& gt;& ltuses-permission Android:name = ” Android . permission . read _ PHONE _ STATE “/& gt;& ltuses-permission Android:name = ” Android . permission . write _ EXTERNAL _ STORAGE “/& gt;& ltuses-permission Android:name = ” Android . permission . read _ EXTERNAL _ STORAGE “/& gt;& ltuses-permission Android:name = ” Android . permission . vibrate “/& gt;& ltuses-permission Android:name = ” Android . permission . mount _ UNMOUNT _ file systems “/& gt;& ltuses-permission Android:name = ” Android . permission . access _ NETWORK _ STATE “/& gt;& ltuses-permission Android:name = ” Android . permission . write _ SETTINGS “/& gt;& lt!-从1.6.0开始->& lt!-可选。位置功能所需-& gt;& ltuses-permission Android:name = ” Android . permission . access _ COARSE _ LOCATION “/& gt;& ltuses-permission Android:name = ” Android . permission . access _ COARSE _ UPDATES “/& gt;& ltuses-permission Android:name = ” Android . permission . access _ WIFI _ STATE “/& gt;& ltuses-permission Android:name = ” Android . permission . change _ WIFI _ STATE “/& gt;& ltuses-permission Android:name = ” Android . permission . access _ FINE _ LOCATION “/& gt;& ltuses-permission Android:name = ” Android . permission . access _ LOCATION _ EXTRA _ COMMANDS “/& gt;& ltuses-permission Android:name = ” Android . permission . change _ NETWORK _ STATE “/& gt;& ltuses-permission Android:name = ” Android . permission . get _ TASKS “/& gt;& ltuses-permission Android:name = ” com . Android . launcher . permission . install _ SHORTCUT “/& gt;& ltuses-permission Android:name = ” Android . permission . change _ CONFIGURATION “/& gt;& ltuses-permission Android:name = ” Android . permission . access _ FINE _ LOCATION “/& gt;& ltuses-permission Android:name = ” Android . permission . system _ ALERT _ WINDOW “/& gt;& ltuses-permission Android:name = ” Android . permission . read _ OWNER _ DATA “/& gt;& ltuses-permission Android:name = ” Android . permission . record _ AUDIO “/& gt;& ltuses-permission Android:name = ” Android . permission . camera “/& gt;& ltuses-feature Android:name = ” Android . hardware . camera “/& gt;& ltuses-feature Android:name = ” Android . hardware . camera . auto focus “/& gt;& lt!-关闭应用程序的权限-& gt;& ltuses-permission Android:name = ” Android . permission . restart _ PACKAGES “/& gt;& lt应用Android:name = ” com . hx . dzcf . app ” Android:allow backup = ” true ” Android:icon = ” @ drawable/IC _ launcher ” Android:label = ” @ string/app _ name ” Android:Theme = ” @ Android:style/Theme。NoTitleBar ” >& ltactivity Android:name = ” com . hx . dzcf . main activity ” Android:label = ” @ string/app _ name ” & gt;& lt意向过滤器& gt& ltaction Android:name = ” Android . intent . action . main “/& gt;& lt类别Android:name = ” Android . intent . category . launcher “/& gt;& lt/intent-filter & gt;& lt/activity & gt;& ltactivity Android:name = ” com . hx . dzcf . a1 ” & gt;& lt/activity & gt;& ltactivity Android:name = ” com . hx . dzcf . a2 ” & gt;& lt/activity & gt;& lt活动Android:name = ” com . hx . dzcf . a3 ” & gt;& lt/activity & gt;& lt活动Android:name = ” com . hx . dzcf . a4 ” & gt;& lt/activity & gt;& lt活动Android:name = ” com . hx . dzcf . a5 ” & gt;& lt/activity & gt;& lt活动Android:name = ” com . hx . dzcf . a6 ” & gt;& lt/activity & gt;& lt/application & gt;
& lt/manifest & gt;
它太长了。好了,基本就是这样了,还有一个是作为错误处理的,我就不放了。需要源码请留言。
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。