Android :: AppWidgetProvider And BroadcastReceiver
Oct 2, 2009
I have an app widget that extends an AppWidgetProvider to create an application widget.
I would like the application widget to be idle until an activity in my app runs; actually when a service in my app is started.
Once that service is started, I need to "wake up" the application widget and communicate with it (i.e. tell it things to display).
So I see that AppWidgetProvider simply extends BroadcastReceiver -- so does that mean:
1. I need to call registerReceiver in my service and tell it to filter for certain kinds of events?
2. Can I even do #1, or will an AppWidgetProvider *only* accept ACTION_APPWIDGET_* intents?
3. If #2 is correct, how can I communicate or "wake up" / trigger the application widget?
4. Can I send events to my app widget using sendBroadcast( intent )?
Then, my app widget has some buttons on it, I need to send an intent back to the application (or service). I see you can do that with PendingIntents, but if i send the different intents it to the same Activity, it seems to re-use the first created pending intent.
View 2 Replies
Apr 21, 2009
I have a general question. Is it possible to set the RemoteView of the widget to a WebView? My goal is to push real time updates to the WebView via the comet technique (HTTP long polling), similar to how Google Talk does it on the desktop browser I suppose. Do you think battery life would be significantly impacted with this approach?
View 5 Replies
View Related
Nov 8, 2010
I would like to pass a value from the AppWidgetProvider to a service. How can I do that? This value is taken from the widget configuration. If this value changes (by going to the configuration again), how do I pass it back to the service? Is there another way to do this?
View 1 Replies
View Related
Aug 2, 2010
I have a widget that shows some data fetched from the Internet. I may have multiple widgets visible on the screen, each displaying some data, partly the same as the other widgets. From time to time I re-fetch the data from the Internet and update the widget views. I've modeled this in an MVC style: I have a model which I can invoke a "re-fetch-data" on, and which the views listen on. My questions:
A) Is it wise to let my model be a singleton?
B) Can I rely on that all widgets are served by the same AppWidgetProvider? Or may some of my widgets get served by a different AppWidgetProvider instance? Or, more generally: Is there any guarantee that there will be only one instance of my AppWidgetProvider? If there is only one instance of my AppWidgetProvider, then I could use an instance variable here for the model, and pass either my AppWidgetProvider or the model around where needed. Perhaps a better option?
C) In the AppWidgetProviders onUpdate method, can I be sure that the same "context" object is passed as argument each invocation?
View 1 Replies
View Related
Jan 1, 2010
Here is my issue, I want to be able to update a specific AppWidgetProvider (home screen widget) from a custom service class. I have to build the remote view in the service because I'm also doing some networking in there, which takes some time. The problem is that I can't figure out how to update a specific widget (individual widgets can have different update intervals, using the alarm manager). If I wanted to do it from the onUpdate of the AppWidgetProvider I could just call appWidgetManager.updateAppWidget(appWidgetId, remoteView); Does anyone have any experience with this or any suggestions?
View 4 Replies
View Related
Nov 13, 2010
I am making a clock widget for the android home screen using AppWidgetProvider. I have it calling the TImerTask class that updates all my values using this code:
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds {
Timer timer = new Timer();
timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 1, 1000);
}
In the TimerTasks run() I am setting a bunch of text views to the relevant values. My problem is that this seems to work fine, but it makes my home screen unresponsive, probably due to updating it every second. How do I fix this and still have it update the display at the correct time? (I only need to see minutes not seconds, but I want the minutes to change at the correct second.)
View 2 Replies
View Related
Oct 30, 2009
It seems like the convenience functions (onUpdate, onEnabled, etc.) aren't being called in the emulator on Android 2.0. Is this a bug, or are these functions just being eliminated? It would have been nice to see this documented somewhere.
View 4 Replies
View Related
Aug 6, 2010
Anyone know if it is possible to add AlertDialog within a AppWidgetProvider class? Here is the code I am working on where I start the AlertDialog on onEnabled function call.
@Override public void onEnabled(Context context) { super.onEnabled(context); Log.v(TAG,"onEnabledWidget"); AlertDialog.Builder builder = new AlertDialog.Builder(context).setIcon( android.R.drawable.ic_dialog_info ).setTitle(R.string.app_name) .setMessage("This is testing") .setNeutralButton("Confirm", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); alertNotSmc = builder.create(); alertNotSmc.show(); //runs when all of the first instance of the widget are placed //on the home screen .........
View 5 Replies
View Related
Jul 14, 2010
I'm slighty puzzled about how android's AppWidget machinery works. I reimplemented the AppWidgetProvider's constructor like this:
public class MyProvider extends AppWidgetProvider {
public MyProvider() {
Log.d("TEST", "Creating...")
}
public void onUpdate(..., int[] appWidgetIds) {
// updating stuff here
From what I've read in the docs, I understood that AppWidgetProvider is instantiated once, when widget of that type is added for the first time. If another widget of the same type gets added, it will be managed by exactly that provider.But I just discovered that this is not the case. For each widget I add, android creates a new MyProvider (I see that from 'adb logcat' - it prints "Creating..." for each widget)!I don't understad why. Maybe I got something wrong? Or documentation isn't clear on something. What's the reason of having appWidgetIds passed to onUpdate and other methods if each provider is managing only ONE widget?
View 2 Replies
View Related
Sep 30, 2009
From a service that's running, how do I send an event or an intent to an app widget that is just sitting their idle.
View 6 Replies
View Related
Nov 23, 2009
I have built a widget that contains a button and an editable TextView (that behaves like an EditText) much like the native Google Search bar widget. How can I access the text that the user has typed into the TextView? In an Activity I would just use findViewById(), but of course I can't do that in the AppWidgetProvider. (I get the error message "The method findViewById(int) is undefined for the type Widget.") So I tried to solve it by using a million casts, like so: String str = (String) ((TextView)((Activity) context).findViewById(R.id.txt_input)).getText(); Unfortunately, with that line present my app crashes. What is the correct way to get references to those Widget elements? I've read all about RemoteViews and Widgets and looked for examples where somebody does this (which seems like it would be common, but I guess not) but I haven't turned up a solution. What am I missing?.....
View 8 Replies
View Related
Feb 2, 2010
I am attempting to signal my widget such that it receives my new Intent from my service
The code I am using to send from the service is as follows:
CODE:...........................
View 2 Replies
View Related
Aug 7, 2009
I was trying to set a progress bar to View.INVISIBLE or View.GONE, or View.VISIBLE inside an AppWidgetProvider. However, it doesn't seem to want to do it. Setting visibility works fine with TextView fields or ImageView fields or ImageButtons. However, ProgressBar doesn't seem to work. It doesn't make sense that just the progress bar type isn't supported for controlling visibility. Has anyone else seen this problem?
View 4 Replies
View Related
Jun 5, 2010
I would like to create a Home Widget containing a ListView, but I don't know if this is possible and if it is, how to do it. I was using a ListActivity and it was pretty simple, but can't figure out a way to do it using AppWidgetProvider.
View 1 Replies
View Related
Feb 14, 2010
I'm writing a widget where i first have a configure screen where the user makes a selection. Then I want to pass that data on to the actual widget. This must be really simple but I just can find out how to do it.
View 2 Replies
View Related
Dec 30, 2009
My app has a 1*4 icon size widget. When a user tries to add a widget I provide with a configuration screen. and some data is collected - it is verified by the server - it is added to the local DB with appWidgetID as the key - all is good. when user hits save, if there is not enough space, he is given a polite toast - "No more room on this home screen". Now my problem is that the application is not informed of this. Application still assumes the widget was created and sits back and wait for the broadcast to update the widget after certain amount of time.
Can anyone tell me if i can find out via a broadcast or a call back or any method possible to determine if the widget was not successfully created, so that i can mark that record in my DB as deleted. Or better if i can know the space available beforehand via some magic ninja code. my whole application design is disturbed because of this problem.
View 3 Replies
View Related
Aug 26, 2009
I know I can save information in a static attribute in a widget, however, is there a way for a widget instance to save the state information similar to the Activity onSaveInstanceState(Bundle outState) method? I don't want to write to a database for this state information.
View 2 Replies
View Related
Dec 31, 2009
Is it possible to access the content resolver methods in a class extending from AppWidgetProvider class? Have been trying to do it with no luck so far.
View 3 Replies
View Related
Apr 5, 2013
I read from my web space from a text file and paste it in TextView.Everything works.
But now I want the (AppWidgetProvider) in my widget insert. My widget has a TextView.
So how can I connect a AsyncTask with a AppWidgetProvider?Tried it. But the app crashes from then.
My MainActivityl.class with AsyncTask it reads. And my AppProviderWidget.class
View 4 Replies
View Related
Dec 3, 2011
Basically what I am trying to do is use a customer font in AppWidgetProvider to display a custom number font in my widget. The issue I am having is that getAssets is not allowed inside of AppWidgetProvider. I have read alot on google and forums about using custom fonts, it seems to be possible but not easy.
View 1 Replies
View Related
Mar 5, 2010
I am writing my own sms receiver app and i want it to catch all the sms using a broadcast receiver. This on its own, is no problem, but i want to be able to stop the message being passed to the messaging app.
View 2 Replies
View Related
Apr 7, 2009
My use case is to launch one of settings app screen when I receive a certain event in idle state. For which, I added my new intent to PhoneAppBroadcastReceiver() in PhoneApp.java (looks like this receiver handles the misc intents) But when i call startActivity(), The phone seems to go into a panic ex. startActivity(new Intent(this, NetworkSetting.class)); My questions are is this the right approach to go about ? If so 1. How can I launch the activity inside of broadcastReceiver? secondly 2. How do i verify if the activity i want to start is already started?Can the NEW_TASK_LAUNCH be used to verify this ,
View 2 Replies
View Related
Sep 21, 2010
I have written an application to read all incoming SMS and if the SMS contains certain string, I will also send a copy of the message to my another phone for backup purposes.
I used the reference from the following website:
http://www.anddev.org/novice-tutorials-f8/recognize-react-on-incoming...
It uses BroadcastReceiver to get the incoming SMS, but when I tried to send it using the following method:
CODE:.............
It always crashes. Any idea how to resolve it? Is it because of using BroadcastReceiver.
View 4 Replies
View Related
Aug 6, 2009
I want to start a project which contains a BroadcastReceiver and an Activity. The BroadcastReceiver doesn't communicate with the activity. But they share a same resource. Can i do it in only one Project (that means, i use only 1 apk to install both BroadcastReceiver and the Activity on my phone), or i have to develope them seperately in 2 projects.
View 3 Replies
View Related
Aug 28, 2009
Can I Receive a Broadcast from a Service? It seem I have to extend BroadcastReceiver to receive broadcasts but I'm already extending Service and I can't extend 2 classes. Do I set up an additional Activity to receive broadcasts and then just pass stuff to the already running Service. And if so, how to I pass additional info to an existing Service? Is there a better way?
View 4 Replies
View Related
Jun 22, 2010
How can I best implement a BroadcastReceiver that may need to "consume" the current broadcast (via abortBroadcast()), but it first needs to perform some non-trivial work to determine whether or not the broadcast should be consumed.
The problem is that if the non-trivial work takes more than 10 seconds then the receiver is considered to be blocked by the system and may be killed.
I realise that long-running operations should not be performed in the onReceive() method of receivers for that very reason, and should instead be handed-off to an appropriate service. However, if the current broadcast is to be consumed, then the abortBroadcast() method must be called within the onReceive() method before it returns. If some processing is required to determine whether the current broadcast should be consumed or not, then things can get tricky.
I'm developing an app that can consume some (but not all) inbound SMS messages. For any given SMS message it will need to perform some analysis based on the sender's phone number and the message body (including database lookups) in order to determine if the message is one that is relevant to the app or not. In the vast majority of cases this will take less than 10 seconds, but it is possible that it could take longer on rare occasions.
To get around this I'm considering the following solution.
1. On receiving a broadcast for a received SMS, my receiver starts a background thread to perform the required analysis and handle the message if appropriate. 2. The main thread (currenly executing the onReceive() method) waits until either the background thread has finished its work, or 8 seconds have elapsed, whichever occurs first. 3. If the background thread finished within the allotted time (which should happen most of the time), then the main thread calls abortBroadcast() or not, (depending on the result of the analysis) and returns normally. 4. If the background thread did NOT finish within 8 seconds, then the main thread stops the background thread and instead starts a service to perform the work. In this case it does NOT call abortBroadcast(), and the broadcast will be passed to other receivers (eg the default messaging app) regardless of whether or not the service ends up handling the message. While not an ideal outcome, it is acceptable.
View 4 Replies
View Related
Dec 29, 2009
I'd like my app to catch incoming SMS messages. There are a few examples of this around. Looks like we just need to do this:
code:..........
Is this correct? I'm sending my phone some sms messages, but the log statement never gets printed. I do have some other SMS applications installed on the phone, which display a popup when the sms is received - are they somehow blocking the intent from getting passed down to my app, they are just consuming it completely?
View 2 Replies
View Related
Jun 2, 2010
I have seen several examples on how to implement a BroadCastReceiver, but how should I implement a Service who has to react on some pending Intent (for example incoming phone call)...Actually I was wondering about the same "prbolem" but in an Activity..You obviously have a class which extends a Service 9or an Activity) so it cannot also extend BroadCastReceiver...It looks like we cannot make "platform-awar" services and/or Activties ?
View 2 Replies
View Related
Jun 22, 2010
I have a BroadcastReceiver set up in my Android application that receives SMS receive events. This works fine, but I want to be able to toggle SMS receiving on and off by toggling the BroadcastReceiver on and off. Because if I have a simple boolean inside the onReceive method, even if the SMS receiving is off, my application will start.
View 1 Replies
View Related
Aug 8, 2010
I'm trying to create an application that can use the android as a fax machine, IE Send a picture as a fax or receive a fax and save as a picture. So far I'm starting from the ground up and making sure I can intercept a call at the users discretion. I have an Receiver registered in the Manifest of my program with a filter of Phone_State which flags when the state has changed(IE incoming call).
So on my BroadcastReceiver I'm trying to have an AlertDialog popup prompting the user to either accept as fax or call but the AlertDialog seems to throw a android.view.WindowManager$BadTokenException Error when it has an incoming call. My code is just simple an onReceive(context arg0, intent arg1) and I pass the arg0 to the AlertDialog...
The full error message is below
CODE:.............
From what I have seen in the AlertDialog code, it passes the context as well as a Window and WindowManager, which I believe is why it's crashing, is there a better way or something else I should be using which might overlay the call screen?
View 2 Replies
View Related