[Update: Gone from the beta too] Twitter removes its homescreen widget support from the latest alpha

Twitter is struggling to figure out what it wants to be when it grows up. Life can be tough when you’re a social network that almost everyone has heard about but no one knows how to use when they’re just joining for the first time.

But despite these tumultuous times at Twitter’s headquarters, the Android app has seen some of its best days in the past few months: an overhauled Material Design inspired interface, a test for a night mode, Android N Direct Reply, and more. But instead of giving something new, the latest Twitter alpha 6.9.0 takes away a feature: the homescreen widget.

If you have the widget added to your homescreen, you will see the above message instead when you’re on the latest alpha. The widget is clearly no longer functional. Whether this change will carry through to the beta and stable versions remains to be seen, but it’s clear that Twitter’s Android developers are at least considering the possibility of removing the widget support altogether. Maybe they found out it wasn’t used all that much and the people who had added it were so few that it didn’t warrant keeping it alive and supported. I guess we’ll have to wait and see. In the meantime, feel free to cry foul in the comments below.

[Source:-Android Central]

Create A Scrollable Widget Full Of App Icons Using ‘Foldery’

There are a ton of apps for Android that allow you to improve your productivity. As this is Android we’re talking about, you have far more freedom than you’d have on iOS, for example. There are apps that can boost your messaging experience, multitasking, and even change the look and feel of your entire home screen while adding some extra features into the mix. Well, we’re here to talk about an app called Foldery Multicon Folder Widget’ or ‘Foldery’ in short, which is basically a widget that will help you organize your home screen in a unique way, read on.

Many of you probably have quite a few icons on your home screen, and some of you are probably reluctant to use too many home screen pages. Well, with Foldery, you can create scrollable widgets and place app icons inside of them. You can essentially create a 1-by-1 widget on your home screen and place a number of icons inside of it. You can go through them by swiping either vertically or horizontally, that’s totally up to you. If your launcher allows you to, you can resize this widget and truly take control of what will it look like. The app also allows you to manipulate the size of the icons you include, you can make them huge, or simply use the standard size, it’s totally up to you. You can also increase the number of columns you’d like to use in a widget, change the background of the widget, and Foldery also supports icon packs, which means you can use whichever icon pack you want, as long as it is installed on your smartphone.Foldery worked great during our testing, and the app is very well designed, it’s not exactly in line with the latest Material Design guidelines, but it looks nice and it’s fairly easy to navigate. One thing to keep in mind, however, is that you can create only 1 Foldery widget in the free version of this application, if you’d like to add more of them, you’ll need to make an in-app purchase. Interesting enough, you have 5 levels of contributions to choose from, ranging from ‘Patronage’ to ‘Coconut Cocktail’, which essentially means you can choose how much you’d like to pay for the app, though do keep in mind that you won’t be able to pay less than $1. All of these aforementioned options will give you access to ‘Foldery Premium’, and this is a one-time payment.

[Source:-AH]

 

bunq heeft handige widget met saldo van al je rekeningen

bunq-app met rekeningoverzicht.

Het is nu een stuk eenvoudiger om snel het saldo van al je bunq-rekeningen te bekijken. De app heeft met ingang van de nieuwste versie namelijk een widget, waarin je het saldo van al je rekeningen snel kunt bekijken in het widget-overzicht op je iPhone.

Saldowidget van bunq

De widgets in iOS zijn handige kleine toepassingen, waardoor je allerlei informatie van een app kunt ophalen zonder dat je de desbetreffende app hoeft te openen. Er zijn allerlei apps die gebruikmaken van zo’n widget en met de update van vandaag heeft ook bunq deze toegevoegd aan haar eigen app. Met de widget van bunq kun je zo snel het saldo van al je bunq-rekeningen bekijken, zonder dat je daarvoor de app hoeft te openen. Dit is vergelijkbaar met de saldowidget van ING Bankieren die een jaar geleden toegevoegd werd. Toch zijn er wel een paar verschillen in de saldowidget van ING en bunq.

bunq-widget met saldo.De saldowidget van ING toont behalve het saldo ook het IBAN-nummer van de rekening en de datum waarop het saldo voor het laatst is bijgewerkt. De widget van bunq laat alleen zien wat het saldo is, samen met de eigen gekozen naam van de bijbehorende rekening. Bovendien werkt de widget van bunq alleen als je ingelogd bent. De bunq-app logt na een bepaalde tijd automatisch uit. Hierdoor krijg je in de widget de melding te zien dat je in moet loggen voordat je het saldo kunt bekijken. Dit maakt de widget wat minder bruikbaar dan die van de ING, omdat je daar altijd het saldo kunt bekijken, ongeacht of je ingelogd bent of niet.

Ben je desondanks bang dat iemand anders jouw saldo kan zien vanaf een vergrendelde iPhone, dan kun je dit eenvoudig uitschakelen. Door het Vandaag-scherm met alle widgets uit te schakelen vanaf een vergrendelde iPhone, moet je het toestel eerst ontgrendelen voordat de widgets zichtbaar zijn. In onderstaande tip lees je hoe je dit instelt.

[Source:-iculture]

Wi-Fi Widget for iPhone Gives You Quick Access to Wi-Fi Router Info and Passwords

iPhone: If you want to get any information about the Wi-Fi network you’re connected to on your iPhone, you’d usually have to jump into the Settings. Wi-Fi Widget puts that info on the widgets screen.

With Wi-Fi Widget, you can easily see what network you’re connected to and what the latency is. This is nice if you tend to bounce between a lot of different networks throughout the day. You can also optionally enter Wi-Fi passwords into the app, and get a share menu to quickly send a password to a friend. Wi-Fi Widget is a simple little app, but it does what it’s supposed to do well, and it’s pretty handy for anyone who moves between routers a lot.

[Source:-Lifehacker]

APP of the day |Energy Bar – Foldery Multicon Folder Widget| 3rd Jan, 2017

APP of the day |Energy Bar- Foldery Multicon Folder Widget

This program is based on smartphone app review, where we’ll discuss apps and their amazing features.

Today we are going to review – Energy Bar

Google Maps On iOS To Have ‘Nearby Traffic Widget’

Google’s endless quest to create the perfect Maps app continues unabated with the release of another update pushed out to its legions of devoted iPhone users on Thursday. It was announced the new “Nearby Traffic” widget that pretty much does what it says on the tin, indicating traffic conditions along your route.

If you are that kind of person who wants to plan ahead and prepare various contingencies for traffic and whatnot, the latest update to Google Maps on iOS might something you might like. Google is now introducing a new widget in the form of “Nearby Traffic” which shows the current traffic around your location. This may help you detect what are the areas you can avoid for you to have a smooth drive.

Google Maps On iOS To Have ‘Nearby Traffic Widget’

According to 9to5 Mac, the latest update to Google Maps brings a new widget the displays traffic time for your location. The widget, seen below, displays a small map showing traffic congestion, with red depicting slow movement and green representing smooth sailing. Additionally, the widget offers up a description. Depending on conditions, the widget will read something along the lines of, “Light traffic in your area. Faster than usual.”

img_0609

In addition, the announced update today seems to remove the Travel Times and Transit widgets that were brought to Google Maps just last month. It’s unclear why Google removed them and if they’re coming back, but for now, Nearby Traffic is the only widget available.

Ubergizmo reported that the new widget will also give a very brief description about the traffic, like “Light traffic in your area” and “Faster than usual”. It has also the ability to search for places along a route while you’re using the app’s turn-by-turn navigation feature. From the navigation display, you can tap the “Search” icon and choose from “Gas Stations” and “Restaurants” criteria or search for a specific place.

How To Update Your iOS Smartphone’s Google Maps

In any case, if you have yet to update your app or download Google Maps for iOS, then head on over to the iTunes App Store for the latest update.

[Source:-iT]

Google Maps iOS update brings ‘Nearby Traffic’ widget, pit stop function

Google Maps, Google maps ios update, Google maps v4.25.0, Goole maps ios widgets, nearby traffic ios widget, add stop on google maps, new google maps ios features, navigation, technology, technology newsGoogle’s latest update to the Google Maps app (v 4.25.0) on iOS brings forth a new feature: “Nearby Traffic” widget. The update brings optimisation for the iOS 10 widgets functionality, and also adds a new feature that will make it easier to find a place to stop during a ride.

The ‘Nearby Traffic’ widget does exactly what it says on the update, and gives users information of traffic conditions near their location in real-time without having to open the Google Maps app. It will be able tell you if there is light or heavy traffic in your area, and also display any delays you can expect.

This functionality is already available for Android users, and appears in the notifications area whenever Google Maps assesses moderate to heavy traffic. In case the traffic is light, the information that will be shown would be ‘light traffic in your area’ or ‘faster than usual’.

To add the ‘Nearby Traffic’ widget to your iOS device, simply swipe right on your home screen and access the widget. Then, scroll down to the bottom and select edit. Then you can add the Google Maps widget to your existing ones, and move it around for optimum placement. iOS already has two other widgets that allow you to find ‘Travel Times’ to home/work and a ‘Public Transport Nearby’ widget.

Read: OnePlus 3T launched in India: Sale date, price, specifications and features

The new update also brings the ability for users to search for nearby places (like restaurants, coffee shops, grocery stores and petrol pumps) while they are using the turn-by-turn feature navigation in the Google Maps app. Once you have started your journey, you can simply tap on the search icon on the top right and select any of the options to ‘Add Stop’. This eliminates the need to turn off navigation just to look for pit stops along the way.

Google has been hosting an aggressive advertising and marketing campaign in India. Billboards with Google Maps adds, especially on how to use the service in Hindi are all over Delhi, and the product has emerged as very useful one in India. The offline maps feature has also proved to be an important one.

In the capital, Google Maps is probably the best way to gauge traffic conditions, given the kind of traffic jams that take place on a daily basis. Now the new widget in iOS should make it more convenient for users who are relying on Google Maps for their daily navigation.

[Source:-Tech i.e]

TradingView adds new embeddable fundamental data widget

tradingview

TradingView, the online charting tools developer and social trading platform, announced it is adding a new fundamental data widget that can be added to any site. It can show any fundamental data indicator, such as dividends or earnings and is free to use.

The widget allows users to configure parameters and change the look and then to copy and paste the embed code into their site.

TradingView’s chart widgets provide free real-time forex and bitcoin data (as well as most other coverage for futures and indexes). Stock delayed data is also available for free. They can be added to websites, blogs and forums by simply pasting the pre-made iframe code.

e5f2180df6

Besides the fundamental data indicator, TradingView offers widgets for advanced real time charts, Market Overview / Quote Board Widget, Hotlists Widget and a Symbol Overview Widget.

It also provides other tools for financial sites, such as standalone charting library with open API, a standalone front-end trading terminal and various publishing and social tools.

TradingView is one of the major providers of forex charting tools and real-time market data. It offers a wide array of features, drawing tools, technical indicators, technical analysis tools, etc. It also provides a trading platform, used by more than 1 million active traders who use the social trading tools to share and discuss ideas and strategies. TradingView offers charting widgets for embedding free real-time quoting and charts, free charting library, front-end trading terminal and publishing and social tools.

[Source:-Smw Weekly]

How to create a widget for your Android app

create-an-android-app-widget-feature-image

Android app widgets may look pretty simple – essentially, they’re just small windows that users embed in an App Widget Host, typically their device’s homescreen – but your average application widget has a lot to offer.

For users, widgets help them make the most of all that homescreen real estate that would otherwise go to waste. And for developers, creating a widget to accompany your latest Android app is a way of delivering a better user experience (and if you want those 5 star reviews then you should seize anyopportunity to deliver a better user experience) plus a well-designed app widget is a useful tool for keeping your app at the forefront of the user’s mind.

Every time the user passes through their homescreen, your widget has an opportunity to catch their interest by presenting them with a snippet of your app’s most important content – ideally tempting them into launching your app.
In this article, I’m going to show you how to create an effective app widget for your latest Android project. I’ll be covering all the essentials of creating a basic widget, before sharing some best practices that can help ensure your widget will have no problem securing itself a permanent spot on the user’s homescreen.

Planning your widget

So, you’re sold on the idea of creating an Android app widget, but the first step is deciding what kind of widget you’re going to build.

If you’re struggling for inspiration, then it can help to look at what other Android developers are doing. When you look at all the Android widgets that are currently out there, they can generally be divided into the following categories:

  • Information widgets. Display important information related to your app. Some examples include clock and weather widgets, and widgets that notify the user about new emails or SMS messages.
  • Collection widgets. These vertically-scrolling widgets display multiple elements from the same group, such as a collection of headlines from a news app, or a series of photos from a gallery app.
  • Control widgets. These widgets give users the ability to trigger an app’s most important features from the comfort of their homescreen – kind of like a remote control. A control widget can help your app feel more like an integral part of the user’s device, rather than an add-on that the user opens, plays around with for a while, and then closes. A widget that allows the user to play, pause and skip tracks in a music application is one example of a control widget.
  • Hybrid widgets. Can’t choose between the different categories? Many widgets combine elements from two or more categories – case in point, the music widget from our previous bullet point. Assuming this widget displays some information about the currently-selected track, then this is an example of a control widget that borrows elements from the information widget category. If you do decide to mix and match, then it’s recommended that you target one category first and then add elements from other categories as and when required.
android-widget-hybrid-music-widget-example

An example of an information widget (above) and a hybrid widget (below) that combines elements of a control widget and an information widget.

What are the essential components of an Android widget?

To create a widget, you’ll need the following classes and XML files:

  • An AppWidgetProviderInfo file. An XML file containing important information about your widget, such as its minimum width and height, its layout resource file, how often it should be updated, and whether it uses a configuration Activity.
  • An AppWidgetProvider class implementation. This is where you’ll define the methods that you’ll use to programmatically interact with your widget.
  • An XML layout resource file. Your widget’s initial layout.
  • An App Widget configuration Activity. If you want the user to be able to modify your widget, then you’ll need to create a configuration Activity. This Activity will launch automatically when the user creates an instance of your widget.

There’s no set rules about the order you should create these files and classes in, but I find that it helps to have a clear idea of how your widget will look, before you start worrying about how it’ll function, so I’m going to start by creating my widget’s layout.

Creating your widget’s layout

You define your widget’s layout in the same way you define the layout for any Activity: create an XML layout resource file and add all the UI elements you want to use.

The only major difference is that widget layouts are based on RemoteViews, so you can only use layouts and views that RemoteViews supports.

Specifically, when you’re creating your widget’s layout you can use the following layout classes only:

  • FrameLayout
  • GridLayout
  • LinearLayout
  • RelativeLayout

And you can use the following widget classes only:

  • AdapterViewFlipper
  • AnalogClock
  • Button
  • Chronometer
  • GridView
  • ImageButton
  • ImageView
  • ListView
  • ProgressBar
  • StackView
  • TextView
  • ViewFlipper

Any layout you create should look good and function correctly across a wide range of different screens, however when it comes to widget layouts you have some extra motivation for ensuring you layout is as flexible as possible:

  • Users typically place widgets on their homescreens, and although all Android homescreens are divided into a grid, the exact number of cells, spacing and sizing will vary between devices. Your widget needs to be flexible enough to handle all the different homescreen grids it may encounter.
  • Users expect to be able to resize widgets horizontally and vertically, so your widget should meet these expectations unless it has a very good reason not to. This means your layout needs to be able to cope with however the user chooses to resize your widget.

Creating a flexible widget layout follows many of the best practices you’ll be familiar with from building other Android layouts, but in particular you should:

  • Provide alternate versions of all your layout’s resources. These alternatives should be optimized for a range of different screen configurations. The Android system will then select the best version of each resource to use at runtime, based on the current device.
  • Create a density-independent layout. Make sure you specify all layout dimensions using density-independent pixels (dpi) and use flexible units of measure, such as “wrap_content” and “match_parent,” rather than absolute units.
  • Test! Make sure you test your widget across a range of screen configurations by creating multiple Android Virtual Devices (AVDs). If you do discover issues with a particular screen configuration, then you may want to create an alternate layout that’s optimized for this particular screen. You should also check that your layout can handle being flipped between portrait and landscape mode, and that it continues to look good and function correctly regardless of how the user resizes it. If you do encounter issues once your widget has been shrunk past a certain size, then you can specify a minimum size for your widget – something I’ll be covering when we create our AppWidgetProviderInfo file.

Create an AppWidgetProviderInfo file

The next step is creating a AppWidgetProviderInfo XML file and defining all the qualities you want your widget to have.

Create a res/xml directory (if your project doesn’t contain one already) and then create a new XML layout inside this directory.

android-app-widget-create-xml-directory

This is going to be our AppWidgetProviderInfo file, so open it and set its root element to <appwidget-provider>. You can now specify all the qualifies your widget should possess – here’s a few examples:

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
// Your widget’s default width and height
   android:minWidth="50dp"
   android:minHeight="50dp"

// How often your widget should be updated, in milliseconds
  android:updatePeriodMillis="90000000"

// The XML file containing the widget’s layout
   android:initialLayout="@layout/appwidget"

// Whether the user can resize your widget horizontally, vertically, or both (horizontal|vertical). If you don’t
// want your widget to be resizable, then you can set this attribute to "none"
   android:resizeMode="horizontal|vertical"

// Even if you follow all the best practices for designing a flexible layout, if a user keeps shrinking your
// widget indefinitely then at some point it’s going to become unusable. Prevent the user from pushing your
// layout to its breaking point, by assigning it a minimum height and width
   android:minResizeHeight="30dp"
   android:minResizeWidth="30dp"

// Specify whether your widget can be displayed on the homescreen, (home_screen), the lockscreen (keyguard)
// or both - although only devices running Android 4.0 and lower support lockscreen widgets. Lockscreen
// widgets aren’t particularly private, so if you do give the user the option of placing your widget on their
// lockscreen then just make sure your widget doesn’t feature any sensitive or potentially embarrassing
// information!
   android:widgetCategory="home_screen">
</appwidget-provider>

Create Your AppWidgetProvider class

The AppWidgetProvider class is where you’ll define the methods that will be called during the widget’s lifecycle, for example whenever a widget is deleted, enabled or disabled. This class is also where you’ll create the code that’ll ultimately be responsible for updating your widget.Create a new Java class that extends the AppWidgetProvider class and override its update methods. In my example, I’m going to be using MyAppWidgetProvider.

 

[Source:-Android Blog]

How to create a widget for your Android app

create-an-android-app-widget-feature-image

Android app widgets may look pretty simple – essentially, they’re just small windows that users embed in an App Widget Host, typically their device’s homescreen – but your average application widget has a lot to offer.

For users, widgets help them make the most of all that homescreen real estate that would otherwise go to waste. And for developers, creating a widget to accompany your latest Android app is a way of delivering a better user experience (and if you want those 5 star reviews then you should seize any opportunity to deliver a better user experience) plus a well-designed app widget is a useful tool for keeping your app at the forefront of the user’s mind.

Every time the user passes through their homescreen, your widget has an opportunity to catch their interest by presenting them with a snippet of your app’s most important content – ideally tempting them into launching your app.
In this article, I’m going to show you how to create an effective app widget for your latest Android project. I’ll be covering all the essentials of creating a basic widget, before sharing some best practices that can help ensure your widget will have no problem securing itself a permanent spot on the user’s homescreen.

Planning your widget

So, you’re sold on the idea of creating an Android app widget, but the first step is deciding what kind of widget you’re going to build.

If you’re struggling for inspiration, then it can help to look at what other Android developers are doing. When you look at all the Android widgets that are currently out there, they can generally be divided into the following categories:

  • Information widgets. Display important information related to your app. Some examples include clock and weather widgets, and widgets that notify the user about new emails or SMS messages.
  • Collection widgets. These vertically-scrolling widgets display multiple elements from the same group, such as a collection of headlines from a news app, or a series of photos from a gallery app.
  • Control widgets. These widgets give users the ability to trigger an app’s most important features from the comfort of their homescreen – kind of like a remote control. A control widget can help your app feel more like an integral part of the user’s device, rather than an add-on that the user opens, plays around with for a while, and then closes. A widget that allows the user to play, pause and skip tracks in a music application is one example of a control widget.
  • Hybrid widgets. Can’t choose between the different categories? Many widgets combine elements from two or more categories – case in point, the music widget from our previous bullet point. Assuming this widget displays some information about the currently-selected track, then this is an example of a control widget that borrows elements from the information widget category. If you do decide to mix and match, then it’s recommended that you target one category first and then add elements from other categories as and when required.

android-widget-hybrid-music-widget-example

An example of an information widget (above) and a hybrid widget (below) that combines elements of a control widget and an information widget.

What are the essential components of an Android widget?

To create a widget, you’ll need the following classes and XML files:

  • An AppWidgetProviderInfo file. An XML file containing important information about your widget, such as its minimum width and height, its layout resource file, how often it should be updated, and whether it uses a configuration Activity.
  • An AppWidgetProvider class implementation. This is where you’ll define the methods that you’ll use to programmatically interact with your widget.
  • An XML layout resource file. Your widget’s initial layout.
  • An App Widget configuration Activity. If you want the user to be able to modify your widget, then you’ll need to create a configuration Activity. This Activity will launch automatically when the user creates an instance of your widget.

There’s no set rules about the order you should create these files and classes in, but I find that it helps to have a clear idea of how your widget will look, before you start worrying about how it’ll function, so I’m going to start by creating my widget’s layout.

Creating your widget’s layout

You define your widget’s layout in the same way you define the layout for any Activity: create an XML layout resource file and add all the UI elements you want to use.

The only major difference is that widget layouts are based on RemoteViews, so you can only use layouts and views that RemoteViews supports.

Specifically, when you’re creating your widget’s layout you can use the following layout classes only:

  • FrameLayout
  • GridLayout
  • LinearLayout
  • RelativeLayout

And you can use the following widget classes only:

  • AdapterViewFlipper
  • AnalogClock
  • Button
  • Chronometer
  • GridView
  • ImageButton
  • ImageView
  • ListView
  • ProgressBar
  • StackView
  • TextView
  • ViewFlipper

Any layout you create should look good and function correctly across a wide range of different screens, however when it comes to widget layouts you have some extra motivation for ensuring you layout is as flexible as possible:

  • Users typically place widgets on their homescreens, and although all Android homescreens are divided into a grid, the exact number of cells, spacing and sizing will vary between devices. Your widget needs to be flexible enough to handle all the different homescreen grids it may encounter.
  • Users expect to be able to resize widgets horizontally and vertically, so your widget should meet these expectations unless it has a very good reason not to. This means your layout needs to be able to cope with however the user chooses to resize your widget.

Creating a flexible widget layout follows many of the best practices you’ll be familiar with from building other Android layouts, but in particular you should:

  • Provide alternate versions of all your layout’s resources. These alternatives should be optimized for a range of different screen configurations. The Android system will then select the best version of each resource to use at runtime, based on the current device.
  • Create a density-independent layout. Make sure you specify all layout dimensions using density-independent pixels (dpi) and use flexible units of measure, such as “wrap_content” and “match_parent,” rather than absolute units.
  • Test! Make sure you test your widget across a range of screen configurations by creating multiple Android Virtual Devices (AVDs). If you do discover issues with a particular screen configuration, then you may want to create an alternate layout that’s optimized for this particular screen. You should also check that your layout can handle being flipped between portrait and landscape mode, and that it continues to look good and function correctly regardless of how the user resizes it. If you do encounter issues once your widget has been shrunk past a certain size, then you can specify a minimum size for your widget – something I’ll be covering when we create our AppWidgetProviderInfo file.

Create an AppWidgetProviderInfo file

The next step is creating a AppWidgetProviderInfo XML file and defining all the qualities you want your widget to have.

Create a res/xml directory (if your project doesn’t contain one already) and then create a new XML layout inside this directory.

android-app-widget-create-xml-directory

This is going to be our AppWidgetProviderInfo file, so open it and set its root element to <appwidget-provider>. You can now specify all the qualifies your widget should possess – here’s a few examples:

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
// Your widget’s default width and height
   android:minWidth="50dp"
   android:minHeight="50dp"

// How often your widget should be updated, in milliseconds
  android:updatePeriodMillis="90000000"

// The XML file containing the widget’s layout
   android:initialLayout="@layout/appwidget"

// Whether the user can resize your widget horizontally, vertically, or both (horizontal|vertical). If you don’t
// want your widget to be resizable, then you can set this attribute to "none"
   android:resizeMode="horizontal|vertical"

// Even if you follow all the best practices for designing a flexible layout, if a user keeps shrinking your
// widget indefinitely then at some point it’s going to become unusable. Prevent the user from pushing your
// layout to its breaking point, by assigning it a minimum height and width
   android:minResizeHeight="30dp"
   android:minResizeWidth="30dp"

// Specify whether your widget can be displayed on the homescreen, (home_screen), the lockscreen (keyguard)
// or both - although only devices running Android 4.0 and lower support lockscreen widgets. Lockscreen
// widgets aren’t particularly private, so if you do give the user the option of placing your widget on their
// lockscreen then just make sure your widget doesn’t feature any sensitive or potentially embarrassing
// information!
   android:widgetCategory="home_screen">
</appwidget-provider>

Create Your AppWidgetProvider class

The AppWidgetProvider class is where you’ll define the methods that will be called during the widget’s lifecycle, for example whenever a widget is deleted, enabled or disabled. This class is also where you’ll create the code that’ll ultimately be responsible for updating your widget.

Create a new Java class that extends the AppWidgetProvider class and override its update methods. In my example, I’m going to be using MyAppWidgetProvider.

public class MyAppWidgetProvider extends AppWidgetProvider {
...
...

// Retrieve the widget’s layout// RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.activity_main); // Tell the AppWidgetManager to perform an update on this application widget// appWidgetManager.updateAppWidget(currentWidgetId,views);

You’ll then need to declare the AppWidgetProvider class in your project’s Manifest:

//Specify your AppWidgetProviderInfo XML file//
<receiver android:name="MyAppWidgetProvider" >
// Specify that the AppWidgetProvider accepts ACTION_APPWIDGET_UPDATE, which is the broadcast that’s sent whenever
// a new instance of this widget is instantiated and also whenever a widget requests an update. Both of these
// are events that the AppWidgetProvider class needs to be able to respond to
   <intent-filter>
       <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
   </intent-filter>
<meta-data android:name="android.appwidget.provider"
// Point the Manifest in the direction of the AppWidgetProviderInfo XML file you created earlier //
     android:resource="@xml/myappwidgetprovider" />
</receiver>

Creating an app widget configuration Activity

Do you want the user to be able to customize your widget? These customizations could be visual tweaks, such as changing the widget’s colour, or functional changes such as specifying how often the widget should be updated.

Whatever the specifics, if you want to create a customizable widget then you’ll need to create a configuration Activity, and set this Activity to launch automatically when the user creates a new instance of your application widget.

To add a configuration Activity to your project, create a new Java class (I’m going to use ConfigurationWidget). Then, when you declare this Activity in your Manifest make sure you specify that it accepts the ACTION_APPWIDGET_CONFIGURE intent.

<activity android:name=".ConfigurationWidget">
   <intent-filter>
       <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
   </intent-filter>
</activity>

You’ll also need to declare this Activity in your project’s AppWidgetProviderInfo using the android:configure attribute, so hop back to this file and add the following:

   android:configure="com.example.android.ConfigurationWidget"

Although the main body of your configuration Activity will vary depending on how the user can edit your widget, there’s a few common features you should add to any configuration Activity, in order to ensure it functions correctly.

Firstly, if the user exits the Activity without completing the configuration process, then you should notify the widget host and tell it not to add the widget to the user’s homescreen:

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setResult(RESULT_CANCELED);

Normally, when the user adds a widget to their homescreen, performing the initial setup is the onUpdate method’s responsibility. However, as soon as you create a configuration Activity, this setup becomes the responsibility of the configuration Activity. This means your configuration Activity will need to request an update from the AppWidgetManager:

//Find the App Widget ID from the Intent that launched this Activity//

Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
   mAppWidgetId = extras.getInt(
           AppWidgetManager.EXTRA_APPWIDGET_ID,
           AppWidgetManager.INVALID_APPWIDGET_ID);
}

// If you receive an intent without the appropriate ID, then the system should kill this Activity//
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
    finish();
}

Once you’ve completed this setup, you can fill this class with all the options your users should be presented with when they create an instance of your widget. Just don’t get carried away – setting up a widget shouldn’t feel like a monumental task, so limit yourself to 2-3 configuration options.

Once you’ve written your configuration code, there’s a few final tasks you’ll need to complete. Firstly, you’ll need to get an instance of the AppWidgetManager by calling getInstance(Context):

AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);

Then, you’ll need to update the app widget with a RemoteViews layout by calling updateAppWidget(int, RemoteViews):

RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.example_appwidget);
appWidgetManager.updateAppWidget(mAppWidgetId, views);

Finally, create the return Intent, set it with the Activity result, and finish your configuration Activity:

Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();

App Widget Best Practices

Now you know the basics of creating a functioning application widget, let’s look at ways to build on these foundations by covering some best practices.

Include margins for earlier versions of Android

An application widget that extends to the edges of the user’s screen or presses flush against other widgets runs the risk of making the user’s homescreen look messy or cluttered. You can make sure your widget always has some breathing space, by including margins.

On Android 4.0 and higher, the system automatically adds padding between the widget frame and the widget’s bounding box, so you only need to add margins manually when your app is installed on devices running anything earlier than Ice Cream Sandwich. You definitely don’t want to add margins across the board, as your manual margins combined with those automatic margins can seriously add up on devices running Android 4.0 and higher, creating an awkward amount of empty space around your widget.

The solution is to create two dimens.xml files that specify different margins, depending on the device your app is installed on:

  • res/values-v14/dimens.xml. In this file, define the 0dp of padding that should be added to the margins that Android 4.0 creates by default.
    <dimen name="widgetmargin">0dp</dimen>
  •  res/values/dimens.xml. This is where you’ll define your widget’s custom margins that should be used on devices running anything earlier than Android 4.0.
    <dimen name="widgetmargin">10dp</dimen>

android-widget-create-alternate-dimens-files

Then, you just need to reference “widgetmargin” in your widget’s layout and the system will select the appropriate widgetmargin value to use at runtime:

    android:padding="@dimen/widgetmargin"

Don’t update too often

Up now, we’ve focused on one method of updating your widget: using the updatePeriodMillis attribute to specify an update interval. Once this interval has elapsed, the app widget framework will request an update, and if the device happens to be asleep at the time then it’ll wake up in order to perform this update.

Waking the user’s device every now and again generally isn’t a huge problem, but if your widget requires frequent updates then this can result in a noticeable drain on the device’s battery. And battery-hogging apps rarely get good reviews on Google play! For the sake of preserving the device’s battery life, you should update your widget as infrequently as you can possibly can without compromising the user experience.

If your widget does have a valid reason for requiring frequent updates, then you should avoid using updatePeriodMillis and opt for an alternative, more battery-friendly way of updating your widget.

One option, is to perform updates based on an alarm that only gets delivered if the device is awake. If the device is asleep, then the update will be delayed until the device wakes up, which means your widget’s updates won’t have such a negative impact on the user’s battery.

To use this technique in your project, you’ll need to use the AlarmManager system service to create an alarm and set it to the type AlarmManager.RTC. You can then specify how often you want your widget to update, in milliseconds, for example:

alarmManager.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), 1000 , ClockIntent(context));

Even after you’ve written this code, your project’s updatePeriodMillis attribute can override your alarm and wake the device anyway. To make sure this doesn’t happen, find this attribute in your project and set it to android:updatePeriodMillis=”0″

Since alarms are delivered as intents, you’ll need to configure your app to listen for this intent type, so open your project’s Manifest and add a new intent-filter beneath the existing  APPWIDGET_UPDATE filter. For example:

<intent-filter>
   <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
   <intent-filter>
   <action android:name="com.jessicathornsby.myapplicationwidget.WIDGET_UPDATE" /> </intent-filter>

With this bit of setup out of the way, you’re free to update your AppWidgetProvider class with the code that specifies how often you want to send this intent, and how your widget should handle these intents when they arrive.

Provide a preview image

You add a new widget to your homescreen by launching your device’s widget picker, browsing the available options, and then selecting the one you like the look of. When you’re browsing this widget picker, you may have noticed that many apps display a preview image of how their widget will look once it’s properly configured and setup on your homescreen.
create-an-android-app-widget

A well-designed preview image is a good way of encouraging the user to choose your widget over the competition, so it’s well worth taking the time to create a preview image. If your project doesn’t feature a dedicated preview image, then the system will use your app’s launcher icon instead, which doesn’t quite have the same effect.

Create the image you want to use and add it to your project’s ‘drawable’ folder. Then, open your AppWidgetProviderInfo file and point it in the direction of this new drawable resource, using the android:previewImage attribute:

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
...
 android:previewImage="@drawable/preview">
</appwidget-provider>

Wrapping Up

In this article, we looked at how to create all the necessary classes and files you’ll need to develop an Android app widget, including an optional configuration Activity that will allow users to tweak your widget’s settings. I also shared some best practices that can help you put those finishing touches to your widget. You can find an app widget outline, complete with all the code covered in this article, on GitHub.

[Source:-Android Authority]