글
안드로이드 전화걸기 기능 소스코드.
package call.android;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
public class TelephonyActivity extends Activity
{
PhoneStateListener Tellistener;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
makeCall();
}
public void makeCall()
{
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:01012341234"));
this.startActivity(callIntent);
TelephonyManager TelMgr = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
Tellistener = new PhoneStateListener();
TelMgr.listen(Tellistener, PhoneStateListener.LISTEN_CALL_STATE);
Log.i(ACTIVITY_SERVICE, "LOGLOGLOG");
}
}
소스코드 작성 후 Menifest.xml파일에 아래와 같이 전화기능에 대한 permission추가를 해 주어야 한다.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="call.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".TelephonyActivity"
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>
</manifest>
실행 결과는 아래와 같습니다. ^^
'개발' 카테고리의 다른 글
[안드로이드]이벤트 처리 (2013.02.27) (0) | 2013.02.27 |
---|---|
[안드로이드]Content Provider(2013.02.22) (0) | 2013.02.22 |
[안드로이드]안드로이드 서비스[Service](2013.02.21) (0) | 2013.02.19 |
[안드로이드]액티비티 수명주기와 SharedPreferences(2013.02.18) (0) | 2013.02.18 |
[안드로이드]액티비티와 인텐트 (0) | 2013.02.17 |
RECENT COMMENT