Mehmet Ethem SULAN :: Android :: How to make a phone call from your application Android Sample

Android ile button tiklandiginda yazilan telefon numarasını arıyor.

tel:05357139804

tel: dan sonra telefon numaranızı yazıp test edin.

AndroidManifest.xml içinde arama izni aşağıdaki gibidir.

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>

PhoneCallActivity.java

package com.call.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.Toast;

public class PhoneCallActivity extends Activity {
    private Button button_start_call;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        button_start_call=(Button) findViewById(R.id.button1);
        
        button_start_call.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
//Button tiklandiginda bu numara araniyor.
				Intent intent_call=new Intent(Intent.ACTION_CALL, Uri.parse("tel:05348762815"));
				startActivity(intent_call);
				Toast.makeText(getApplicationContext(), "Wait for call...", Toast.LENGTH_SHORT).show();
			}
		});
    }
}

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"
    >
    <Button 
    android:id="@+id/button1" 
    android:text="Start Call" 
    android:layout_width="match_parent" 
    android:layout_height="200dip">
    </Button>
</LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.call.phone"
      android:versionCode="1"
      android:versionName="1.0">
      
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>


    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".PhoneCallActivity"
                  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>

Download source code PhoneCall.tar.gz

Comments

There is one comment for this post.

  1. cagri on Temmuz 25, 2011 8:55 am

    http://www.ethemsulan.com/2010/06/sending-email-from-your-application.html bu adres teki uygulamanın zipli halini rica edebilir miyim. mail adresinden yada bir yere upload edebilirmisiniz

Write a Comment

Let me know what you think?