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 何云隆 閱讀(3071) 評論(2)  編輯  收藏 所屬分類: Android

          評論

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

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

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

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

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

          主站蜘蛛池模板: 中超| 绥芬河市| 浙江省| 集贤县| 崇仁县| 沅江市| 凯里市| 林州市| 图们市| 星座| 邻水| 新泰市| 海淀区| 安乡县| 榆社县| 海丰县| 板桥市| 峡江县| 科技| 佳木斯市| 道孚县| 隆化县| 黄浦区| 石河子市| 龙泉市| 张家界市| 德钦县| 怀远县| 安溪县| 政和县| 社旗县| 衡南县| 株洲县| 民县| 天等县| 沂南县| 鲜城| 大方县| 巢湖市| 广西| 方城县|