Android调用系统自带功能( 照相,浏览照片,打开浏览器,拨打电话)

简介: MainActivity如下:package cn.com.bravesoft.testintent;import android.net.Uri;import android.

MainActivity如下:

package cn.com.bravesoft.testintent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.app.Activity;
import android.content.Intent;
/**
 * 
 *官方资料:
 *1 权限设置
 *  http://developer.android.com/reference/android/Manifest.permission.html
 *2 系统Intent
 *  http://developer.android.com/reference/android/content/Intent.html#ACTION_CALL
 */
public class MainActivity extends Activity {
	private Button mTelephoneButton;
	private Button mPhotosButton;
	private Button mBrowserButton;
	private Button mCameraButton;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		init();
	}
    private void init(){
    	mTelephoneButton=(Button) findViewById(R.id.callTelephoneButton);
    	mTelephoneButton.setOnClickListener(new ButtonOnClickListenerImpl());
    	mPhotosButton=(Button) findViewById(R.id.browsephotosButton);
    	mPhotosButton.setOnClickListener(new ButtonOnClickListenerImpl());
    	mBrowserButton=(Button) findViewById(R.id.openBrowserButton);
    	mBrowserButton.setOnClickListener(new ButtonOnClickListenerImpl());
    	mCameraButton=(Button) findViewById(R.id.openCameraButton);
    	mCameraButton.setOnClickListener(new ButtonOnClickListenerImpl());
    }
    private class ButtonOnClickListenerImpl implements OnClickListener{
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.callTelephoneButton:
				//拨打电话
				Intent telephoneIntent=new Intent();
				telephoneIntent.setAction("android.intent.action.CALL");
				telephoneIntent.setData(Uri.parse("tel:"+"150028068"));
				startActivity(telephoneIntent);
				break;
			case R.id.browsephotosButton:
				//查看图片
                Intent galleryIntent=new Intent();
                galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
                galleryIntent.setType("image/*");
                startActivity(galleryIntent);
				break;
			case R.id.openBrowserButton:
				 //打开浏览器
				 Intent browserIntent=new Intent();
				 browserIntent.setAction(Intent.ACTION_VIEW);
				 browserIntent.setData(Uri.parse("http://www.ifeng.com"));
	             startActivity(browserIntent);
				break;
			case R.id.openCameraButton:
				//打开照相机
				Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
				startActivity(cameraIntent);
				break;

			default:
				break;
			}
		}
    	
    }
}

main.xml如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    >
   <Button
       android:id="@+id/callTelephoneButton"
       android:layout_width="150dip"
       android:layout_height="40dip"
       android:gravity="center"
       android:text="@string/callTelephone"
       android:layout_marginTop="50dip"
       android:textSize="20sp"
       />
    <Button
       android:id="@+id/browsephotosButton"
       android:layout_width="150dip"
       android:layout_height="40dip"
       android:gravity="center"
       android:text="@string/browsephotos"
       android:layout_marginTop="50dip"
       android:textSize="20sp"
       />
     <Button
       android:id="@+id/openBrowserButton"
       android:layout_width="150dip"
       android:layout_height="40dip"
       android:gravity="center"
       android:text="@string/openBrowser"
       android:layout_marginTop="50dip"
       android:textSize="20sp"
       />
      <Button
       android:id="@+id/openCameraButton"
       android:layout_width="150dip"
       android:layout_height="40dip"
       android:gravity="center"
       android:text="@string/openCamera"
       android:layout_marginTop="50dip"
       android:textSize="20sp"
       />
   
</LinearLayout>


相关文章
|
9月前
|
Linux 测试技术 语音技术
【车载Android】模拟Android系统的高负载环境
本文介绍如何将Linux压力测试工具Stress移植到Android系统,用于模拟高负载环境下的CPU、内存、IO和磁盘压力,帮助开发者优化车载Android应用在多任务并发时的性能问题,提升系统稳定性与用户体验。
715 6
|
9月前
|
Java 数据库 Android开发
基于Android的电子记账本系统
本项目研究开发一款基于Java与Android平台的开源电子记账系统,采用SQLite数据库和Gradle工具,实现高效、安全、便捷的个人财务管理,顺应数字化转型趋势。
|
安全 搜索推荐 Android开发
Android系统SELinux安全机制详解
如此看来,SELinux对于大家来说,就像那位不眠不休,严阵以待的港口管理员,守护我们安卓系统的平安,维护这片海港的和谐生态。SELinux就这样,默默无闻,却卫士如山,给予Android系统一份厚重的安全保障。
464 18
|
NoSQL 应用服务中间件 PHP
布谷一对一直播源码android版环境配置流程及功能明细
部署需基于 CentOS 7.9 系统,硬盘不低于 40G,使用宝塔面板安装环境,包括 PHP 7.3(含 Redis、Fileinfo 扩展)、Nginx、MySQL 5.6、Redis 和最新 Composer。Swoole 扩展需按步骤配置。2021.08.05 后部署需将站点目录设为 public 并用 ThinkPHP 伪静态。开发环境建议 Windows 操作系统与最新 Android Studio,基础配置涉及 APP 名称修改、接口域名更换、包名调整及第三方登录分享(如 QQ、微信)的配置,同时需完成阿里云与腾讯云相关设置。
|
监控 Java Android开发
深入探索Android系统的内存管理机制
本文旨在全面解析Android系统的内存管理机制,包括其工作原理、常见问题及其解决方案。通过对Android内存模型的深入分析,本文将帮助开发者更好地理解内存分配、回收以及优化策略,从而提高应用性能和用户体验。
1163 38
|
人工智能 API 数据库
Browser Use:开源 AI 浏览器助手,自动完成网页交互任务,支持多标签页管理、视觉识别和内容提取等功能
Browser Use 是一款专为大语言模型设计的智能浏览器工具,支持多标签页管理、视觉识别、内容提取等功能,并能记录和重复执行特定动作,适用于多种应用场景。
3874 0
Browser Use:开源 AI 浏览器助手,自动完成网页交互任务,支持多标签页管理、视觉识别和内容提取等功能
|
存储 安全 Android开发
探索Android系统的最新安全特性
在数字时代,智能手机已成为我们生活中不可或缺的一部分。随着技术的不断进步,手机操作系统的安全性也越来越受到重视。本文将深入探讨Android系统最新的安全特性,包括其设计理念、实施方式以及对用户的影响。通过分析这些安全措施如何保护用户免受恶意软件和网络攻击的威胁,我们希望为读者提供对Android安全性的全面了解。
|
安全 Android开发 iOS开发
深入探讨Android与iOS系统的差异及未来发展趋势
本文旨在深入分析Android和iOS两大移动操作系统的核心技术差异、用户体验以及各自的市场表现,进一步探讨它们在未来技术革新中可能的发展方向。通过对比两者的开放性、安全性、生态系统等方面,本文揭示了两大系统在移动设备市场中的竞争态势和潜在变革。
|
8月前
|
移动开发 前端开发 Android开发
【02】建立各项目录和页面标准化产品-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【02】建立各项目录和页面标准化产品-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
1406 12
【02】建立各项目录和页面标准化产品-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡