hyljava

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



          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>
           <!-- 開發的應用適應的版本8代表Android2.2 -->
           <uses-sdk android:minSdkVersion="8" />
           <!-- 這里指定撥打電話的權限 -->
           <uses-permission android:name="android.permission.CALL_PHONE" />
          </manifest>
          hyl.xml
          <?xml version="1.0" encoding="utf-8"?>
          <resources>
            <string name="mobellabel">請輸入手機號碼</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的第一個應用(撥打電話) 2012-09-05 11:08 anthony

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

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

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

          看來你想的很細的  回復  更多評論   

          主站蜘蛛池模板: 泾川县| 民丰县| 内江市| 北流市| 南京市| 大石桥市| 伊金霍洛旗| 韩城市| 临高县| 苏尼特左旗| 芦山县| 鸡泽县| 建阳市| 桦川县| 泸定县| 彭州市| 读书| 平罗县| 榆树市| 扬中市| 南康市| 东山县| 肥乡县| 岫岩| 亚东县| 精河县| 武陟县| 泽州县| 涿鹿县| 岗巴县| 孟津县| 秦皇岛市| 肃北| 嘉峪关市| 犍为县| 延庆县| 仙居县| 甘肃省| 松江区| 宝应县| 明溪县|