Android笔记九.Intent异常处理及常用系统调用
Intent intent=new Intent();intent.setClassName("com.tencent.mm","com.tencent.mm.app.MMApplication");startActivity(intent);
Intent intent=new Intent();intent.setClassName("com.tencent.mm","com.tencent.mm.app.MMApplication");startActivity(intent);
(1)拨打电话 Toast.makeText( PocketSphinxDemo.this, "正在启动拨号器,请稍后...", Toast.LENGTH_SHORT).show(); Intent intent1=new Intent(); //创建一个intent intent1.setAction(Intent.ACTION_DIAL); //设置intent的Action属性 intent1.setData(Uri.parse("tel://")); //设置intent的Date属性 startActivity(intent1); //启动Activity //启动Activity (2)打开浏览器 try{ Toast.makeText( PocketSphinxDemo.this, "正在启动浏览器,请稍后...", Toast.LENGTH_SHORT).show(); Uri uri=Uri.parse("http://www.baidu.com"); //将字符串转换为uri对象 Intent intent2=new Intent(Intent.ACTION_VIEW,uri); //创建一个同时指定Action属性和Data属性的intent intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent2); //启动Activity }catch(ActivityNotFoundException e) { Toast.makeText(PocketSphinxDemo.this, " 启动'浏览器'异常!\n请检查是否安装了该应用.", Toast.LENGTH_SHORT).show(); } (3)打开地图 try{ Toast.makeText( PocketSphinxDemo.this, "正在打开地图,请稍后...", Toast.LENGTH_SHORT).show(); Uri uri=Uri.parse("geo:38.899533,-77.036476");//将字符串转换为uri对象 Intent intent3=new Intent(); intent3.setAction(Intent.ACTION_VIEW); intent3.setData(uri); intent3.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent3); } catch(ActivityNotFoundException e) { Toast.makeText(PocketSphinxDemo.this, " 启动'地图'异常!\n请检查是否安装了该应用.", Toast.LENGTH_SHORT).show(); } (3)编辑短信(调用发送短信程序) Toast.makeText( PocketSphinxDemo.this, "正在打开短信,请稍后...", Toast.LENGTH_SHORT).show(); Intent intent4=new Intent(Intent.ACTION_VIEW); //创建一个带Action属性的intent intent4.setType("vnd.android-dir/mms-sms"); startActivity(intent4); (4)查看联系人 Toast.makeText( PocketSphinxDemo.this, "正在启动联系人,请稍后...", Toast.LENGTH_SHORT).show(); Intent intent5 = new Intent(Intent.ACTION_VIEW, ContactsContract.Contacts.CONTENT_URI); startActivity(intent5); (5)打开相机 Toast.makeText( PocketSphinxDemo.this, "正在启动相机,请稍后...", Toast.LENGTH_SHORT).show(); Intent intent7=new Intent(); intent7.setAction(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); //启动相机app startActivity(intent7); (6)打开图库 Toast.makeText( PocketSphinxDemo.this, "正在打开图库,请稍后...", Toast.LENGTH_SHORT).show(); Intent intent8 = new Intent(); intent8.setType("image/*"); intent8.setAction(Intent.ACTION_GET_CONTENT); startActivity(intent8); (7)打开计算器 Toast.makeText( PocketSphinxDemo.this, "正在启动计算器,请稍后...", Toast.LENGTH_SHORT).show(); Intent intent11 = new Intent(); intent11.setClassName("com.android.calculator2","com.android.calculator2.Calculator"); //调用setClassName指定了启动哪个应用程序 startActivity(intent11); (8)打开系统设置 Intent intentSet= new Intent(Settings.ACTION_SETTINGS); startActivity(intentSet); (9)打开时钟 try{ Intent intentclock=new Intent(); intentclock.setClassName("com.android.deskclock", "com.android.deskclock.DeskClock"); startActivity(intentclock); } catch(ActivityNotFoundException e) { Toast.makeText(PocketSphinxDemo.this, " 启动'时钟'异常!\n请检查是否安装了该应用.", Toast.LENGTH_SHORT).show(); } (10)打开文件管理器 try{ Intent intentFile=new Intent(); intentFile.setAction(Intent.ACTION_VIEW); intentFile.setType("text/plain"); startActivity(intentFile); }catch(ActivityNotFoundException e) { Toast.makeText(PocketSphinxDemo.this, " 启动'文件管理器'异常!\n请检查是否安装了该应用.", Toast.LENGTH_SHORT).show(); } (11)打开QQ try{ Toast.makeText( PocketSphinxDemo.this, "正在打开QQ聊天工具,请稍后...", Toast.LENGTH_SHORT).show(); Intent intent12=new Intent(); intent12.setClassName("com.tencent.mobileqq","com.tencent.mobileqq.activity.SplashActivity"); intent12.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent12); } catch(ActivityNotFoundException e) { Toast.makeText(PocketSphinxDemo.this, " 启动'QQ'异常!\n请检查是否安装了该应用.", Toast.LENGTH_SHORT).show(); } (12)打开微信 try{ Toast.makeText( PocketSphinxDemo.this, "正在启动微信客户端,请稍后...", Toast.LENGTH_SHORT).show(); Intent intent4=new Intent(); intent4.setClassName("com.tencent.mm","com.tencent.mm.ui.LauncherUI"); intent4.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent4); } catch(ActivityNotFoundException e) { Toast.makeText(PocketSphinxDemo.this, " 启动'微信'异常!\n请检查是否安装了该应用.", Toast.LENGTH_SHORT).show(); } (13)重启手机 String cmd = "su -c reboot"; try { Toast.makeText(PocketSphinxDemo.this, "正在重启手机,请稍后...", Toast.LENGTH_SHORT).show(); Runtime.getRuntime().exec(cmd); } catch (IOException e) { // TODO Auto-generated catch block new AlertDialog.Builder(PocketSphinxDemo.this).setTitle("Error").setMessage( e.getMessage()).setPositiveButton("OK", null).show(); }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。