[英]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.