A have a little confuse the difference between Widget Context and Application Context: Regarding problem relate with unable to register new BroadcastReceiver via implement source code of Android Widget (Ref.1)
For readability reason, i copy my answer as below: ★Problem by Henry (Ref.1):
I am making a widget that needs a broadcast receiver, like the one in com.example.android.apis.appwidget.ExampleBroadcastReceiver. However, the example defines Intent.ACTION_TIMEZONE_CHANGED in the manifest, but there are some that do not allow this
For example, Intent.ACTION_TIME_TICK says "You can not receive this through components declared in manifests, only by exlicitly registering for it with Context.registerReceiver(). "
So I removed the manifest declarations and tried replacing the AppWidgetProvider.onEnabled function that was in the example with a call like the following: context.registerReceiver(myReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));
(where "myReceiver" is an instance of the receiver I want.) However, when I try to run the code, I get the following error:
Unable to start receiver...android.content.ReceiverCallNotAllowedException: IntentReceiver components are not allowed to register to receive intents
★Our analysis this issue and solution for this problem (Ref.1)
This is result after investigate this problem, i was handler successful this issue. So i collect as report to share with android developer. Hope it help
Here is result:
❶ISSUE:* Regarding limited from Widget, when try to register BroadcastReceiver via explicit source code: (No effect when register BroadcastReceiver via Manifest.xml)
❷EXAMPLE: * BroadcastReceiver: ACTION_TIME_TICK message is one example: As docs from Android had point out: "You can not receive this through components declared in manifests, only by exlicitly registering for it with Context.registerReceiver()." (Ref.1)
❸PREVIOUS SOLUTION:* Code Snippet: context.registerReceiver(this, intentName); (1)
❹ERROR when used 3★ solution* When implement follow (1), it though exception: android.content.ReceiverCallNotAllowedException: IntentReceiver components are not allowed to register to receive intents
★Good news for anyone who need to register BroadcastReceiver in Widget :) we CAN register successful BroadcastReceiver
❺OUR SOLUTION:* But, We can fixed this by used application context instead of Widget context(*) Code Snippet: context.getApplicationContext.registerReceiver(this, intentName);
❻REFERENCE:* http://developer.android.com/reference/android/content/Intent.html#AC... Regarding
❼TARGET ENVIRONEMNT:* SDK 2.3, both on Emulator and NexusOne 2.3, If anyone success with this solution please update our report
❽NOTES* May be difference between Context object of widget and application, but i still don't known exactly cause of this problem.
Please let me known if your have better solution or explain more clearly
Also i had solver this problem, but i still don't known exactly cause of this problem.
Please let me known if your have better solution or explain more clearly
★CONCLUTION:
● NG: When use Widget context to register BroadcastReceiver
context.registerReceiver(this, intentName);
-> it thought exception:
Unable to start receiver...android.content.ReceiverCallNotAllowedException: IntentReceiver components are not allowed to register to receive intents
● OK: When use Application context everything working fine:
ontext.getApplicationContext.registerReceiver(this, intentName);
★QUESTION: Also our solution can solver problem: "unable to register new broadcast message via implement source code of Android widget".
But i still concern two Qestion:
Question❶: The difference between Widget Context and Application Context and other Context object (Activity Context)'
Question❷: Because context object was use usually so when to use Application context and when to use other Context.
For ❷ i had found explain relate with memory leak (Ref. 2), but i think it may not enough (Ref.2)
So if your have answer please let me known, any answer appreciated.
Thanks
★Referecens:
(2) http://developer.android.com/resources/articles/avoiding-memory-leaks.html