【发布时间】:2014-01-21 08:20:27
【问题描述】:
如何在来电时打开带有接听和拒绝按钮的自定义 UI,我想显示自定义 UI 而不是默认拨号器。 我正在使用以下代码,但拨号器已打开且我的活动未打开:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.callintruptdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".IncomingCall"></activity>
<receiver android:name=".CallReceiver">
<intent-filter >
<action android:name="android.intent.action.PHONE_STATE"></action>
</intent-filter>
</receiver>
</application>
我有一个广播接收器,它监听来电,接收器是:
@Override
public void onReceive(Context context, Intent intent) {
Log.d("CallReceiver","IncomingBroadcastReceiver: onReceive: ");
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
Log.d("CallReceiver","IncomingBroadcastReceiver: onReceive: " + state);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING))
{
Intent i = new Intent(context, IncomingCall.class);
i.putExtras(intent);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
IncomingCall 类的代码是:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
setContentView(R.layout.activity_main);
String number = getIntent().getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
TextView text = (TextView)findViewById(R.id.text);
text.setText("Incoming call from " + number);
}
但我的自定义 UI 没有显示。
我还想要我的 UI 上的按钮以及如何通过单击该按钮来接听来电。 提前致谢。
编辑:-- 更新我的代码后,我可以打开我的自定义 UI,现在我想通过单击其上的按钮来接听电话。如何做到这一点任何帮助..
【问题讨论】:
-
可能您的设备已选择默认拨号器以始终接听来电。进行网络搜索,了解如何为此清除默认应用。
-
我在模拟器上测试它,当我运行应用程序时,它显示拨号器,但当我调试应用程序时,它显示我的自定义 ui。所以我错过了。
-
检查此 [link][1]、[link1][2] 和 [link][3] [1]:stackoverflow.com/questions/9256218/… [2]:stackoverflow.com/questions/8699257/… [3]:@ 987654323@
标签: android telephonymanager phone-call