android基础学习5————隐式意图intent开启系统照相机
来源:互联网 发布:mac版inode如何上网 编辑:程序博客网 时间:2024/06/06 02:24
显式意图开启组件时必须要指定组件的名称,一般只在本应用程序切换组件时使用。而隐式意图的功能要比显式意图更加强大,不仅可以开启本应用的组件,还可以开启其他应用的组件,例如系统自带的照相机、浏览器等。
首先,设计用户交互界面
<?xml version="1.0" encoding="utf-8"?><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" tools:context="com.example.lenovo.opencamera.MainActivity"> <Button android:id="@+id/opencamera" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="打开照相机" /></RelativeLayout>
然后在MainActivity中通过隐式意图开启系统中的照相机
package com.example.lenovo.opencamera;import android.content.Intent;import android.net.Uri;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //获取界面上的按钮 Button button=(Button)findViewById(R.id.opencamera); //给Button按钮添加点击事件 button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent=new Intent(); intent.setAction("android.media.action.IMAGE_CAPTURE"); intent.addCategory("android.intent.category.DEFAULT"); startActivity(intent); } }); }}
这里配置的action和category和系统照相机一样。
最后运行程序,点击按钮即可看见成效。
0 0
- android基础学习5————隐式意图intent开启系统照相机
- android隐式意图开启系统照相机
- Android学习记录(7)—Intent中显示意图和隐式意图的用法
- River的Android学习笔记——Intent意图
- android学习之Intent隐式意图
- Android案例学习——打开系统照相机
- Android Intent学习之 隐式意图& 显示意图& intent 跳转问题
- android——Intent意图机制详说(待续)
- 关于Android的隐式意图(调用系统图库和照相机设置图片)
- Android Intent学习之 隐式意图&IntentFilter的作用
- Android学习记录--Intent中显示意图和隐式意图的用法
- Android基础 | 意图Intent讲解
- Android显式意图、隐式意图、意图过滤器(intent-filter)、意图间传值
- Android显式意图、隐式意图、意图过滤器(intent-filter)、意图间传值
- android Intent (隐式意图和显示意图)
- android intent 隐式意图和显示意图(activity跳转)
- android intent 隐式意图和显示意图(activity跳转)
- android Intent (隐式意图和显示意图)
- git版本库 开发解答
- JavaWeb开发中的国际化问题
- UML类图
- 练习笔记——API实现QQ窗口“灵异”移动
- linux中安装Python3.6
- android基础学习5————隐式意图intent开启系统照相机
- python爬虫实战——win10 python环境配置
- Android 音频
- JAVASE
- 女生赛HDU6024
- css---border-radius--实现太极图旋转
- 嵌入式Linux系统基础知识
- 基于proteus的51单片机仿真实例四十八、C语言的指针数组演示实例
- 生产者消费者模式