android 打电话 发送短信(%d,android,roi,移动开发)

时间:2024-05-04 07:42:24 作者 : 石家庄SEO 分类 : 移动开发
  • TAG :

    android+%E6%89%93%E7%94%B5%E8%AF%9D+%E5%8F%91%E9%80%81%E7%9F%AD%E4%BF%A1

1.XML布局

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"

tools:context=".MainActivity"

android:orientation="vertical">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="号码:"

/>

android:id="@+id/phoneNumber"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

android:id="@+id/call"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="拨打电话号码"/>waihui实时点差

android:id="@+id/message"

android:layout_width="match_parent"

android:layout_height="wrap_content"

/>

android:id="@+id/send_sms"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="发送短信"/>

android:id="@+id/send_sms_noApp"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="直接发送短信"/>

2.MainActivity

package com.example.android013;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;

import android.app.PendingIntent;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.telephony.SmsManager;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

private Button call;

private Button send_sms;

private Button send_sms_noApp;

private EditText phoneNumber;

private EditText message;

private String Phone; //定义字符

private String msg;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

call=findViewById(R.id.call);

send_sms=findViewById(R.id.send_sms);

send_sms_noApp=findViewById(R.id.send_sms_noApp);

phoneNumber=findViewById(R.id.phoneNumber);

message=findViewById(R.id.message);

call.setOnClickListener(this);

send_sms.setOnClickListener(this);

send_sms_noApp.setOnClickListener(this);

}

@SuppressLint("WrongConstant")

@Override

public void onClick(View v) {

switch (v.getId()){

case R.id.call:

//意图

Intent li=new Intent();

//设置动作

li.setAction(Intent.ACTION_DIAL); //拨打

//给谁打电话

Phone=phoneNumber.getText().toString();

li.setData(Uri.parse("tel:"+Phone));

//启动意图

startActivity(li);

break;

case R.id.send_sms:

//意图

Intent li1=new Intent();

//获取电话

Phone=phoneNumber.getText().toString();

//获取短信

msg=message.getText().toString();

//设置动作

li1.setAction(Intent.ACTION_SENDTO);//发送到哪里

li1.setData(Uri.parse("smsto:"+Phone)); //发送到谁

//发送内容 键值对出现

li1.putExtra("sms_body",msg); //一条短信只能容纳140个字节70个汉字.判断长度

//启动意图

startActivity(li1);

break;

case R.id.send_sms_noApp: //自己发送,不启动系统自带的APP

//短信管理者

SmsManager manager=SmsManager.getDefault();

//意图

PendingIntent pendingIntent=PendingIntent.getBroadcast(MainActivity.this,0,new Intent(),0);

manager.sendTextMessage("12306",null,"回家正好啊",pendingIntent,null);

Toast.makeText(this,"发送成功",0).show();

break;

}

}

}

本文:android 打电话 发送短信的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:Go语言中的Iota关键字怎么使用下一篇:

14 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18