成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

android代碼實(shí)現(xiàn)打電話和發(fā)送短信功能-創(chuàng)新互聯(lián)

1.XML布局

創(chuàng)新互聯(lián)從2013年成立,先為城固等服務(wù)建站,城固等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為城固企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。

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="號(hào)碼:"

/>

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="撥打電話號(hào)碼"/>waihui實(shí)時(shí)點(diǎn)差

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="發(fā)送短信"/>

android:id="@+id/send_sms_noApp"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="直接發(fā)送短信"/>

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();

//設(shè)置動(dòng)作

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

//給誰(shuí)打電話

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

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

//啟動(dòng)意圖

startActivity(li);

break;

case R.id.send_sms:

//意圖

Intent li1=new Intent();

//獲取電話

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

//獲取短信

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

//設(shè)置動(dòng)作

li1.setAction(Intent.ACTION_SENDTO);//發(fā)送到哪里

li1.setData(Uri.parse("smsto:"+Phone)); //發(fā)送到誰(shuí)

//發(fā)送內(nèi)容 鍵值對(duì)出現(xiàn)

li1.putExtra("sms_body",msg); //一條短信只能容納140個(gè)字節(jié)70個(gè)漢字.判斷長(zhǎng)度

//啟動(dòng)意圖

startActivity(li1);

break;

case R.id.send_sms_noApp: //自己發(fā)送,不啟動(dòng)系統(tǒng)自帶的APP

//短信管理者

SmsManager manager=SmsManager.getDefault();

//意圖

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

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

Toast.makeText(this,"發(fā)送成功",0).show();

break;

}

}

}

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

網(wǎng)站名稱(chēng):android代碼實(shí)現(xiàn)打電話和發(fā)送短信功能-創(chuàng)新互聯(lián)
路徑分享:http://jinyejixie.com/article40/hidho.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、標(biāo)簽優(yōu)化、搜索引擎優(yōu)化定制開(kāi)發(fā)、網(wǎng)站內(nèi)鏈、營(yíng)銷(xiāo)型網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司
阳原县| 和龙市| 南充市| 西乌珠穆沁旗| 甘洛县| 玉田县| 汉阴县| 台安县| 四会市| 温州市| 文登市| 甘德县| 泗阳县| 兰坪| 阳山县| 上饶县| 乌鲁木齐县| 岳普湖县| 深水埗区| 琼海市| 博客| 定南县| 贵南县| 防城港市| 天气| 扬州市| 全南县| 浠水县| 攀枝花市| 弥渡县| 柯坪县| 疏勒县| 敦煌市| 科技| 德昌县| 普定县| 华亭县| 商南县| 奉贤区| 黑山县| 基隆市|