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

相关文章

gitlab安装及邮箱配置和常用使用方式

《gitlab安装及邮箱配置和常用使用方式》:本文主要介绍gitlab安装及邮箱配置和常用使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.安装GitLab2.配置GitLab邮件服务3.GitLab的账号注册邮箱验证及其分组4.gitlab分支和标签的

SpringBoot3应用中集成和使用Spring Retry的实践记录

《SpringBoot3应用中集成和使用SpringRetry的实践记录》SpringRetry为SpringBoot3提供重试机制,支持注解和编程式两种方式,可配置重试策略与监听器,适用于临时性故... 目录1. 简介2. 环境准备3. 使用方式3.1 注解方式 基础使用自定义重试策略失败恢复机制注意事项

nginx启动命令和默认配置文件的使用

《nginx启动命令和默认配置文件的使用》:本文主要介绍nginx启动命令和默认配置文件的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录常见命令nginx.conf配置文件location匹配规则图片服务器总结常见命令# 默认配置文件启动./nginx

在Windows上使用qemu安装ubuntu24.04服务器的详细指南

《在Windows上使用qemu安装ubuntu24.04服务器的详细指南》本文介绍了在Windows上使用QEMU安装Ubuntu24.04的全流程:安装QEMU、准备ISO镜像、创建虚拟磁盘、配置... 目录1. 安装QEMU环境2. 准备Ubuntu 24.04镜像3. 启动QEMU安装Ubuntu4

使用Python和OpenCV库实现实时颜色识别系统

《使用Python和OpenCV库实现实时颜色识别系统》:本文主要介绍使用Python和OpenCV库实现的实时颜色识别系统,这个系统能够通过摄像头捕捉视频流,并在视频中指定区域内识别主要颜色(红... 目录一、引言二、系统概述三、代码解析1. 导入库2. 颜色识别函数3. 主程序循环四、HSV色彩空间详解

Windows下C++使用SQLitede的操作过程

《Windows下C++使用SQLitede的操作过程》本文介绍了Windows下C++使用SQLite的安装配置、CppSQLite库封装优势、核心功能(如数据库连接、事务管理)、跨平台支持及性能优... 目录Windows下C++使用SQLite1、安装2、代码示例CppSQLite:C++轻松操作SQ

Python常用命令提示符使用方法详解

《Python常用命令提示符使用方法详解》在学习python的过程中,我们需要用到命令提示符(CMD)进行环境的配置,:本文主要介绍Python常用命令提示符使用方法的相关资料,文中通过代码介绍的... 目录一、python环境基础命令【Windows】1、检查Python是否安装2、 查看Python的安

Python并行处理实战之如何使用ProcessPoolExecutor加速计算

《Python并行处理实战之如何使用ProcessPoolExecutor加速计算》Python提供了多种并行处理的方式,其中concurrent.futures模块的ProcessPoolExecu... 目录简介完整代码示例代码解释1. 导入必要的模块2. 定义处理函数3. 主函数4. 生成数字列表5.

Python中help()和dir()函数的使用

《Python中help()和dir()函数的使用》我们经常需要查看某个对象(如模块、类、函数等)的属性和方法,Python提供了两个内置函数help()和dir(),它们可以帮助我们快速了解代... 目录1. 引言2. help() 函数2.1 作用2.2 使用方法2.3 示例(1) 查看内置函数的帮助(

Linux脚本(shell)的使用方式

《Linux脚本(shell)的使用方式》:本文主要介绍Linux脚本(shell)的使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录概述语法详解数学运算表达式Shell变量变量分类环境变量Shell内部变量自定义变量:定义、赋值自定义变量:引用、修改、删