ACTION_MAIN android.intent.action.MAIN 应用程序入口
ACTION_VIEW android.intent.action.VIEW 显示数据给用户
ACTION_ATTACH_DATA android.intent.action.ATTACH_DATA 指明附加信息给其他地方的一些数据
ACTION_EDIT android.intent.action.EDIT 显示可编辑的数据
ACTION_PICK android.intent.action.PICK 选择数据
ACTION_CHOOSER android.intent.action.CHOOSER 显示一个Activity选择器
ACTION_GET_CONTENT android.intent.action.GET_CONTENT 获得内容
ACTION_DIAL android.intent.action.GET_CONTENT 显示打电话面板
ACITON_CALL android.intent.action.DIAL 直接打电话
ACTION_SEND android.intent.action.SEND 直接发短信
ACTION_SENDTO android.intent.action.SENDTO 选择发短信
ACTION_ANSWER android.intent.action.ANSWER 应答电话
ACTION_INSERT android.intent.action.INSERT 插入数据
ACTION_DELETE android.intent.action.DELETE 删除数据
ACTION_RUN android.intent.action.RUN 运行数据
ACTION_SYNC android.intent.action.SYNC 同步数据
ACTION_PICK_ACTIVITY android.intent.action.PICK_ACTIVITY 选择Activity
ACTION_SEARCH android.intent.action.SEARCH 搜索
ACTION_WEB_SEARCH android.intent.action.WEB_SEARCH Web搜索
ACTION_FACTORY_TEST android.intent.action.FACTORY_TEST 工厂测试入口点
------------------------------------布局文件----------------------------------------------------------
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Android中常用系统Intent" />
<Button
android:id="@+id/intent_call_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="拨打电话" />
<Button
android:id="@+id/intent_sms_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="发送短信" />
<Button
android:id="@+id/intent_email_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="发送邮件" />
<Button
android:id="@+id/intent_net_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="打开网页" />
<Button
android:id="@+id/intent_pic_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="发送图片" />
<Button
android:id="@+id/intent_media_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="打开媒体" />
<Button
android:id="@+id/intent_search_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="搜索" />
<Button
android:id="@+id/intent_install_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="安装软件" />
<Button
android:id="@+id/intent_unstall_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="卸载软件" />
</LinearLayout>
</ScrollView>
----------------------------Activity代码--------------------------------------------------------
public class MainActivity extends Activity implements OnClickListener {
private Button callBtn;
private Button smsBtn;
private Button emailBtn;
private Button browseBtn;
private Button searchBtn;
private Button installBtn;
private Button unInstallBtn;
private Button mediaBtn;
private Button picBtn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViewsById();
initListeners();
}
private void initViewsById() {
callBtn = (Button) findViewById(R.id.intent_call_btn);
smsBtn = (Button) findViewById(R.id.intent_sms_btn);
emailBtn = (Button) findViewById(R.id.intent_email_btn);
browseBtn = (Button) findViewById(R.id.intent_net_btn);
picBtn = (Button) findViewById(R.id.intent_pic_btn);
installBtn = (Button) findViewById(R.id.intent_install_btn);
unInstallBtn = (Button) findViewById(R.id.intent_unstall_btn);
mediaBtn = (Button) findViewById(R.id.intent_media_btn);
searchBtn = (Button) findViewById(R.id.intent_search_btn);
}
private void initListeners() {
callBtn.setOnClickListener(this);
smsBtn.setOnClickListener(this);
emailBtn.setOnClickListener(this);
browseBtn.setOnClickListener(this);
picBtn.setOnClickListener(this);
installBtn.setOnClickListener(this);
unInstallBtn.setOnClickListener(this);
mediaBtn.setOnClickListener(this);
searchBtn.setOnClickListener(this);
}
/**浏览器 */
private void netBrowse() {
/**地址*/
Uri uri = Uri.parse("http://www.baidu.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
/**视频 */
private void playMedia() {
/**uri*/
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
/**搜索 */
private void search() {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, "android");
startActivity(intent);
}
/**拨打电话 */
private void callTelphone() {
/**电话号码 */
Uri uri = Uri.parse("tel:10086");
Intent intent = new Intent(Intent.ACTION_DIAL, uri);
startActivity(intent);
}
/**发短信Activity */
private void sendSms() {
Uri uri = Uri.parse("smsto:10086");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
startActivity(intent);
}
/**发送图片(彩信) */
@SuppressLint("SdCardPath")
private void sendPicSms() {
/**图片位置*/
Uri imguri = Uri.parse("/mnt/sdcard/abc.png");
Intent intent = new Intent(Intent.ACTION_SEND);
/**图片流数据*/
intent.putExtra(Intent.EXTRA_STREAM, imguri);
/**指定类型*/
intent.setType("image/png");
startActivity(Intent.createChooser(intent, "Send Image To:"));
}
/**发邮件 */
private void sendEmail() {
Intent intent = new Intent(Intent.ACTION_SEND);
/**收件人*/
String[] to = { "[email protected]" };
intent.putExtra(Intent.EXTRA_EMAIL, to);
/** 抄送*/
String[] cc = { "[email protected]" };
intent.putExtra(Intent.EXTRA_CC, cc);
/**邮件主题*/
intent.putExtra(Intent.EXTRA_SUBJECT, "朋友,您好!");
/**邮件内容*/
intent.putExtra(Intent.EXTRA_TEXT, "好多的内容呀........");
/**类型/格式*/
intent.setType("message/rfc822");
startActivity(Intent.createChooser(intent, "请选择客户端邮箱!"));
}
/**安装应用 */
private void installSotf() {
/**地址*/
Intent intent = new Intent(Intent.ACTION_VIEW);
/**指定apk文件路径*/
intent.setDataAndType(Uri.fromFile(new File("/mnt/sdcard/tutu.apk")), "application/vnd.android.package-archive");
startActivity(intent);
}
/**卸载应用程序 */
private void uninstallSoft() {
Uri uri = Uri.fromParts("package", "tutu.ch05", null);
Intent it = new Intent(Intent.ACTION_DELETE, uri);
startActivity(it);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.intent_call_btn:
callTelphone();
break;
case R.id.intent_sms_btn:
sendSms();
break;
case R.id.intent_email_btn:
sendEmail();
break;
case R.id.intent_pic_btn:
sendPicSms();
break;
case R.id.intent_net_btn:
netBrowse();
break;
case R.id.intent_search_btn:
search();
break;
case R.id.intent_install_btn:
installSotf();
break;
case R.id.intent_unstall_btn:
uninstallSoft();
break;
case R.id.intent_media_btn:
playMedia();
break;
}
}
}
-------------------------------------------相应的权限------------------------------------------------------
<uses-permission android:name="android.permission.CALL_PHONE">
<uses-permission android:name="android.permission.INTENT">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>