Search code examples
androidandroid-intentbroadcastreceiversip

Show app in calling options list


I want to register my app for calling options so that it will show my app in option list whenever user call from call logs or contacts list.It is something like this enter image description here

I have searched about this and found I have to register app for new out going call intent with process outgoing call permission .Also I have to generate view to show options and on click events I have to perform action as per the item has selected.But I am not getting proper tutorial or code to which I can refer to achieve this .So please if any one knows about this help me .


Solution

  • Here is the simple code u can check this one....

    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
    <uses-permission android:name="android.permission.READ_CALL_LOG" />
    <uses-permission android:name="android.permission.WRITE_CALL_LOG" />
    
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.test.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.CALL_PRIVILEGED" />
    
                <category android:name="android.intent.category.DEFAULT" />
    
                <data android:scheme="tel" />
            </intent-filter>
        </activity>
    </application>
    

    And the java code:

    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            String tel = outgoingRecord();
            Toast.makeText(this, tel, Toast.LENGTH_LONG).show();
            TextView textView=(TextView)findViewById(R.id.tv);
            textView.setText(tel);
    
        }
    
        public String outgoingRecord() {
            Cursor c = getContentResolver().query(
                    android.provider.CallLog.Calls.CONTENT_URI, null, null, null,
                    android.provider.CallLog.Calls.DATE + " DESC");
            startManagingCursor(c);
            int numberColumn = c
                    .getColumnIndex(android.provider.CallLog.Calls.NUMBER);
            int dateColumn = c.getColumnIndex(android.provider.CallLog.Calls.DATE);
            // type can be: Incoming, Outgoing or Missed
            int typeColumn = c.getColumnIndex(android.provider.CallLog.Calls.TYPE);
            int durationColumn = c
                    .getColumnIndex(android.provider.CallLog.Calls.DURATION);
            // Will hold the calls, available to the cursor
            ArrayList<String> callList = new ArrayList<String>();
            try {
                boolean moveToFirst = c.moveToFirst();
                Log.e("MOVETOFIRST", "moveToFirst=" + moveToFirst);
            }
    
            catch (Exception e) {
                Log.e("MOVETOFIRSTERROR", "MOVETOFIRST Error=" + e.toString());
            }
    
            String callerPhoneNumber = c.getString(numberColumn);
            int callDate = c.getInt(dateColumn);
            int callType = c.getInt(typeColumn);
            int duration = c.getInt(durationColumn);
            Log.d("CALLS", "callDate=" + callDate);
            switch (callType) {
            case android.provider.CallLog.Calls.INCOMING_TYPE:
                Log.d("INCOMINGCALLLOG", "CallerPhoneNum=" + callerPhoneNumber
                        + " " + "Duration=" + duration);
                break;
            case android.provider.CallLog.Calls.MISSED_TYPE:
                break;
            case android.provider.CallLog.Calls.OUTGOING_TYPE:
                Log.d("OUTGOINGCALLLOG", "CallerPhoneNum=" + callerPhoneNumber
                        + " " + "Duration=" + duration);
                break;
            }
            return callerPhoneNumber;
        }
    }
    

    The Output is....

    ScreenShot Of Output