Is it possible to refresh 3rd party widgets? - android

I'm writing an application that changes the screen brightness. I also use a 3rd party widget that both changes the screen brightness and displays the current brightness value. My program and the 3rd party widget have different functions and I want to continue to use them both. However, when my application changes the screen brightness, the 3rd party widget doesn't automatically refresh to reflect this change. So, my questions are:
Is it possible for my application to call the 3rd party widget to be refreshed?
If so, is this done by refreshing every widget on the phone, or can I target that specific widget (by package name, for example)?

Is it possible for my application to call the 3rd party widget to be refreshed?
Not readily, and quite possibly not at all.
If so, is this done by refreshing every widget on the phone
AFAIK, that is not possible.
or can I target that specific widget (by package name, for example)?
You would have no choice in the matter.
The only way that this might work is if you call sendBroadcast() with the same Intent that the system would use for updating the third-party app widget. You would need to specify the ComponentName of the other app's AppWidgetProvider. And, you have no way of knowing what the app widget IDs are for that particular Intent extra. If the third-party AppWidgetProvider is expecting something in this broadcast (e.g., app widget IDs) that you are not providing, it will likely crash. It's also possible that this broadcast is secured and cannot be sent by other apps -- I've never tried this.

Related

Create single android widget for multiple application

I have develop 3 android applications .Now i want to create a single android widget for all 3 application.I am able to do individual widget for all 3 application.But dont know how to integrate these 3 widget into single widget?
Well, you do have to choose one of your applications for the widget to belong to. A widget is simply a special type of BroadcastReceiver, and (like activities) a receiver is a component that must be declared in the manifest of one of your apps. This is how Android sees that you have a widget, and how it knows which app to notify when the widget needs to be redrawn.
You can, however, have your widget use data from all of your applications, and you can have clicks in your widget launch any of your applications. The best way to get data from other applications is to use a ContentProvider, either one backed with a database, or a simple one that returns a small amount of data when requested at a certain URI.
For clicks to launch your other apps, you simply need to define intents that launch your other apps' activities, and configure views in your widget with a PendingIntent that is built using those intents.
Does that make sense? Let me know if you need more explanation.

Enable BroadcastReceivers for plugin-style functionality

I am attempting to create a system where I have certain factory-basic functionality.
I intend 3rd party developers to be able to extend this functionality with their own code.
This is intended to work by firing off a Broadcast in certain situations where I would like a 3rd party App to receive data that it can use.
This system works, but the issue I have is that since version 3.1, the App needs to be run by a user in order to enable BroadcastReceivers. I was hoping that I could let these plugins exist without a launcher / default Activity, so that users do not need to clog their launcher with icons for plugins. Extra Activities would be defined for settings, but that would be called from my App-ecosystem.
tl;dr:
How can I enable a BroadcastReceiver in a newly installed App with as little user intervention as possible (ideally, without being located in the Launcher).
AFAIK, the Android 3.1+ limitation is for implicit Intents. Explicit Intents -- where you set the ComponentName of the receiver -- should work without issue.
So, the question now becomes: how are you really communicating with multiple plugins?
If your intention was to send a single broadcast that everyone can receive, that will trip over the Android 3.1 issue. You would need to directly invoke some component in the third-party app yourself to enable it, such as starting one of its activities from your UI via an explicit Intent, or sending a broadcast to one of its components directly via an explicit Intent.
If your intention was to send a broadcast specifically to individual plugins, then you already have some sort of way of discovering plugins (e.g., monitoring added packages and looking for a component with certain <meta-data>). In that case, you can arrange to derive the explicit Intent to use (e.g., it's the component with the <meta-data>) and should be able to broadcast to it explicitly.
If you are finding that explicit Intents do not work due to the Android 3.1 "stopped state" limitation, please let me know, as I would want to do some more investigation.
oh, I was not aware of this new security feature. What a bummer...
but now that I understood the details of the question, I'll sugest an answer, but not sure it will work, you'll have to test it for yourself.
Maybe you can on your app receive the PACKAGE_ADDED broadcast, on this Receiver, you'll query the package manager for this newly added package and check if it have an intent-filter for your broadcast, if it does, then your app should explicitly launch some component of that 3rd party app, so it can be 'initialised' by the 3.1 system restriction.
That might mean that you'll need to change the interaction with your 3rd party developers so they have a standard component your app can always fire, but it does seem like a feasible work-around.

android access widget list, coax/remind users to install widget

I would like users to install the widget component of my app. Currently my "mainactivity" simply pops up a textview saying that there is a widget and to see their widget list.
Unfortunately right now, this requires them to open the mainactivity at all. If they want to see the widget in their list of widgets.
I don't want to do anything annoying, but there does seems like there are a lot of hurdles to actually getting and using a widget right now.
Things I could do: setup an onboot service that checks to see if the widget is on the launcher screen. It could remind users once or twice (ever) via some kind of notification. The widget can turn off that service using its onUpdate method or other lifecycle commands. I personally hate erroneous notifications.
One thing I'd like to do is programmatically open up the widgets list. is that possible? any other best practices? Since we can't have widget only apps anymore, I'd still like the main component of my app to be a widget.
setup an onboot service that checks to see if the widget is on the launcher screen
That will require the user to launch your activity, anyway, on Android 3.1+. Your "onboot service" will not run before then.
One thing I'd like to do is programmatically open up the widgets list. is that possible?
No. After all, the user has to indicate where on the home screen the app widget goes first.
any other best practices?
An app that is purely an app widget, unless it is blindingly obvious that it is only an app widget, is going to have these sorts of issues. That is why many app widgets are simply one piece of a more substantial app, so that if the user elects not to use your app widget, or does not notice that it is there, it is not that big of a deal.

How to make widget of running application in android?

I want to make my running application's widget. I mean I want to access my application through widget on home screen. I want to dial a call, send sms to particular number which is stored in my application.
Is it possible in android? I am stuck on this if anyone has any type of idea then please suggest me..
Edit:-
I want to make widget like Power Control. In this we can operate all features of settings through widget. At the same ways I want to control my application through widget and for that I have to sync my application with widget or visa-versa. So I am not able to understand how can I do that.. Can anyone help me in this manner?
Thanks.
You can create broadcast receiver to consume all the broadcast events, and it doesn't matter if you fire broadcast events from your application of from your widget, they all will be handled at your broadcast listener.
There is no shortcut to convert an app to widget.
Sorry buddy.
You should do an additional component to your application. That component will be widget. In Eclipse you could add a new class to your package through the wizard and say that it will be a widget.
It should have simple layout - check elements you used in the view. only FrameLayout, LinearLayout, RelativeLayout, AnalogClock, Button, Chronometer, ImageButton, ImageView, ProgressBar, TextView, ViewFlipper are allowed. Using forbidden elements causes "Problem Loading Widget" message. Beware!
I think, you have already seen that page about how to place a widget in Manifest and how to make an appwidget-provider.
After installing on the device or emulator you whould install widget to the screen. Long touch will conduct you to the widget install wizard of the device/emulator. You will need to do it only once - at every debug launch you'll have the new version on the right place automatically.
Don't forget to renew all important views though - it will not be done automatically. (check what is not refreshing by itself and refresh them in code).
I think, you already know, how to call your launch Activity from the widget body. Only now it won't be launch activity already, but the activity to be first launched from the widget. The widget will be declared as launch in the Manifest.
System settings: just localize your settings-modifying logic in one class (like PowerControlHelper or something), figure out what parameters your methods will take and reuse it both in widget and in full-UI application. Not much difference there, you can access all the same android APIs from within widget logic as well as from activity logic.
Your application's own settings: it doesn't matter where you access your private data as long as it's the same application. See http://developer.android.com/guide/topics/data/data-storage.html#pref for more details on Shared Preferences.

Start application when Content provider is changed

I want my application to start when someone modifies a content provider. A setting to be specific. The settings framework calls "notify" when a value is set.
If my app was started I would use registerContentObserver() I guess, but is is not started.
Can define some intent-filter in my manifest that wakes up my application. A back up plan would be to have a service running all the time that has registered a listener, but that seems like a wast or resources.
Thanks, Ola
This isn't directly supported by the Android device because starting an app every time a ContentProvider's data changes is a path to really killing your battery. To do the query, you'd need to do it in a service, which as you said is understandably undesirable.
Secondly, starting an intent is a user action. Android really doesn't support allowing an application to start all on its own without user request... Doing so would be impolite! What if your user was doing something important and then your app pops up on top? Remember the user is in control, not you. Instead of starting an application, consider placing a Status Bar Notification so the user can deal with it when it's convenient for them.

Categories

Resources