Create single android widget for multiple application - android

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.

Related

how can i get the control from the ui elements from another app?

Somebody knows how can i get the control from the ui elements from another app?.
For example, in whatsapp how could I write in the EditText to send a message using speech to text?
Thanks in advance!!
Greetings.
You interact with other apps stored on the device using the Intent framework. What you are asking is literally impossible, unless you're talking about hacking the device.
In Android all apps are separated from each other. If your app wants to access data from another app to show it in your custom ui, the vendor of the application must provide a ContentProvider.
If the publisher of the target app has declared some activities with intent-filters, the ui components can be opened by wrapping your data inside of an Intent.
In such cases the availability of at least one matching intent filter should be checked, before sending the Intent.

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.

Is it possible to refresh 3rd party widgets?

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.

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.

Accessing AppWidgetHost to launch the 'Add Widget' activity from within my program's activity

I would like to add the ability for a user to launch the Add Widget activity to choose my application's widget to add to their phone's homescreen from within my application.
I was following this example: Android:NPE while trying to activityForResult with ACTION_APPWIDGET_PICK intent, but realized that I didn't have the homescreens AppWidgetHost.
I know I need to use the AppWidgetManager.ACTION_APPWIDGET_PICK, but Android Developer says that I need to launch this from within my AppWidgetHost. If I am trying to get the appwidget onto the homescreen, this implies that I need to gain access to that instance of the AppWidgetHost. How would I get access to that or get that instance? Is it even possible to do anything with the homescreen's AppWidgetHost?
How would I get access to that or get that instance?
You can't. That's not in your process.
Is it even possible to do anything with the homescreen's AppWidgetHost?
Only if you are the home screen in question.
I would like to add the ability for a user to launch the Add Widget activity to choose my application's widget to add to their phone's homescreen from within my application.
AFAIK, this is not supported.

Categories

Resources