简体   繁体   中英

how to pickup outgoing call on android and include you in default application list

when user start make call, android propose to choice, which app can be using to make call (like Skype). Simple question - how my app can be in that list and how i can get number, which user was put in system dialer?

i was do a all issues, which suggest in both answers, but still, if customer press call on phone dialpad, i still seen :

make call with: - skype - phone

and there is no my app inside list.

EDITED

now problem is solved for that code, now my app in list and opened as well: (was wrong > symbol)

  <activity
        android:name=".PhonePadActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />

            <action android:name="android.intent.action.CALL" />
            <data android:scheme="tel" />
            <category android:name="android.intent.category.DEFAULT" />
            <action android:name="android.intent.action.CALL_PRIVILEGED" />
       </intent-filter>


    </activity>

Second part of problem - get phone number, which user was dial in standard dialpad, still not solved:

that code inside onCreated:

Intent intent = getIntent();

String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Toast.makeText(this, "Call was made to-->>" + number, 5000).show();

gives null.

SECOND EDITION

Last time i was received from Google notification that they are restrict CALL_PRIVILEGED (bcs we are not support emergency calls for them.) Without CALL_PRIVILEGED my app not in list again. Anybody know a fresh solution for that thing? I'm now discussed with google support regarding that issue, we got some iterations without success for now.

Declare your Activity as to add it in option list for calling application

<activity android:name="Makecall" >
        <intent-filter> 

            <action android:name="android.intent.action.CALL" />
           <data android:scheme="tel" />
           <category android:name="android.intent.category.DEFAULT" />
           <action android:name="android.intent.action.CALL_PRIVILEGED" />

        </intent-filter>
    </activity>

and for calling to any Number use Intent.ACTION_DIAL as :

Uri numberuri = Uri.parse("tel:"  + edit_text_number);
Intent intent_call = new Intent(Intent.ACTION_DIAL, numberuri);
startActivity(intent_call);

What you need to do is setup an Intent filter on the Activity you want to make the call. You do this inside your AndroidManifest.xml file. Modify your activity definition to include this intent filter:

<intent-filter>
    <action android:name="android.intent.action.CALL" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="tel" />
</intent-filter>

To get the phone number to which the call was being made, use the following method in the Broadcast receiver,

public void onReceive(Context context, Intent intent) 
    {
        String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        Toast.makeText(context, "Call was made to-->>" + number, 5000).show();

    }

To answer the second part of your question, ie how to extract the phone number from the intent object, you can just call:

String schemeSpecificPart = intent.getData().getSchemeSpecificPart();

If you want to parse this into a structured object, you can use Google's libphonenumber library: https://code.google.com/p/libphonenumber/

eg

PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
TelephonyManager manager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
Phonenumber.PhoneNumber number;
try {
     number = phoneUtil.parse(schemeSpecificPart, deviceCountry);
} catch (NumberParseException e) {
     // handle the exception
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM