短信发送器

第一个程序:酷驴拨号器

首先建一个Android工程:phone

string.xml

<? xml   version = "1.0"   encoding = "utf-8" ?>
< resources >
     < string   name = "hello" > Hello World, PhoneActivity! </ string >
     < string   name = "app_name" > 酷驴拨号器 </ string >
     < string   name = "mobile" > 请输入手机号 </ string >
     < string   name = "button" > 拨打此号码 </ string >
</ resources >

main.xml

<? xml   version = "1.0"   encoding = "utf-8" ?>
< LinearLayout   xmlns:android = "http://schemas.android.com/apk/res/android"
     android:orientation = "vertical"
     android:layout_width = "fill_parent"
     android:layout_height = "fill_parent"
     >
< TextView   
     android:layout_width = "fill_parent"  
     android:layout_height = "wrap_content"  
     android:text = "@string/mobile"
     />
< EditText   
     android:layout_width = "fill_parent"  
     android:layout_height = "wrap_content"  
     android:id = "@+id/mobile"
     />
< Button   
     android:layout_width = "wrap_content"  
     android:layout_height = "wrap_content"  
     android:text = "@string/button"
     android:id = "@+id/button"
     />
</ LinearLayout >

在drawable-hdpi中加入donkey.png,酷驴这张图片

PhoneActivity.Java

package cn.itcast.activity;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class PhoneActivity extends Activity {
private EditText mobileText;
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mobileText = (EditText)this.findViewById(R.id.mobile);
        
        Button button = (Button)this.findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String mobile = mobileText.getText().toString();
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + mobile)); //动作
PhoneActivity.this.startActivity(intent);
}
});
    }
}

AndroidManifest.xml

<? xml   version = "1.0"   encoding = "utf-8" ?>
< manifest   xmlns:android = "http://schemas.android.com/apk/res/android"
       package = "cn.itcast.activity"
       android:versionCode = "1"
       android:versionName = "1.0" >
     < application   android:icon = "@drawable/donkey"   android:label = "@string/app_name" >
         < activity   android:name = ".PhoneActivity"
                   android:label = "@string/app_name" >
             < intent-filter >
                 < action   android:name = "android.intent.action.MAIN"   />
                 < category   android:name = "android.intent.category.LAUNCHER"   />
             </ intent-filter >
         </ activity >
     </ application >
     < uses-sdk   android:minSdkVersion = "7"   />
< uses-permission   android:name = "android.permission.CALL_PHONE" />
</ manifest >  

你可能感兴趣的:(职场,短信,休闲)