Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make Call State in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 121
    Comment on it

    Hello friend's
    If you want to create a Call State function in Android see the below code example. Here I have used TelephonyManger method to get the information of call state And I have used PhoneStateListener. In AndroidManifest.xml I have added Phone state permission and sdk version.

    Step(1)-MainActivity-

         public class MainActivity extends Activity {
    
                @Override
                protected void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.activity_main);
    
                    TelephonyManager telephonyManager =
                            (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    
                    PhoneStateListener callStateListener = new PhoneStateListener() {
                        public void onCallStateChanged(int state, String incomingNumber)
                        {
                            if(state==TelephonyManager.CALL_STATE_RINGING){
                                Toast.makeText(getApplicationContext(), "Phone Is Riging",
                                        Toast.LENGTH_LONG).show();
                            }
                            if(state==TelephonyManager.CALL_STATE_OFFHOOK){
                                Toast.makeText(getApplicationContext(),"Phone is Currently in A call",
                                        Toast.LENGTH_LONG).show();
                            }
    
                            if(state==TelephonyManager.CALL_STATE_IDLE){
                                Toast.makeText(getApplicationContext(),"phone is neither ringing nor in a call",
                                        Toast.LENGTH_LONG).show();
                            }
                        }
                    };
                    telephonyManager.listen(callStateListener,PhoneStateListener.LISTEN_CALL_STATE);
    
                }
    
                @Override
                public boolean onCreateOptionsMenu(Menu menu) {
                    // Inflate the menu; this adds items to the action bar if it is present.
                    getMenuInflater().inflate(R.menu.menu_main, menu);
                    return true;
                }
    
            }
    

    Step(2)- Android manifest.xml-

      <?xml version="1.0" encoding="utf-8"?>
        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="com.tiwari.rajshekhar.callstate"
            android:versionCode="1"
            android:versionName="1.0">
            <uses-sdk
                android:minSdkVersion="8"
                android:targetSdkVersion="17"/>
            <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    
            <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"
                    android:label="@string/app_name"
                    android:theme="@style/AppTheme.NoActionBar">
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN" />
    
                        <category android:name="android.intent.category.LAUNCHER" />
                    </intent-filter>
                </activity>
            </application>
    
        </manifest>
    
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: