Blog purpose for android basic example for android app developer. any query please my contact

Tuesday, 19 September 2017

Android Calling

                                 

Android Calling Example



Let us start actual programming with Android Studio
Before you start writing your Calling example using Android SDK,
you have to make sure that you have set-up your Android development
environment properly as explained in Android.


Create Android Application

1. The Application First Step Create a New Project Start project



2. Rename Application Name Below Screen Ex: Calling
Click Next





3. After Spacific Minium sdk API 23 Select Lolipop 5.0
Click Next





4. Final Select Blank Activity Click Next





5. Then Select MainActivity Click Finish





6. Then Open a Android Studio



1. MainActivity.Java


package com.example.calling;

import android.content.Intent;
import android.net.Uri;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class Calling extends AppCompatActivity {
    EditText edittext1;
    Button button1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_calling);

        edittext1=(EditText)findViewById(R.id.editText);
        button1=(Button)findViewById(R.id.button1);

        //Performing action on button click
        button1.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View arg0) {
                String number=edittext1.getText().toString();
                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:"+number));
                startActivity(callIntent);
            }

        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        //    getMenuInflater().inflate(R.menu.activity_main, menu);
        // ArrayList numbersArrayList=getIntent().getExtras().getStringArrayList("phoneNumbers");
        return true;
    }



    public void rt(View view){
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
        startActivity(intent);

    }
}

2. Activity Main.xml


<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?
  RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="taskreminderapp.techsect.com.techlock.MainActivity">


      
      <ImageButton
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:id="@+id/imageButton"
        android:src="@drawable/ru"
        android:background="@drawable/roundcorner"
        android:padding="1dp"
        android:onClick="rt"
        android:layout_weight="0.21"
        android:elevation="0dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_marginRight="29dp"
        android:layout_marginEnd="29dp"
        android:layout_marginTop="23dp"/>
  
 <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="phone"
        android:ems="10"
        android:id="@+id/editText"
        android:layout_below="@+id/imageButton"
        android:layout_toLeftOf="@+id/imageButton"
        android:layout_toStartOf="@+id/imageButton"
        android:layout_marginRight="14dp"
        android:layout_marginEnd="14dp"
        android:layout_marginTop="47dp"
        android:textColorLink="?android:attr/textColorPrimaryInverse"
        android:textColor="?android:attr/navigationBarColor" />
  
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Call"
        android:layout_centerVertical="true"
        android:layout_alignLeft="@+id/editText"
        android:layout_alignStart="@+id/editText"
        android:layout_marginLeft="49dp"
        android:layout_marginStart="49dp" />
  
  
  
  
 </RelativeLayout>

3. Activity Mainifests.xml


<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.calling">

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

  <application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:supportsRtl="true"
      android:theme="@style/AppTheme">
      
      <activity android:name=".MainActivity">
         <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
      </activity>
   </application>
</manifest>
     

4. String.xml


<resources>
   <string name="app_name">Calling</string>
   <string name="hello_world">Hello world!</string>
   <string name="menu_settings">Settings</string>
   <string name="title_activity_main">MainActivity</string>
</resources>

5. Output







                                   <<  PREVIEW >>

                                  <<   NEXT       >>

No comments:

Post a Comment