因此,在link的android开发人员页面上,有有关如何使用自己的UI实现调用应用程序的文档。
问题是,我对这些东西还很陌生,还没有在线找到任何相关信息。我的应用程序已经可以检测到有人何时拨打用户的电话,甚至弹出带有该号码的.toast,但是我没有发现任何有关如何更改有人呼叫时终止的UI的信息。
这是我的AndoidManifest的外观
<application
android:name="io.flutter.app.FlutterApplication"
android:label="seacure1"
android:icon="@mipmap/ic_launcher">
<receiver android:name=".IncomingCallReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
这就是.toasts的原因
public class IncomingCallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
ITelephony telephonyService;
try {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING)){
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Method m = tm.getClass().getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(tm);
if ((number != null)) {
assert telephonyService != null;
telephonyService.endCall();
Toast.makeText(context, "Ending call from " + number, Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(context, "Receiving call from " + number, Toast.LENGTH_SHORT).show();
}
if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_OFFHOOK)){
Toast.makeText(context, "Answered call from " + number, Toast.LENGTH_SHORT).show();
}
if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_IDLE)){
Toast.makeText(context, "Idle "+ number, Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
那么,当有人呼叫用户时,我如何实现一种更改UI的方法?我的应用程序如何拒绝/拒绝呼叫?
谢谢。