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

相关文章

C++ Sort函数使用场景分析

《C++Sort函数使用场景分析》sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变,如果某些场景需要保持相同元素间的相对顺序,可使... 目录C++ Sort函数详解一、sort函数调用的两种方式二、sort函数使用场景三、sort函数排序

在Android平台上实现消息推送功能

《在Android平台上实现消息推送功能》随着移动互联网应用的飞速发展,消息推送已成为移动应用中不可或缺的功能,在Android平台上,实现消息推送涉及到服务端的消息发送、客户端的消息接收、通知渠道(... 目录一、项目概述二、相关知识介绍2.1 消息推送的基本原理2.2 Firebase Cloud Me

Java String字符串的常用使用方法

《JavaString字符串的常用使用方法》String是JDK提供的一个类,是引用类型,并不是基本的数据类型,String用于字符串操作,在之前学习c语言的时候,对于一些字符串,会初始化字符数组表... 目录一、什么是String二、如何定义一个String1. 用双引号定义2. 通过构造函数定义三、St

Pydantic中Optional 和Union类型的使用

《Pydantic中Optional和Union类型的使用》本文主要介绍了Pydantic中Optional和Union类型的使用,这两者在处理可选字段和多类型字段时尤为重要,文中通过示例代码介绍的... 目录简介Optional 类型Union 类型Optional 和 Union 的组合总结简介Pyd

Vue3使用router,params传参为空问题

《Vue3使用router,params传参为空问题》:本文主要介绍Vue3使用router,params传参为空问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录vue3使用China编程router,params传参为空1.使用query方式传参2.使用 Histo

使用Python自建轻量级的HTTP调试工具

《使用Python自建轻量级的HTTP调试工具》这篇文章主要为大家详细介绍了如何使用Python自建一个轻量级的HTTP调试工具,文中的示例代码讲解详细,感兴趣的小伙伴可以参考一下... 目录一、为什么需要自建工具二、核心功能设计三、技术选型四、分步实现五、进阶优化技巧六、使用示例七、性能对比八、扩展方向建

使用Python实现一键隐藏屏幕并锁定输入

《使用Python实现一键隐藏屏幕并锁定输入》本文主要介绍了使用Python编写一个一键隐藏屏幕并锁定输入的黑科技程序,能够在指定热键触发后立即遮挡屏幕,并禁止一切键盘鼠标输入,这样就再也不用担心自己... 目录1. 概述2. 功能亮点3.代码实现4.使用方法5. 展示效果6. 代码优化与拓展7. 总结1.

使用Python开发一个简单的本地图片服务器

《使用Python开发一个简单的本地图片服务器》本文介绍了如何结合wxPython构建的图形用户界面GUI和Python内建的Web服务器功能,在本地网络中搭建一个私人的,即开即用的网页相册,文中的示... 目录项目目标核心技术栈代码深度解析完整代码工作流程主要功能与优势潜在改进与思考运行结果总结你是否曾经

Linux中的计划任务(crontab)使用方式

《Linux中的计划任务(crontab)使用方式》:本文主要介绍Linux中的计划任务(crontab)使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、前言1、linux的起源与发展2、什么是计划任务(crontab)二、crontab基础1、cro

kotlin中const 和val的区别及使用场景分析

《kotlin中const和val的区别及使用场景分析》在Kotlin中,const和val都是用来声明常量的,但它们的使用场景和功能有所不同,下面给大家介绍kotlin中const和val的区别,... 目录kotlin中const 和val的区别1. val:2. const:二 代码示例1 Java