简体   繁体   English

如何在android上接听拨出电话并将您包括在默认应用程序列表中

[英]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). 当用户开始拨打电话时,Android建议选择可以使用哪个应用进行拨打电话(例如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 拨打电话:-Skype-电话

and there is no my app inside list. 并且列表中没有我的应用程序。

EDITED 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: onCreated中的代码:

Intent intent = getIntent();

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

gives null. 给出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. 上次从Google收到通知我,通知他们限制他们使用CALL_PRIVILEGED(因为我们不支持对他们的紧急呼叫。)如果没有CALL_PRIVILEGED,我的应用程序将不在列表中。 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. 现在,我正在与Google支持人员讨论该问题,目前我们进行了一些迭代,但均未成功。

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 : 要呼叫任何号码,请使用Intent.ACTION_DIAL作为:

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. 您需要做的是在要拨打电话的活动上设置一个Intent过滤器。 You do this inside your AndroidManifest.xml file. 您可以在AndroidManifest.xml文件中执行此操作。 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: 要回答问题的第二部分,即如何从intent对象中提取电话号码,您可以致电:

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/ 如果要将其解析为结构化对象,则可以使用Google的libphonenumber库: 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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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