0.5 C
New York
Tuesday, November 28, 2023

Android Widget (Home Screen and LockScreen)

Please follow the steps be to create a widget on your smartphone by the Android Studio.

First I’ll create a new project. So we start from the ground up and have a look at the minimum SDK which is API android 4.1 jelly bean that’s a little bit important which you will see at the later point because a widget is available for the home screen. So android 5 lollipop is a change in version, on versions above android 5 the lock screen is not available for widgets anymore.

We start with an empty activity, which is default stuff.

And lets see, while this is running; system comes up, building app…. My application.

Now the Android studio is starting.

It opens my new project and they have created some help in some automatism in the android studio.

Now let’s start here –

when the system came up here – we have the main activity, that’s default.

And let’s say this is our text – ‘Demo Widget’, so that we know that its the app.

And now  in java, go to ‘new’ -> app -> app widget

And for the app widget the default is your home screen only because your keyguard only an API 17+.

Now you say home screen and keyguard and lets have a look there again, homescreen only or keyguard only (API17+) that’s important on another point.

Let’s have a look there, that’s written here on developer android.com – for android 5 zero and higher only homescreen is valid.

Only android versions 5.0 and lower support lock screen widgets.

So when you select on here – the keyguard, then the keyguard is available only on the home screen, not the lock screen for future applications. And then there is also a button here, click button configuration screen.

And maybe you want to have an app with 2nd positions.The widget will be placed on those positions on the homescreen or cells.

And the assistant creates one file in the java files where the code is placed for the new Java

And something which is called ‘App widget configuration activity’ we will see what this is at a later point. Then we have on the resources a layout. A layout for the main activity itself, so you may have an app __ do some stuff and the widget itself is lets say an additional option.

And here we have the layout for the app widget which is this one that’s the text we will see at a later point.

There’s a textview 

Let’s have a look there again. Only that stuff is possible there – button, image button, text view and some other views are possible to be placed in this lock screen widget or in this widget (homescreen or lock screen).

And now we run that stuff on our emulator

And while this is running I will show you something on the manifest.

The manifest, there is also something written there where we should have a look. When the system created that widget template, this receiver take an intent filter and metadata. So this is done by inserting that widget by the menu 

I will show you now some stuff. When the system came up with this stuff….

Now when I click on my homescreen there will come out a widget.

A block and on the widget block before I tested it with my widget. Now when I click on there and I hold it and place it on my homescreen.

Automatically, when I crop it there comes up a configuration so this is my first example/widget.

Now I add this widget and the widget comes here and also takes that text

And I can click on there, there is no action bound with this widget. Its like a…. or something like this. And we close this now for the moment. And now we will see here the new app widget info.xml.

There is one small block in there called android configure.

And this forces in my application

The new app widget configuration activity so this class will be opened as soon as you implement the widget into the homescreen

And for the point on this app was to show, you see nexus API 23.

Now this is starting and the point is that since this is API 23 is that you can configure anything on the lock screen.

So….. at the lock screen at this point.

Related Articles

Latest Articles