hyljava

          Android的第一個應(yīng)用(撥打電話)



          AndroidManifest.xml

          <?xml version="1.0" encoding="utf-8"?>
          <manifest xmlns:android=" package="com.hyl.phone" android:versionCode="1" android:versionName="1.0">
           <application android:icon="@drawable/maolv" 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>
           <!-- 開發(fā)的應(yīng)用適應(yīng)的版本8代表Android2.2 -->
           <uses-sdk android:minSdkVersion="8" />
           <!-- 這里指定撥打電話的權(quán)限 -->
           <uses-permission android:name="android.permission.CALL_PHONE" />
          </manifest>
          hyl.xml
          <?xml version="1.0" encoding="utf-8"?>
          <resources>
            <string name="mobellabel">請輸入手機(jī)號碼</string>
              <string name="button">撥打此號碼</string>
           
          </resources>
          main.xml

          <?xml version="1.0" encoding="utf-8"?>
          <LinearLayout xmlns: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/mobellabel"
            android:id="@+id/TextView01"
            
            />


           <EditText   android:id="@+id/EditText01"
            android:layout_width="fill_parent" android:layout_height="wrap_content" />
            
           <Button android:text="@string/button" android:id="@+id/Button01"
            android:layout_width="wrap_content" android:layout_height="wrap_content" />
          </LinearLayout>



          phoneActivity.java

          package com.hyl.phone;

          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 {
              /** Called when the activity is first created. */
            private Button button;
            private EditText editText;
           public void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.main);
                 
                   button=  (Button)this.findViewById(R.id.Button01);
                   editText=(EditText) this.findViewById(R.id.EditText01);
                 
                  button.setOnClickListener(new ButtonListener());
                 
              }
             
              private final class ButtonListener implements View.OnClickListener{

            public void onClick(View v) {
             String phonenum=editText.getText().toString();
             //android.intent.action.CALL=Intent.ACTION_CALL
             Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phonenum));
             startActivity(intent);
            }
               
              }

           
          }







          posted on 2012-08-10 20:52 何云隆 閱讀(3074) 評論(2)  編輯  收藏 所屬分類: Android

          評論

          # re: Android的第一個應(yīng)用(撥打電話) 2012-09-05 11:08 anthony

          為什么不用編輯器?這代碼排版看得人不舒服。  回復(fù)  更多評論   

          # re: Android的第一個應(yīng)用(撥打電話) 2012-09-05 11:14 何云隆

          @anthony
          我直接從我的工程中復(fù)制出來的
          之后就這樣直接粘貼上了

          看來你想的很細(xì)的  回復(fù)  更多評論   

          主站蜘蛛池模板: 增城市| 甘南县| 平利县| 喜德县| 朝阳市| 方正县| 文山县| 榆树市| 祁阳县| 凌源市| 林周县| 新宾| 开原市| 鲁山县| 新宁县| 景洪市| 稻城县| 宜君县| 贺兰县| 兰州市| 和政县| 昌都县| 昌吉市| 马尔康县| 江安县| 乐安县| 隆化县| 阿尔山市| 龙江县| 福海县| 贺兰县| 和硕县| 台江县| 稷山县| 龙山县| 简阳市| 乌兰察布市| 富源县| 庄河市| 林西县| 高淳县|