Starting the application from a BroadCastReceiver (NEW_OUTGOING_CALL doesn't always work)

百般思念 提交于 2019-12-24 11:36:57

问题


Well, I've written an application that starts by dialing an specific number, I have used NEW_OUTGOING_CALL(a broad cast receiver) to catch the dial event. So far the broad cast receiver on my AndroidManifest.xml is like the following code:

<receiver android:name=".CustomBroadCastReceiver">
    <intent-filter>
         <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
    </intent-filter>
</receiver>

The problem is that when I try it on a new system, it doesn't work at first , But after a few times testing, it starts working. I have checked the android logs and think it doesn't even register as a broadcast receiver. I couldn't find a reason for this behavior in Android reference, And want to know if anybody had the same problem and found solution for it,

Please consider that this broad cast receiver is suppose to be the starting trigger of my application

I have also read something about stopped packages, And I want to know if it is related to my case, And if it is, is there a way to set flags such as FLAG_INCLUDE_STOPPED_PACKAGES on AndroidManifest.xml

======Edited======

After I call the following command for the first time on adb shell

am broadcast -n com.package.name/.StartApp

This line appears on the Emulator's log

06-15 11:17:53.216: INFO/ActivityManager(74): Start proc com.package.name for broadcast com.package.name/.StartApp: pid=2153 uid=10041 gids={3003}

And then the broad cast receiver get registered on the Emulator, Looks like my application needs to be started in order to register the broad cast receiver


回答1:


I couldn't found anything in android documentation, But after spending hours testing this case on different devices, I found out that broadcast receivers only register after the application is executed. So apparently one activity must be started after installation and then everything works perfectly.



来源:https://stackoverflow.com/questions/17122085/starting-the-application-from-a-broadcastreceiver-new-outgoing-call-doesnt-alw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!