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

1

1

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

Foregoing answered 15/6, 2013 at 9:22 Comment(3)
Sounds like it's not such a good idea to use a broadcastreceiver for such purposes, Android automatically kills them on low memory, so there must be always an activity. #15863151Foregoing
possible duplicate of Broadcast receiver not working in ICS if the app is not started atleast onceElectrotype
They reached to the same point as I did, But it would save a lot of my time If I has found it sooner, Thanx anywayForegoing
F
3

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.

Foregoing answered 15/7, 2013 at 12:56 Comment(2)
This is actually true. Starting from HONEYCOMB android doesn't allow any broadcast receivers to be invoked until application is explicitely launched by the user.Tertias
@VladimirIvanov I think there is another way to register our broadcast receiver before the application is being started, That's using device administrators, after you add your app to the device admin's your add get's all it's broadcast receivers even if it's not being loaded.Foregoing

© 2022 - 2024 — McMap. All rights reserved.