Android looper,Android -- I/O CALL SMS Layout

 2023-09-20 阅读 27 评论 0

摘要:Layout--布局 常用的的就是线性布局: <?xml version="1.0" encoding="utf-8"?><!--这是个线性布局--><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <!--这个属性规定它是纵向方式排列控

Layout--布局

常用的的就是线性布局:

<?xml version="1.0" encoding="utf-8"?>

<!--这是个线性布局-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<!--这个属性规定它是纵向方式排列控件--
>
android:orientation="vertical"
<!--前面加了layout_的属性,就是相对于父控件的属性,这里是填充父控件-->
android:layout_width="fill_parent"
<!--填充父控件-->
android:layout_height="fill_parent"
<!--长宽都填充了父控件,它是最顶层的,于是撑满了整个屏幕-->

>

<!--我想让两个控件平行排布,但是父控件是纵向排布,那就再嵌套一个纵向排列的线性布局-->
<LinearLayout android:orientation="horizontal"
<!-- 和父类的一个意思 --
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>

<!-- 一个文本框 -->
<TextView

<!--这个属性,是宽度按照内容的宽度来定-->
android:layout_width="wrap_content"

android:layout_height="fill_parent"

<!-- 文本是通过资源获取的 -->
android:text="@string/tvPhoneNum"
/>

<!--一个输入框-->
<EditText android:id="@+id/etPhoneNum" <!-- id,定义它,就用这种格式 @+id/ -->
android:layout_width="fill_parent"
android:layout_height="wrap_content"

/>

</LinearLayout>

<TextView
android:layout_width="fill_parent"
android:layout_height
="wrap_content"
android:text
="@string/tvMessage"
/>

<EditText
android:id="@+id/etMessage"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent"
android:layout_weight
="1"
android:gravity
="top|left"


/>

<LinearLayout
android:orientation="horizontal"
android:layout_width
="fill_parent"
android:layout_height
="wrap_content"
<!-- 这个属性规定其内容靠右 --
>
android:gravity="right"
>
<Button
android:id="@+id/btnHistroy"
android:layout_width
="wrap_content"
android:layout_height
="wrap_content"
<!-- 控件的比重,当它为1,其它控件没有设置的时候,它优先填充剩余的部分,
多于一个控件时,根据设置了这个属性的控件的个数,然后与每个控件中这个属性得值运算的出每个控件的填充比例
--
>
android:layout_weight="1"
android:text="@string/btnHistroy"
/>
<Button
android:id="@+id/btnCall"
android:layout_width
="wrap_content"
android:layout_height
="wrap_content"
android:text
="@string/btnCall"
/>

<Button
android:id="@+id/btnSendMessage"
android:layout_width
="wrap_content"
android:layout_height
="wrap_content"
android:text
="@string/btnSendMessage"

/>


</LinearLayout>

</LinearLayout>

标签中的属性,也就两种,一种是规定自己相对于自身内容的外观,一种是相对于父控件的外观(以layout_开头),也就是这个控件的超系统子系统(自己是首先想到了TRIZ 才这样理解起来)。

Android looper。编码--获取layout中的控件对象

在layout中为某个控件定义了id属性

android:id="@+id/idName"

@+id 开头,那么R.java资源文件就会自动把它加入到id子类中,框架嘛,显示在屏幕上的时候就已经创建了,你获取不获取,它都在哪里,一个实例,在代码中这样获取

findViewById(R.id.idName)

他返回的是个View,需要自己强转成期望的类型。

I/O接口。

Intent携带数据(打电话)转向CALL(打电话) 以及 短信

这些操作需要权限,要更改 AndroidManifest.xml 文件

添加一下标签,与<application>标签同级别

<!-- 申请用户授权 电话拨打-->
<uses-permission android:name="android.permission.CALL_PHONE"/>

<!-- 申请用户授权 短信发送-->
<uses-permission android:name="android.permission.SEND_SMS"/>

android layout、


---------------------------------------------------------


android:layout_margin?

//获取Intent
Intent i=new Intent();

//设置要转向的Activity
i.setAction(Intent.ACTION_CALL);

//设置参数
i.setData(Uri.parse("tel:"+num));

//开始转向
startActivity(i);

Intent  可以理解为意图,它是联系每个活动(视图活动、Activity)的纽带

Intent.ACTION_CALL 就是电话那个视图。。。。。

把电话号码穿过去,电话号码是个URI,格式是 "tel:电话号码"

android:orientation="vertical"?

//短信管理器
SmsManager smMessage=SmsManager.getDefault();

//从控件获得短信内容
String message=etMessage.getText().toString();


if (message !=null && !"".equals(message)){

//都知道每条短信有字数限制,这个方法就是自动帮你拆分短信
ArrayList<String> messages=smMessage.divideMessage(message);


for(String sms:messages){

//发送拆分后的短信
smMessage.sendTextMessage(num, null, sms, null, null);


}

}

sendTextMessage有很多参数

void android.telephony.SmsManager.sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)

看看手册,第一个目标地址,第二个源地址,空的话就是本机的号,第三个短信内容,后两个都可以为空

android so。I/O操作文件

linux权限很高,每个程序都有自己的uid,dalvik又是每个程序一个虚拟机,uid根据包名来判断

//获得一个某文件的输出流
FileOutputStream fio=openFileOutput("myHistroy.txt", MODE_APPEND| MODE_PRIVATE);

//输入流
openFileOutput("myHistroy.txt");

既然每个程序的uid都不同,那么每个程序就相当于一个独立的用户了,它们都有自己的用户目录,存储自己的数据,位于
/data/data/程序包名

按着上面的方法创建的文件,属于这个文件夹下面得东西

android:windowSoftInputMode,/data/data/程序包名/files/文件

转载于:https://www.cnblogs.com/hangxin1940/archive/2011/07/13/2104831.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/80907.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息