如何发送在Android虚拟来电广播Android

由网友(独一无二)分享简介:我试图发送一个广播,模拟来电。我加了许可AndroidManifest.xml文件,<使用-权限的Andr​​oid:名称=android.permission.READ_PHONE_STATE>< /使用-许可>当我尝试运行该程序时,手机将重新启动。(仿真器也是如此)。意向意图=新的意图()...

我试图发送一个广播,模拟来电。 我加了许可AndroidManifest.xml文件,

 <使用-权限的Andr​​oid:名称=android.permission.READ_PHONE_STATE>< /使用-许可>
 

当我尝试运行该程序时,手机将重新启动。(仿真器也是如此)。

 意向意图=新的意图();
    intent.setAction(android.intent.action.PHONE_STATE);
    intent.putExtra(TelephonyManager.EXTRA_STATE,TelephonyManager.CALL_STATE_RINGING);
    intent.putExtra(EXTRA_INCOMING_NUMBER,923982398);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    sendBroadcast(意向);
 

解决方案

我可能是错的,因为我无法找到的文档什么,但我会说这是不可能的'恶搞'的电话铃声播放。它几乎肯定保留为系统只。

想想吧 - 如果应用程序能做到这一点,它可能只是导致作怪,而不是什么恶意的,但它不是东西,我想发生在我的电话

创建自己的手机铃声行动,以用于测试目的,有你的BroadcastReceiver听吧。当你来到释放应用程序,然后只需更改的BroadcastReceiver的意图过滤器监听真钞。

I am trying to send a broadcast to simulate an incoming call. I added the permission in AndroidManifest.xml file,

<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>

When I try to run the program, the phone reboots.(Emulator too).

  Intent intent = new Intent();
    intent.setAction("android.intent.action.PHONE_STATE");
    intent.putExtra(TelephonyManager.EXTRA_STATE, TelephonyManager.CALL_STATE_RINGING);
    intent.putExtra("EXTRA_INCOMING_NUMBER", "923982398");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    sendBroadcast(intent);

解决方案

I may be wrong as I can't find anything in the docs but I'd say it's not possible to 'spoof' a call ringing broadcast. It's almost certainly reserved as 'system only'.

Think about it - if apps could do this, it may simply result in 'mischief' rather than anything malicious but it isn't something that I'd like to happen on my phone.

Create your own 'phone ringing' action to use for testing purposes and have your BroadcastReceiver listen for it. When you come to release the app then simply change the BroadcastReceiver's intent filter to listen for the real one.

阅读全文

相关推荐

最新文章