Android学习笔记之使用意图打开内置应用程序组件

本文主要是介绍Android学习笔记之使用意图打开内置应用程序组件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!


(1)布局文件如下:

<RelativeLayout 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"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context=".MainActivity" ><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_alignParentTop="true"android:onClick="IntentTest"android:text="从Google搜索内容" /><Buttonandroid:id="@+id/button2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/button1"android:layout_below="@+id/button1"android:onClick="IntentTest"android:text="游览网页" /><Buttonandroid:id="@+id/button3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/button2"android:layout_below="@+id/button2"android:onClick="IntentTest"android:text="显示地图" /><Buttonandroid:id="@+id/button4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/button3"android:layout_below="@+id/button3"android:onClick="IntentTest"android:text="拨打电话" /><Buttonandroid:id="@+id/button5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/button4"android:layout_centerVertical="true"android:onClick="IntentTest"android:text="发短信" /><Buttonandroid:id="@+id/button6"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/button5"android:layout_below="@+id/button5"android:onClick="IntentTest"android:text="播放多媒体" /><Buttonandroid:id="@+id/button7"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignRight="@+id/button4"android:layout_below="@+id/button6"android:onClick="IntentTest"android:text="安装APK" /><Buttonandroid:id="@+id/button8"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/button7"android:layout_below="@+id/button7"android:onClick="IntentTest"android:text="卸载APK" /></RelativeLayout>

(2)MainActivity.java

package com.example.intent_openinterapplicationapi;import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;public class MainActivity extends Activity {private Button button1;private Button button2;private Button button3;private Button button4;private Button button5;private Button button6;private Button button7;private Button button8;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);button1 = (Button) this.findViewById(R.id.button1);button2 = (Button) this.findViewById(R.id.button2);button3 = (Button) this.findViewById(R.id.button3);button4 = (Button) this.findViewById(R.id.button4);button5 = (Button) this.findViewById(R.id.button5);button6 = (Button) this.findViewById(R.id.button6);button7 = (Button) this.findViewById(R.id.button7);button8 = (Button) this.findViewById(R.id.button8);}public void IntentTest(View v) {switch (v.getId()) {case R.id.button1:Intent intent = new Intent();intent.setAction(Intent.ACTION_WEB_SEARCH);intent.putExtra(SearchManager.QUERY, "searchString");startActivity(intent);break;case R.id.button2:Uri uri = Uri.parse("http://www.baidu.com");Intent intent2 = new Intent(Intent.ACTION_VIEW, uri);startActivity(intent2);break;case R.id.button3:Uri uri1 = Uri.parse("geo:38.899533,77.036476");Intent intent3 = new Intent(Intent.ACTION_VIEW, uri1);startActivity(intent3);break;case R.id.button4:Uri uri2 = Uri.parse("tel:18080808080");Intent intent4 = new Intent(Intent.ACTION_DIAL, uri2);startActivity(intent4);break;case R.id.button5:Intent intent5 = new Intent(Intent.ACTION_VIEW);intent5.putExtra("sms_body", "The SMS TEXT!");intent5.setType("vnd.android-dir/mms-sms");startActivity(intent5);break;case R.id.button6:Intent intent6 = new Intent(Intent.ACTION_VIEW);Uri uri3 = Uri.parse("file:///sdcard/song.mp3");intent6.setDataAndType(uri3, "audio/mp3");startActivity(intent6);break;case R.id.button7:Uri installUri = Uri.fromParts("package", "xxx", null);Intent intent7 = new Intent(Intent.ACTION_PACKAGE_ADDED);startActivity(intent7);break;case R.id.button8:Uri deletellUri = Uri.fromParts("package", "strPackageName", null);Intent intent8 = new Intent(Intent.ACTION_DELETE, deletellUri);startActivity(intent8);break;default:break;}}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}


这篇关于Android学习笔记之使用意图打开内置应用程序组件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/997220

相关文章

Python中模块graphviz使用入门

《Python中模块graphviz使用入门》graphviz是一个用于创建和操作图形的Python库,本文主要介绍了Python中模块graphviz使用入门,具有一定的参考价值,感兴趣的可以了解一... 目录1.安装2. 基本用法2.1 输出图像格式2.2 图像style设置2.3 属性2.4 子图和聚

windows和Linux使用命令行计算文件的MD5值

《windows和Linux使用命令行计算文件的MD5值》在Windows和Linux系统中,您可以使用命令行(终端或命令提示符)来计算文件的MD5值,文章介绍了在Windows和Linux/macO... 目录在Windows上:在linux或MACOS上:总结在Windows上:可以使用certuti

CentOS和Ubuntu系统使用shell脚本创建用户和设置密码

《CentOS和Ubuntu系统使用shell脚本创建用户和设置密码》在Linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设置密码,本文写了一个shell... 在linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设

Python使用Matplotlib绘制3D曲面图详解

《Python使用Matplotlib绘制3D曲面图详解》:本文主要介绍Python使用Matplotlib绘制3D曲面图,在Python中,使用Matplotlib库绘制3D曲面图可以通过mpl... 目录准备工作绘制简单的 3D 曲面图绘制 3D 曲面图添加线框和透明度控制图形视角Matplotlib

Pandas中统计汇总可视化函数plot()的使用

《Pandas中统计汇总可视化函数plot()的使用》Pandas提供了许多强大的数据处理和分析功能,其中plot()函数就是其可视化功能的一个重要组成部分,本文主要介绍了Pandas中统计汇总可视化... 目录一、plot()函数简介二、plot()函数的基本用法三、plot()函数的参数详解四、使用pl

使用Python实现IP地址和端口状态检测与监控

《使用Python实现IP地址和端口状态检测与监控》在网络运维和服务器管理中,IP地址和端口的可用性监控是保障业务连续性的基础需求,本文将带你用Python从零打造一个高可用IP监控系统,感兴趣的小伙... 目录概述:为什么需要IP监控系统使用步骤说明1. 环境准备2. 系统部署3. 核心功能配置系统效果展

使用Java将各种数据写入Excel表格的操作示例

《使用Java将各种数据写入Excel表格的操作示例》在数据处理与管理领域,Excel凭借其强大的功能和广泛的应用,成为了数据存储与展示的重要工具,在Java开发过程中,常常需要将不同类型的数据,本文... 目录前言安装免费Java库1. 写入文本、或数值到 Excel单元格2. 写入数组到 Excel表格

redis中使用lua脚本的原理与基本使用详解

《redis中使用lua脚本的原理与基本使用详解》在Redis中使用Lua脚本可以实现原子性操作、减少网络开销以及提高执行效率,下面小编就来和大家详细介绍一下在redis中使用lua脚本的原理... 目录Redis 执行 Lua 脚本的原理基本使用方法使用EVAL命令执行 Lua 脚本使用EVALSHA命令

Java 中的 @SneakyThrows 注解使用方法(简化异常处理的利与弊)

《Java中的@SneakyThrows注解使用方法(简化异常处理的利与弊)》为了简化异常处理,Lombok提供了一个强大的注解@SneakyThrows,本文将详细介绍@SneakyThro... 目录1. @SneakyThrows 简介 1.1 什么是 Lombok?2. @SneakyThrows

使用Python和Pyecharts创建交互式地图

《使用Python和Pyecharts创建交互式地图》在数据可视化领域,创建交互式地图是一种强大的方式,可以使受众能够以引人入胜且信息丰富的方式探索地理数据,下面我们看看如何使用Python和Pyec... 目录简介Pyecharts 简介创建上海地图代码说明运行结果总结简介在数据可视化领域,创建交互式地