当前位置:操作系统 > 安卓/Android >>

Android的第一个应用(拨打电话)



AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/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="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/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);
  }
    
    }

 
}

 
作者:hyljava

 


 

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,