안드로이드 전화걸기 기능 소스코드.

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>

실행 결과는 아래와 같습니다. ^^


by wisegirl 2012. 2. 9. 13:38

구글 블로그를 사용하다가, 여기가 더 좋은것 같아서 새로운 둥지를 틀어보려 해요~
저에게 초대장을 하사해 주신 철규님께 감사의 말씀을 드립니다. 호호
이젠 블로그로 어떤 글들을 어떻게 잘 꾸며볼까~ 고민좀 해봐야 겠네요~
화이팅 ^^

by wisegirl 2012. 2. 9. 13:26