Intent常用系统调用
来源:互联网 发布:手机淘宝掌柜热卖在哪 编辑:程序博客网 时间:2024/05/16 06:52
/********************************************************** * @文件名称:Test.java * @创建时间:2014年11月20日 下午11:16:40 * @修改历史:2014年11月20日 **********************************************************/package com.jinlin.intentdemo;import java.io.IOException;import android.app.Activity;import android.app.AlertDialog;import android.content.ActivityNotFoundException;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.provider.ContactsContract;import android.provider.MediaStore;import android.provider.Settings;import android.view.View;import android.view.View.OnClickListener;import android.widget.Toast;/** * @author J!nl!n * @date 2014年11月20日 * @time 下午11:16:40 * @type Test.java * @todo */public class Test extends Activity implements OnClickListener {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);findViewById(R.id.Button1).setOnClickListener(this);findViewById(R.id.Button2).setOnClickListener(this);findViewById(R.id.Button3).setOnClickListener(this);findViewById(R.id.Button4).setOnClickListener(this);findViewById(R.id.Button5).setOnClickListener(this);findViewById(R.id.Button6).setOnClickListener(this);findViewById(R.id.Button7).setOnClickListener(this);findViewById(R.id.Button8).setOnClickListener(this);findViewById(R.id.Button9).setOnClickListener(this);findViewById(R.id.Button10).setOnClickListener(this);findViewById(R.id.Button11).setOnClickListener(this);findViewById(R.id.Button12).setOnClickListener(this);findViewById(R.id.Button13).setOnClickListener(this);findViewById(R.id.Button14).setOnClickListener(this);}@Overridepublic void onClick(View view) {switch (view.getId()) {// 拨打电话case R.id.Button1:Toast.makeText(Test.this, "正在启动拨号器,请稍后...", Toast.LENGTH_SHORT).show();Intent intent1 = new Intent(); // 创建一个intentintent1.setAction(Intent.ACTION_DIAL); // 设置intent的Action属性intent1.setData(Uri.parse("tel://")); // 设置intent的Date属性startActivity(intent1); // 启动Activity //启动Activitybreak;// 打开浏览器case R.id.Button2:try {Toast.makeText(Test.this, "正在启动浏览器,请稍后...", Toast.LENGTH_SHORT).show();Uri uri = Uri.parse("http://www.baidu.com"); // 将字符串转换为uri对象Intent intent2 = new Intent(Intent.ACTION_VIEW, uri); // 创建一个同时指定Action属性和Data属性的intentintent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);startActivity(intent2); // 启动Activity} catch (ActivityNotFoundException e) {Toast.makeText(Test.this, " 启动'浏览器'异常!\n请检查是否安装了该应用.", Toast.LENGTH_SHORT).show();}break;// 打开地图case R.id.Button3:try {Toast.makeText(Test.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(Test.this, " 启动'地图'异常!\n请检查是否安装了该应用.", Toast.LENGTH_SHORT).show();}break;// 编辑短信(调用发送短信程序)case R.id.Button4:Toast.makeText(Test.this, "正在打开短信,请稍后...", Toast.LENGTH_SHORT).show();Intent intent4 = new Intent(Intent.ACTION_VIEW); // 创建一个带Action属性的intentintent4.setType("vnd.android-dir/mms-sms");startActivity(intent4);break;// 查看联系人case R.id.Button5:Toast.makeText(Test.this, "正在启动联系人,请稍后...", Toast.LENGTH_SHORT).show();Intent intent5 = new Intent(Intent.ACTION_VIEW, ContactsContract.Contacts.CONTENT_URI);startActivity(intent5);break;// 打开相机case R.id.Button6:Toast.makeText(Test.this, "正在启动相机,请稍后...", Toast.LENGTH_SHORT).show();Intent intent6 = new Intent();intent6.setAction(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); // 启动相机appstartActivity(intent6);break;// 打开图库case R.id.Button7:Toast.makeText(Test.this, "正在打开图库,请稍后...", Toast.LENGTH_SHORT).show();Intent intent7 = new Intent();intent7.setType("image/*");intent7.setAction(Intent.ACTION_GET_CONTENT);startActivity(intent7);break;// 打开计算器case R.id.Button8:Toast.makeText(Test.this, "正在启动计算器,请稍后...", Toast.LENGTH_SHORT).show();Intent intent8 = new Intent();intent8.setClassName("com.android.calculator2", "com.android.calculator2.Calculator"); // 调用setClassName指定了启动哪个应用程序startActivity(intent8);break;// 打开系统设置case R.id.Button9:Intent intentSet = new Intent(Settings.ACTION_SETTINGS);startActivity(intentSet);break;// 打开时钟case R.id.Button10:try {Intent intentclock = new Intent();intentclock.setClassName("com.android.deskclock", "com.android.deskclock.DeskClock");startActivity(intentclock);} catch (ActivityNotFoundException e) {Toast.makeText(Test.this, " 启动'时钟'异常!\n请检查是否安装了该应用.", Toast.LENGTH_SHORT).show();}break;// 打开文件管理器case R.id.Button11:try {Intent intentFile = new Intent();intentFile.setAction(Intent.ACTION_VIEW);intentFile.setType("text/plain");startActivity(intentFile);} catch (ActivityNotFoundException e) {Toast.makeText(Test.this, " 启动'文件管理器'异常!\n请检查是否安装了该应用.", Toast.LENGTH_SHORT).show();}break;// 打开QQcase R.id.Button12:try {Toast.makeText(Test.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(Test.this, " 启动'QQ'异常!\n请检查是否安装了该应用.", Toast.LENGTH_SHORT).show();}break;// 打开微信case R.id.Button13:try {Toast.makeText(Test.this, "正在启动微信客户端,请稍后...", Toast.LENGTH_SHORT).show();Intent intent13 = new Intent();intent13.setClassName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");intent13.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);startActivity(intent13);} catch (ActivityNotFoundException e) {Toast.makeText(Test.this, " 启动'微信'异常!\n请检查是否安装了该应用.", Toast.LENGTH_SHORT).show();}break;// 重启手机case R.id.Button14:String cmd = "su -c reboot";try {Toast.makeText(Test.this, "正在重启手机,请稍后...", Toast.LENGTH_SHORT).show();Runtime.getRuntime().exec(cmd);} catch (IOException e) {// TODO Auto-generated catch blocknew AlertDialog.Builder(Test.this).setTitle("Error").setMessage(e.getMessage()).setPositiveButton("OK", null).show();}break;default:break;}}}
源码下载
0 0
- Intent常用系统调用
- Intent 常用调用系统action
- 调用系统应用常用uri & intent设置
- 分享:用Intent调用常用的系统组件
- 【Android】调用系统应用常用uri & intent设置
- 【Android】调用系统应用常用uri & intent设置
- 总结a:android系统常用的intent调用
- Android调用系统组件常用uri & intent设置
- 【Android学习笔记】用intent调用常用的系统组件
- 【Android】调用系统应用常用uri & intent设置
- Android调用系统应用常用uri & intent设置
- Android笔记五.Intent异常处理及常用系统调用
- 常用Intent调用代码
- android 系统Intent调用
- Intent 调用系统程序
- android 系统Intent调用
- Intent 调用系统图片库
- 调用系统 隐式intent
- JSF中selectonemenu中前后台交互的问题和javascript访问h:form中控件的问题
- android文件选择的实现
- DES/3DES/AES 加密算法区别
- LeetCode: Single Number II
- android--监听按键
- Intent常用系统调用
- Leetcode Count and Say
- 机器学习基础知识-回归与梯度下降法
- ZOJ--3574--Under Attack II【线段树+欧拉公式】
- 手动创建数据库脚本以及报错处理:ORA-01519ORA-00604ORA-30012
- 会场安排问题(南阳oj14)(贪心-区间不重叠)
- WEBERP测试实录:一 webERP安装
- C++ STL map类型简介
- android之Android.mk小结