[英]how to pickup outgoing call on android and include you in default application list
当用户开始拨打电话时,Android建议选择可以使用哪个应用进行拨打电话(例如Skype)。 一个简单的问题-我的应用程序如何在该列表中以及如何获取号码,哪个用户被放置在系统拨号器中?
我做了所有问题,在两个答案中都提出了建议,但是,如果客户在电话拨号盘上按呼叫,我仍然会看到:
拨打电话:-Skype-电话
并且列表中没有我的应用程序。
EDITED
现在该代码的问题已解决,现在我的应用程序也在列表中并打开了:(错误>符号)
<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>
问题的第二部分-获取电话号码,该用户使用标准拨号盘拨号,但仍未解决:
onCreated中的代码:
Intent intent = getIntent();
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Toast.makeText(this, "Call was made to-->>" + number, 5000).show();
给出null。
第二版
上次从Google收到通知我,通知他们限制他们使用CALL_PRIVILEGED(因为我们不支持对他们的紧急呼叫。)如果没有CALL_PRIVILEGED,我的应用程序将不在列表中。 有人知道这件事的新解决方案吗? 现在,我正在与Google支持人员讨论该问题,目前我们进行了一些迭代,但均未成功。
声明您的活动,以将其添加到调用应用程序的选项列表中
<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>
要呼叫任何号码,请使用Intent.ACTION_DIAL
作为:
Uri numberuri = Uri.parse("tel:" + edit_text_number);
Intent intent_call = new Intent(Intent.ACTION_DIAL, numberuri);
startActivity(intent_call);
您需要做的是在要拨打电话的活动上设置一个Intent过滤器。 您可以在AndroidManifest.xml文件中执行此操作。 修改您的活动定义以包括此意图过滤器:
<intent-filter>
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
要获取拨打电话的电话号码,请在广播接收器中使用以下方法,
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();
}
要回答问题的第二部分,即如何从intent对象中提取电话号码,您可以致电:
String schemeSpecificPart = intent.getData().getSchemeSpecificPart();
如果要将其解析为结构化对象,则可以使用Google的libphonenumber库: https : //code.google.com/p/libphonenumber/
例如
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.