How to make widget of running application in android? - 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.

Related

Add subview to arbitary activity android

I'm going to show notification in any view in my Android application, but I didn't find any way how to do it without getting current activity.
On iOS we can just do
Window.AddSubview(customNotification);
But is there any way to do it in Android?
When you refer to notifications in Android, it means the notifications you can see out side the app (see notifications documentation for an explanation). I assume this is not what you are referring to because you are referring to the iOS Window.
Android also has a Window class. However, an Activity is usually the right UI component you should be looking at when adding a custom View. As opposed to iOS, an Android app almost always needs to work in a certain Context to add UI components and you can't just add one to a static Window.
My suggestion is then to change the logic a bit. I assume you have a running Activity at any point (if otherwise and you are running from a Service, perhaps notifications are the right solution after all). So what you can do is to broadcast your request to show certain data and the active Activity will pick it up and add your custom view to itself in the right spot.
Another option is to start a new dialog Activity using the application context.

Place app widget on homescreen out of an activity

I know that it's not possible to place an app widget programatically on the homescreen - the user has to do it by himself. But is there a way, to let the user create an app widget without having to go to the "widgets-tab" and choosing it from the list of all available widgets?
My idea is to have a Button in my Activity, which provides some kind of shortcut to that list . This way the user still would create it by himself, but he wouldn't have to leave the app. Is there an Intent I could use in combination with startActivityForResult()?
Have a look at CommonsWare answer here:
Add widget to homescreen from Android application
You can bring the list up put you are unable to select a widget and install it for that your app must be an appWidgetHost
In Android O, its possible to pin app widget programmatically. Just watch at example here
Also check out Google official documentation

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.

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