Android笔记--发送彩信
发送彩信
界面还是那个界面,图片也实现了从相册进行选择图片,选择完成之后,就会回到界面里面的功能;
下面接着实现发送彩信的完整版;
具体实现如下:
界面代码不再展示,主要着重于后台的代码编写啦!
1、先获取到各个文本输入框以及“发送彩信”按钮的id,用来出发相应的点击事件

2、然后编写button的点击事件

其中运用到一个自定义的函数方法--setMess:

源代码在此:
package com.example.myapplication;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
public class tiaoPhoto extends AppCompatActivity implements View.OnClickListener {
private ImageView iv_photo;
private Button btn_send;
private EditText et_hao;
private EditText et_top;
private EditText et_body;
private Uri pUri;
private ActivityResultLauncher<Intent> resultLauncher;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tiao_photo);
//获取到手机号码,标题和内容
et_hao=findViewById(R.id.et_hao);
et_top=findViewById(R.id.et_top);
et_body=findViewById(R.id.et_body);
iv_photo=findViewById(R.id.iv_photo);
iv_photo.setOnClickListener(this);//设置点击事件
//获取到发送彩信的按钮点击事件
btn_send=findViewById(R.id.btn_send);
//发送彩信点击事件
btn_send.setOnClickListener(this);
//跳转到系统相册,选择图片,并返回
resultLauncher=registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if(result.getResultCode()==RESULT_OK){
Intent intent=result.getData();
//获得选中文件的路径对象
pUri=intent.getData();
if(pUri!=null){
iv_photo.setImageURI(pUri);
Log.d("ning","pUri"+pUri.toString());
}
}
}
});
}
@Override
public void onClick(View view) {
switch(view.getId()){
case R.id.iv_photo:
//跳转到系统相册,选择图片,并返回
Intent intent=new Intent(Intent.ACTION_GET_CONTENT);
//确定需要的图片类型
intent.setType("image/*");
resultLauncher.launch(intent);//返回之后,跳转到上面的那个方法里面
break;
case R.id.btn_send:
//发送带有图片的彩信
setMess(et_hao.getText().toString(),
et_top.getText().toString(),
et_body.getText().toString());
break;
}
}
//发送带有图片的彩信的函数方法
private void setMess(String hao, String top, String body) {
Intent intent=new Intent(Intent.ACTION_SEND);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//允许读取图片的uri的地址
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
//发送彩信号码
intent.putExtra("address",hao);
//发送彩信标题
intent.putExtra("subject",top);
//发送彩信内容
intent.putExtra("subject",body);
//发送图片附件
intent.putExtra(Intent.EXTRA_STREAM,pUri);
//指定类型
intent.setType("image/*");
//弹出底部弹窗
startActivity(intent);
}
}
结果展示

Android笔记--发送彩信的更多相关文章
- Android笔记---使用HttpClient发送POST和GET请求
在Android上发送 HTTP 请求的方式一般有两种, HttpURLConnection 和 HttpClient,关于HttpURLConnection的使用方法能够參考HTTP之利用HttpU ...
- Android笔记——Android中数据的存储方式(二)
我们在实际开发中,有的时候需要储存或者备份比较复杂的数据.这些数据的特点是,内容多.结构大,比如短信备份等.我们知道SharedPreferences和Files(文本文件)储存这种数据会非常的没有效 ...
- Android短信彩信收发流程(应用层)
下图为ComposeMessageActivity中confirmSendMessageIfNeeded部分的信息发送流程.主要以接收者有效性的确认为主,然后转向sendMessage方法进行发送. ...
- 深度分析:Android4.3下MMS发送到附件为音频文件(音频为系统内置音频)的彩信给自己,添加音频-发送彩信-接收彩信-下载音频附件-预览-播放(三,接收彩信<2,下载彩信>)
彩信的接收简介: 主要是由应用程序负责从彩信服务中心(MMSC Multimedia Messaging Service Center)下载彩信信息.大致的流程是Frameworks会先发出一条短信, ...
- android之发送短信程序
首先改写activity_main.xml文件 代码如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/re ...
- Android笔记:Socket客户端收发数据
client.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" and ...
- Android笔记:触摸事件的分析与总结----TouchEvent处理机制
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://glblong.blog.51cto.com/3058613/1559320 ...
- android 同时发送几条通知
android 同时发送几条通知 ======= 下面是转载的文章. 同时发送几条通知把ID添加,接收的时候找到这个id就可以出来多条了. 还是不太明白或者编码实现不了的可以加我QQ. 博客很少上 ...
- Android 笔记之 R 文件
Android笔记之R文件 h2{ color: #4abcde; } a{ color: blue; text-decoration: none; } a:hover{ color: red; te ...
- Android 笔记之 Android 系统架构
Android笔记之Android系统架构 h2{ color: #4abcde; } a{ color: blue; text-decoration: none; } a:hover{ color: ...
随机推荐
- 服务器新建分支,vscode检测不到
执行 git remote update origin 命令,刷新远程分支
- GraalVM & Spring Boot初体验
前言 这两天封在家里,一直在琢磨想去把这个博客项目改成微服务的形式.不过就目前而言我的服务器内存放好几个Java进程是吃不消的,原因在于一个独立的JVM所占用的内存资源太吃内存.不过在云原生时代,使用 ...
- Flask----常用路由系统及自定义路由系统
@app.route('/user/<username>') @app.route('/post/<int:post_id>') @app.route('/post/<f ...
- js判断变量数据类型typeof、instanceof、Object.prototype.toString.call()、 constructor
JavaScript有4种方法判断变量的类型,分别是typeof.instanceof.Object.prototype.toString.call()(对象原型链判断方法). constructor ...
- uniapp里面设置onlaunch以后在加载页面调接口
main.js 里面 Vue.prototype.$onLaunched = new Promise(resolve => { Vue.prototype.$isResolve = resolv ...
- @Conditional注解分析,SpringBoot自动化配置的关键
基于SpringBoot 2.1.5.RELEASE分析 @Conditional系列注解 @Conditional系列注解是SpringBoot自动化配置的核心要点之一,主要用于设定条件,在达到一定 ...
- Chorme 兼容
Chorme自动更新,不知道什么时候版本 就变了.之前好用的代码,突然不好用了. 启动时提示Only local connections are allowed 检查一下兼容性参照下文,下载对应的Dr ...
- java调用c++的几种方式
jni 类似c#调用c++的方式,定义java端的c++代码接口. package crayon.jni; public class JNITest { public native static vo ...
- CSS 常用样式-字体属性
字体类样式我们已经学习过字号font-size.字体font-family两个属性,接下来还有几个常用的字体属性. 粗细 font-weight: 作用:设置文字是否加粗显示. 属性名:font-we ...
- python实现录屏功能(亲测好用)
更新时间:2020年03月02日 13:59:52 作者:linnahan https://www.jb51.net/article/181757.htm import time,threading ...