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

Hossein Shahdoost
  • 1,692
  • 18
  • 32
  • 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. http://stackoverflow.com/questions/15862651/android-kills-broadcast-receivers-on-system-low-memory – Hossein Shahdoost Jun 19 '13 at 11:48
  • 1
    possible duplicate of [Broadcast receiver not working in ICS if the app is not started atleast once](http://stackoverflow.com/questions/9952562/broadcast-receiver-not-working-in-ics-if-the-app-is-not-started-atleast-once) – Selvin Jul 16 '13 at 09:58
  • 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 anyway – Hossein Shahdoost Jul 22 '13 at 10:40

1 Answers1

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.

Hossein Shahdoost
  • 1,692
  • 18
  • 32
  • 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. – Vladimir Ivanov Apr 22 '15 at 11:18
  • @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. – Hossein Shahdoost May 01 '15 at 22:54