大家好,我想创建一个应用程序,其中有一个活动说我的活动。现在,如果在20秒内未得到答复,我希望通过来电启动它。请帮助我。关于广播接收器
Q
关于广播接收器
0
A
回答
1
您首先需要注册您的接收器,如..
<receiver android:name=".CustomBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
这里您注册监听手机状态改变。
接下来您需要根据您的规格扩展phonestateListener。
public class CustomPhoneStateListener extends PhoneStateListener {
private static final String TAG = "CustomPhoneStateListener";
public void onCallStateChange(int state, String incomingNumber){
//Here you recieve the phone state being changed and are able to get the number and state.
switch(state){
case TelephonyManager.CALL_STATE_RINGING:
Log.d(TAG, "RINGING");
//Here you could count with for() for 20 seconds and then create a method to do what you want.
break;
在这里,你创建广播接收器...
public class CustomBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "CustomBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.v(TAG, "inside");
TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
CustomPhoneStateListener customPhoneListener = new CustomPhoneStateListener();
telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
Bundle bundle = intent.getExtras();
String phoneNr= bundle.getString("incoming_number");
Log.v(TAG, "phoneNr: "+phoneNr);
}
编辑:
要算你可以创建一个方法,如
public void increment() {
if (count < maxCount) count++;
}
+0
感谢回复我已经完成了。如何让它等待20秒。 – Suyash
+0
你可以使用for循环来查看,而CALL_STATE_RINGER只是每次创建一个int并增加一个int。 “int i = 0;增加它i ++ –
+0
或者你可以使用一个while循环 –
相关问题
- 1. 广播接收器
- 2. 广播接收器
- 3. 关于广播接收机android
- 4. 广播接收器的的onReceive()未能接收由另一广播接收器
- 5. 广播接收器不能接收
- 6. 广播接收
- 7. GCM广播接收器
- 8. C2DM广播接收器
- 9. 广播接收器仅
- 10. 广播接收器建议
- 11. Android。广播接收器
- 12. Android MMS广播接收器
- 13. 起价广播接收器
- 14. 来电广播接收器
- 15. startActivity()从广播接收器
- 16. 与广播接收器
- 17. 注销广播接收器
- 18. Android广播接收器
- 19. android:广播接收器,用于屏幕和屏幕关闭
- 20. 广播接收器没有收到广播
- 21. 注册广播接收器对于接收到的SMS
- 22. 活动收听广播接收器
- 23. Xamarin广播接收器没有收到
- 24. 定时器广播接收器android
- 25. 广播接收器报警管理器
- 26. 广播接收器接收不到正确的操作意图广播
- 27. 问题的广播接收器(接收器未注册错误)
- 28. 广播接收器的显示Toast
- 29. ON&OFF Android的广播接收器
- 30. 是没可能从广播接收器
所以要启动广播接听电话时是否有来电?正确? –