Android-I/O call SMS Layout

Source: Internet
Author: User

Layout -- Layout

Linear layout is commonly used:

<? XML version = "1.0" encoding = "UTF-8"?>

<! -- This is a linear layout -->
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
<! -- This Property specifies that it is a vertical control arrangement -->
Android: Orientation = "vertical"
<! -- The layout _ attribute is added before, that is, the property relative to the parent control. Here, the parent control is filled. -->
Android: layout_width = "fill_parent"
<! -- Fill the parent control -->
Android: layout_height = "fill_parent"
<! -- The parent control is filled with the length and width, which is the top-level, so the screen is full. -->

>

<! -- I want to arrange the two controls in parallel, but the parent control is vertical, then a linear layout of Vertical arrangement is nested. -->
<Linearlayout Android: Orientation = "horizontal"
<! -- And the meaning of the parent class -->
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
>

<! -- A text box -->
<Textview

<! -- This attribute is set to the width of the content. -->
Android: layout_width = "wrap_content"

Android: layout_height = "fill_parent"

<! -- Text is obtained through resources -->
Android: text = "@ string/tvphonenum"
/>

<! -- An input box -->
<Edittext Android: Id = "@ + ID/etphonenum" <! -- Id, define it, and use this format @ + 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"
<! -- This attribute specifies that the content is directed to the right -->
Android: gravity = "right"
>
<Button
Android: Id = "@ + ID/btnhistroy"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
<! -- The proportion of the Control. When it is 1 and other controls are not set, it preferentially fills the remaining part,
When there is more than one control, according to the number of controls with this property set, and then calculate the fill ratio of each control based on the value of this property in each control
-->
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>

There are two types of attributes in the tag. One is to specify the appearance of the widget relative to its own content, and the other is relative to the appearance of the parent widget (starting with layout ), that is, the super system and sub-system of the control (the first thing I can understand is that I think of it with the help of ITIL ).

Encoding -- get the control object in Layout

The ID attribute is defined for a control in layout.

Android: Id = "@ + ID/idname"

To@ + IdStartingR. JavaThe resource file will automatically add it to the ID subclass. The framework is created when it is displayed on the screen. If you do not obtain it, where is it, an instance, obtain it in the Code as follows:

Findviewbyid (R. Id. idname)

The returned view must be converted to the expected type.

Intent carries data (CALL) to call (CALL) and text message

These operations require permissions to be modified.Androidmanifest. xmlFile

Add a tag<Application>Tag at the same level

<! -- Apply for an authorized user call -->
<Uses-Permission Android: Name = "android. Permission. call_phone"/>

<! -- Apply to authorize the user to send text messages -->
<Uses-Permission Android: Name = "android. Permission. send_sms"/>


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



// Get intent
Intent I = new intent ();

// Set the activity to be switched
I. setaction (intent. action_call );

// Set parameters
I. setdata (URI. parse ("Tel:" + num ));

// Start turning
Startactivity (I );

IntentIt can be understood as an intent, which is the link connecting each activity (view activity, activity)

Intent. action_callIs the phone view .....

Put the phone number in the past. The phone number is a URI in the format"Tel: phone number"

// SMS Manager
Smsmanager smmessage = smsmanager. getdefault ();

// Obtain the text message content from the control
String message = etmessage. gettext (). tostring ();

If (message! = NULL &&! "". Equals (Message )){

// We all know that each text message has a limit on the number of words. This method is used to automatically split the text message.
Arraylist <string> messages = smmessage. dividemessage (Message );

For (string SMS: messages ){

// Send the split text message
Smmessage. sendtextmessage (Num, null, SMS, null, null );

}

}

Sendtextmessage has many parameters.

Void Android. telephony. smsmanager. sendtextmessage (string destinationaddress, string scaddress, string text, pendingintent sentintent, pendingintent deliveryintent)

Look at the manual. The first target address and the second source address. If it is null, it indicates the number of the local machine, and the third text message content. The last two messages can be empty.

I/O operation File

Linux has high permissions. Each program has its own uid. Dalvik is a virtual machine for each program. The UID is determined based on the package name.

// Obtain the output stream of a file
Fileoutputstream FIO = openfileoutput ("myhistroy.txt", mode_append | mode_private );

// Input stream
Openfileoutput ("myhistroy.txt ");

Since each program has different uid, each program is equivalent to an independent user. They all have their own user directories and store their own data
/Data/package name

The file created by following the above method belongs to the things under this folder

/Data/package name/files/File

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.