Android:电话拨号器
16lz
2022-03-31
PhoneActivity.java
- publicclassPhoneActivityextendsActivityimplementsOnClickListener{
- /**
- *Button呼出电话按钮
- */
- privateButtonbtn_callon;
- /**
- *EditText号码输入框
- */
- privateEditTextet_phoneNum;
- /**
- *String用户输入电话号码字符串
- */
- privateStringphoneNum;
- /**Calledwhentheactivityisfirstcreated.*/
- @Override
- publicvoidonCreate(BundlesavedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- initView();
- btn_callon.setOnClickListener(this);
- }
- /**
- *初始化界面:获取组件
- */
- publicvoidinitView(){
- btn_callon=(Button)findViewById(R.id.btn_id_phone_callon);
- et_phoneNum=(EditText)findViewById(R.id.et_id_phone_phoneNum);
- }
- publicvoidonClick(Viewv){
- phoneNum=et_phoneNum.getText().toString();
- if(phoneNum!=null&&!"".equals(phoneNum.trim())){//判断手机号是否为空
- Intentintent=newIntent(Intent.ACTION_CALL,Uri.parse("tel:"//把tel前缀传给系统之后,操作系统会自动调用拨号服务来拨打该号码
- +phoneNum));
- startActivity(intent);
- }
- }
- }
main.xml
- <?xmlversion="1.0"encoding="utf-8"?>
- <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical">
- <TextView
- style="@style/wrap_content"
- android:text="@string/tv_text_phone_phonetext"/>
- <EditText
- android:id="@+id/et_id_phone_phoneNum"
- style="@style/fill_parent"
- android:inputType="number"
- android:singleLine="true"/>
- <Button
- android:id="@+id/btn_id_phone_callon"
- style="@style/wrap_content"
- android:text="@string/btn_text_phone_callon"/>
- </LinearLayout>
strings.xml
- <?xmlversion="1.0"encoding="utf-8"?>
- <resources>
- <stringname="tv_text_phone_phonetext">请输入电话号码:</string>
- <stringname="btn_text_phone_callon">呼出电话</string>
- <stringname="app_name">Phone</string>
- </resources>
style.xml
- <?xmlversion="1.0"encoding="utf-8"?>
- <resources>
- <stylename="wrap_content">
- <itemname="android:layout_width">wrap_content</item>
- <itemname="android:layout_height">wrap_content</item>
- </style>
- <stylename="fill_parent">
- <itemname="android:layout_width">fill_parent</item>
- <itemname="android:layout_height">wrap_content</item>
- </style>
- </resources>
AndroidManifest.xml
- <?xmlversion="1.0"encoding="utf-8"?>
- <manifestxmlns:android="http://schemas.android.com/apk/res/android"
- package="com.fisnail"
- android:versionCode="1"
- android:versionName="1.0">
- <uses-sdkandroid:minSdkVersion="8"/>
- <!--拨打电话权限-->
- <uses-permissionandroid:name="android.permission.CALL_PHONE"/>
- <application
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name">
- <activity
- android:name=".PhoneActivity"
- android:label="@string/app_name">
- <intent-filter>
- <actionandroid:name="android.intent.action.MAIN"/>
- <categoryandroid:name="android.intent.category.LAUNCHER"/>
- </intent-filter>
- </activity>
- </application>
- </manifest>
更多相关文章
- Android(安卓)获取手机信息
- 短信拦截
- Android(安卓)重力感应选号码
- Android的第一个应用(拨打电话)
- Android电话系统之-rild
- Android电话系统之-rild
- Android(安卓)Contacts的使用(一)
- Android(安卓)利用广播实现黑名单【指定号码】的短信的拦截 附源
- 无废话Android之常见adb指令、电话拨号器、点击事件的4种写法、