intent

Android基础——Intent的Action和Data属性

喜欢而已 提交于 2020-01-27 21:57:53
布局文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="打电话" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=

Android基础——使用Bundle在Activity间传递数据

倾然丶 夕夏残阳落幕 提交于 2020-01-26 22:23:09
Bundle是个保存元组<key,value>的数据结构,两个活动传递数据时就通过Bundle进行传递 在Main中输入数据,然后将数据传递给Address 两个活动布局 Main <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <EditText android:id="@+id/name" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入姓名" /> <EditText android:id="@+id

Android调用相机,本地相册。

不羁岁月 提交于 2020-01-26 18:56:41
这两个应用操作本质上就是通过activity的action属性来调用相应的activity。 调用相机核心代码: Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //指向拍照activity的intent activity.startActivityForResult(camera, GMJValues.CAMERA); //camera为自己设置的request code 调用相册的核心代码: Intent picture = new Intent(Intent.ACTION_GET_CONTENT); picture.setType("image/*"); activity.startActivityForResult(picture, GMJValues.PICTURE); 第一句为启动指向显示文件的activity,第二句为设置显示的文件的路径。 其他类似的调用:    // 视频    Intent innerIntent = new Intent(Intent.ACTION_GET_CONTENT);    innerIntent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";    Intent

Android 广播(Android 10)

拥有回忆 提交于 2020-01-25 19:56:27
代码实现 AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapplication"> <uses-permission android:name="android.permission.BROADCAST_STICKY" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar"> <intent-filter> <action

android录音功能的实现

牧云@^-^@ 提交于 2020-01-24 15:04:07
这个录音实现是我在Bus上看到并下载的,他那个源码不完整,再次把我整理完整的代码贴出,源码地址在这:http://download.csdn.net/detail/chaozhung/5618649 Bus上的那个网址找不到了,见谅!!! 下为核心代码: 核心代码1.. package com.lv.reco; import java.io.File; public class SoundRecorder extends Activity implements Button.OnClickListener, Recorder.OnStateChangedListener { private static final String TAG = "SoundRecorder"; private static final String RECORDER_STATE_KEY = "recorder_state"; private static final String SAMPLE_INTERRUPTED_KEY = "sample_interrupted"; private static final String MAX_FILE_SIZE_KEY = "max_file_size"; private static final String AUDIO_3GPP = "audio

Android 拨打电话

青春壹個敷衍的年華 提交于 2020-01-24 13:46:59
1 从文本框中获取内容 EditText mobileText = (EditText)findViewById(R.id.mobile); String mobile = mobileText.getText().toString(); 2 打电话的权限 在功能清单中加入代码 <uses-permission Android :name="android.permission.CALL_PHONE"/> 编写代码实现Button的点击相应 Intent intent = new Intent(); intent.setAction("android.intent.action.CALL"); Intent.ACTION_CALL打电话。(当intent被触发就会拨打电话) intent.setData(Uri.parse("tel:"+ mobile)); startActivity(intent); 期中intent.setData表示获取数据 Uri.parse("tel:"+ mobile)); 这里的parse方法返回的是一个URI类型,通过这个URI可以访问一个网络上或者是本地的资源,android中指定了uri是tel:115-1345是对应的打电话的资源。 来源: https://www.cnblogs.com/qq280383983/archive/2013/03

Android Broadcast

爷,独闯天下 提交于 2020-01-24 05:22:23
广播接收者(BroadcastReceiver)用于接收广播,广播Intent的发送是通过调用Context.SendBroadcast()、Context.sendOrdredBroadcast()来实现的,通常一个广播Intent可以被订阅了此Intent的广播接收者接收,这个特性跟JMS中的Topic消息接收者类似,要实现一个广播接收者方法: 1、继承BroadcastReceiver,重写onReceive()方法; 2、订阅感兴趣的广播Intent,订阅方式有两种: >>1.代码方式注册, 在onStart()中调用registerReceiver()进行注册和在onStop中调用unregisterReceiver()释放服务 : IntentFilter filter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED"); IncomingSMSReceiver receiver = new IncomingSMSReceiver(); registerReceiver(receiver,filter); unregisterReceiver(receiver) >>2.XML方式注册,在Manifest.xml中application节点里进行订阅 <receiver android:name=

Broadcast 使用详解

吃可爱长大的小学妹 提交于 2020-01-24 05:20:05
极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以下内容: 广播的生命周期 四大组件之一,必须在Androidmainfest.xml中注册 广播的注册(静态广播、动态广播) 广播的发送(正常、有序、持续) 广播接收(系统广播、自定义广播) Broadcast 是 Android 四大组件之一,是一种广泛运用在应用程序之间异步传输信息的机制。 Broadcast 本质上是一个 Intent 对象,差别在于 Broadcast 可以被多个 BroadcastReceiver 处理。 BroadcastReceiver 是一个全局监听器,通过它的 onReceive() 可以过滤用户想要的广播,进而进行其它操作。 1. BroadcastReceiver简介 BroadcastReceiver继承关系 BroadcastReceiver 默认是在主线程中执行,如果 onReceiver() 方法处理事件超过 10s ,则应用将会发生 ANR(Application Not Responding) ,此时,如果建立工作线程并不能解决此问题,因此建议:如处理耗时操作,请用 Service 代替。 BroadcastReceiver 继承关系

Android - Android 面试题集 -- Android 部分答案

萝らか妹 提交于 2020-01-24 05:19:22
2.1 Activity 1.Activity是什么? Activity是Android的四大组件之一。是用户操作的可视化界面;它为用户提供了一个完成操作指令的窗口。 当我们创建完毕Activity之后,需要调用setContentView()方法来完成界面的显示;以此来为用户提供交互的入口。 2.典型情况下的Activity生命周期? Activity启动–>onCreate()–>onStart()–>onResume() 点击home键回到桌面–>onPause()–>onStop() 再次回到原Activity时–>onRestart()–>onStart()–>onResume() 退出当前Activity时–>onPause()–>onStop()–>onDestroy() 3.异常情况下的Activity的生命周期 & 数据如何保存和恢复? 在onStop之前调用onSaveInstanceState保存当前Activity状态,当Activity被重新创建后,系统调用 onRestoreInstanceState,并且把Activity销毁时onSaveInstanceState方法所保存的Bundle对象 作为参数传递给onRestoreInstanceState和onCreate方法 onRestoreInstanceState的调用时机发生在onStart之后

Android开发之旅:活动与任务

旧时模样 提交于 2020-01-24 05:18:20
——坚持就是胜利!关键是你能坚持吗?不能的话,你注定是个失败者。 引言 关于Android应用程序原理及术语,前面两篇: Android开发之旅:应用程序基础及组件 Android开发之旅:应用程序基础及组件(续) 介绍了Android应用程序的进程运行方式:每一个应用程序运行在它自己的Linux进程中。当应用程序中的任何代码需要执行时,Android将启动进程;当它不在需要且系统资源被其他应用程序请求时,Android将关闭进程。而且我们还知道了Android应用程序不像别的应用程序那样(有Main函数入口点),它没有单一的程序入口点,但是它必须要有四个组件中的一个或几个:活动(Activities) 、服务(Services) 、广播接收者(Broadcast receivers) 、内容提供者(Content providers)。且分别介绍它们的作用,及如何激活和关闭它们、如何在清单文件(AndroidManifest.xml)中声明它们及Intent过滤器。 在简单回顾之后,本篇还是继续介绍Android应用程序原理及术语——活动与任务(Activities and Tasks)。 1、活动与任务概述 2、亲和度和新任务(Affinities and new tasks) 3、启动模式(Launch modes) 4、清除栈(Clearing the stack) 5