Android简易电话拨号器实例详解
程序员文章站
2022-06-29 12:00:34
安卓开发简易电话拨号器,具体内容如下
我是基于安卓4.2.2开发的,下面是我写的mainactivity.java代码:
package com.example...
安卓开发简易电话拨号器,具体内容如下
我是基于安卓4.2.2开发的,下面是我写的mainactivity.java代码:
package com.example.phone; import android.support.v7.app.actionbaractivity; import android.support.v4.app.fragment; import android.content.intent; import android.net.uri; import android.os.bundle; import android.view.layoutinflater; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.view.onclicklistener; import android.view.viewgroup; import android.widget.button; import android.widget.edittext; public class mainactivity extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); if (savedinstancestate == null) { getsupportfragmentmanager().begintransaction() .add(r.id.container, new placeholderfragment()).commit(); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate the menu; this adds items to the action bar if it is present. getmenuinflater().inflate(r.menu.main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. the action bar will // automatically handle clicks on the home/up button, so long // as you specify a parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } /** * a placeholder fragment containing a simple view. */ public static class placeholderfragment extends fragment { public placeholderfragment() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_main, container, false); final edittext numbertext=(edittext) rootview.findviewbyid(r.id.number); button button=(button)rootview.findviewbyid(r.id.button); button.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { string number=numbertext.gettext().tostring(); intent intent = new intent(intent.action_call,uri.parse("tel:"+number)); startactivity(intent); // todo auto-generated method stub } }); return rootview; } } }
布局文件我就不贴出来了,需要注意的是项目清单文件(androidmanifest.xml )中需要加入perimission: <uses-permission android:name="android.permission.call_phone"/>.我是安卓初学者,希望对和我一样的初学者有所帮助。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。