Androidnbsp;Intentnbsp;用法全面总结

2024-01-12 03:32

本文主要是介绍Androidnbsp;Intentnbsp;用法全面总结,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

[代码] 调用拨号程序
    // 给移动客服10086拨打电话
      Uri uri = Uri.parse("tel:10086");
      Intent intent = new Intent(Intent.ACTION_DIAL, uri);
      startActivity(intent);
[代码] 发送短信或彩信
      // 给10086发送内容为“Hello”的短信
      Uri uri = Uri.parse("smsto:10086");
      Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
      intent.putExtra("sms_body", "Hello");
      startActivity(intent);
      // 发送彩信(相当于发送带附件的短信)
      Intent intent = new Intent(Intent.ACTION_SEND);
      intent.putExtra("sms_body", "Hello");
      Uri uri = Uri.parse("content://media/external/images/media/23");
    intent.putExtra(Intent.EXTRA_STREAM, uri);
      intent.setType("image/png");
      startActivity(intent);
[代码] 通过浏览器打开网页
      // 打开Google主页
      Uri uri = Uri.parse("http://www.google.com");
      Intent intent  = new Intent(Intent.ACTION_VIEW, uri);
      startActivity(intent);
[代码] 发送电子邮件
      // 给someone@domain.com发邮件
      Uri uri = Uri.parse("mailto:someone@domain.com");
      Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
      startActivity(intent);
      // 给someone@domain.com发邮件发送内容为“Hello”的邮件
      Intent intent = new Intent(Intent.ACTION_SEND);
      intent.putExtra(Intent.EXTRA_EMAIL, "someone@domain.com");
      intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
      intent.putExtra(Intent.EXTRA_TEXT, "Hello");
      intent.setType("text/plain");
      startActivity(intent);
      // 给多人发邮件
      Intent intent=new Intent(Intent.ACTION_SEND);
    String[] tos = {"1@abc.com", "2@abc.com"}; // 收件人
      String[] ccs = {"3@abc.com", "4@abc.com"}; // 抄送
      String[] bccs = {"5@abc.com", "6@abc.com"}; // 密送
      intent.putExtra(Intent.EXTRA_EMAIL, tos);
      intent.putExtra(Intent.EXTRA_CC, ccs);
      intent.putExtra(Intent.EXTRA_BCC, bccs);
      intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
    intent.putExtra(Intent.EXTRA_TEXT, "Hello");
      intent.setType("message/rfc822");
    startActivity(intent);
[代码] 显示地图与路径规划
    // 打开Google地图中国北京位置(北纬39.9,东经116.3)
      Uri uri = Uri.parse("geo:39.9,116.3");
      Intent intent = new Intent(Intent.ACTION_VIEW, uri);
      startActivity(intent);
      // 路径规划:从北京某地(北纬39.9,东经116.3)到上海某地(北纬31.2,东经121.4)
      Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=39.9 116.3&daddr=31.2 121.4");
      Intent intent = new Intent(Intent.ACTION_VIEW, uri);
      startActivity(intent);
[代码] 播放多媒体
      Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri uri = Uri.parse("file:///sdcard/foo.mp3");
      intent.setDataAndType(uri, "audio/mp3");
      startActivity(intent);
   
      Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
      Intent intent = new Intent(Intent.ACTION_VIEW, uri);
      startActivity(intent);
[代码] 拍照
      // 打开拍照程序
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      startActivityForResult(intent, 0);
      // 取出照片数据
      Bundle extras = intent.getExtras();
    Bitmap bitmap = (Bitmap) extras.get("data");
[代码] 获取并剪切图片
    // 获取并剪切图片
      Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
      intent.setType("image/*");
      intent.putExtra("crop", "true"); // 开启剪切
    intent.putExtra("aspectX", 1); // 剪切的宽高比为1:2
      intent.putExtra("aspectY", 2);
      intent.putExtra("outputX", 20); // 保存图片的宽和高
      intent.putExtra("outputY", 40);
    intent.putExtra("output", Uri.fromFile(new File("/mnt/sdcard/temp"))); // 保存路径
      intent.putExtra("outputFormat", "JPEG");// 返回格式
      startActivityForResult(intent, 0);
      // 剪切特定图片
      Intent intent = new Intent("com.android.camera.action.CROP");
      intent.setClassName("com.android.camera", "com.android.camera.CropImage");
      intent.setData(Uri.fromFile(new File("/mnt/sdcard/temp")));
      intent.putExtra("outputX", 1); // 剪切的宽高比为1:2
    intent.putExtra("outputY", 2);
      intent.putExtra("aspectX", 20); // 保存图片的宽和高
  intent.putExtra("aspectY", 40);
      intent.putExtra("scale", true);
      intent.putExtra("noFaceDetection", true);
    intent.putExtra("output", Uri.parse("file:///mnt/sdcard/temp"));
      startActivityForResult(intent, 0);
[代码] 打开Google Market
      // 打开Google Market直接进入该程序的详细页面
      Uri uri = Uri.parse("market://details?id=" + "com.demo.app");
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
      startActivity(intent);
[代码] 安装和卸载程序
      Uri uri = Uri.fromParts("package", "com.demo.app", null);
      Intent intent = new Intent(Intent.ACTION_DELETE, uri);
      startActivity(intent);
[代码] 进入设置界面

    // 进入无线网络设置界面(其它可以举一反三)
  Intent intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
    startActivityForResult(intent, 0);

这篇关于Androidnbsp;Intentnbsp;用法全面总结的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

Python中logging模块用法示例总结

《Python中logging模块用法示例总结》在Python中logging模块是一个强大的日志记录工具,它允许用户将程序运行期间产生的日志信息输出到控制台或者写入到文件中,:本文主要介绍Pyt... 目录前言一. 基本使用1. 五种日志等级2.  设置报告等级3. 自定义格式4. C语言风格的格式化方法

SpringBoot 获取请求参数的常用注解及用法

《SpringBoot获取请求参数的常用注解及用法》SpringBoot通过@RequestParam、@PathVariable等注解支持从HTTP请求中获取参数,涵盖查询、路径、请求体、头、C... 目录SpringBoot 提供了多种注解来方便地从 HTTP 请求中获取参数以下是主要的注解及其用法:1

Spring 依赖注入与循环依赖总结

《Spring依赖注入与循环依赖总结》这篇文章给大家介绍Spring依赖注入与循环依赖总结篇,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录1. Spring 三级缓存解决循环依赖1. 创建UserService原始对象2. 将原始对象包装成工

Java中HashMap的用法详细介绍

《Java中HashMap的用法详细介绍》JavaHashMap是一种高效的数据结构,用于存储键值对,它是基于哈希表实现的,提供快速的插入、删除和查找操作,:本文主要介绍Java中HashMap... 目录一.HashMap1.基本概念2.底层数据结构:3.HashCode和equals方法为什么重写Has

Android协程高级用法大全

《Android协程高级用法大全》这篇文章给大家介绍Android协程高级用法大全,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友跟随小编一起学习吧... 目录1️⃣ 协程作用域(CoroutineScope)与生命周期绑定Activity/Fragment 中手

Python异步编程之await与asyncio基本用法详解

《Python异步编程之await与asyncio基本用法详解》在Python中,await和asyncio是异步编程的核心工具,用于高效处理I/O密集型任务(如网络请求、文件读写、数据库操作等),接... 目录一、核心概念二、使用场景三、基本用法1. 定义协程2. 运行协程3. 并发执行多个任务四、关键

MySQL中查询和展示LONGBLOB类型数据的技巧总结

《MySQL中查询和展示LONGBLOB类型数据的技巧总结》在MySQL中LONGBLOB是一种二进制大对象(BLOB)数据类型,用于存储大量的二进制数据,:本文主要介绍MySQL中查询和展示LO... 目录前言1. 查询 LONGBLOB 数据的大小2. 查询并展示 LONGBLOB 数据2.1 转换为十

Python中yield的用法和实际应用示例

《Python中yield的用法和实际应用示例》在Python中,yield关键字主要用于生成器函数(generatorfunctions)中,其目的是使函数能够像迭代器一样工作,即可以被遍历,但不会... 目录python中yield的用法详解一、引言二、yield的基本用法1、yield与生成器2、yi

深度解析Python yfinance的核心功能和高级用法

《深度解析Pythonyfinance的核心功能和高级用法》yfinance是一个功能强大且易于使用的Python库,用于从YahooFinance获取金融数据,本教程将深入探讨yfinance的核... 目录yfinance 深度解析教程 (python)1. 简介与安装1.1 什么是 yfinance?

Python 字符串裁切与提取全面且实用的解决方案

《Python字符串裁切与提取全面且实用的解决方案》本文梳理了Python字符串处理方法,涵盖基础切片、split/partition分割、正则匹配及结构化数据解析(如BeautifulSoup、j... 目录python 字符串裁切与提取的完整指南 基础切片方法1. 使用切片操作符[start:end]2