Download Source
package com.javaorigin.widget; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.widget.RemoteViews; package com.javaorigin.widget; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.widget.RemoteViews; public class TemperatureWidget extends AppWidgetProvider { double temp=0; @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { context.getApplicationContext().registerReceiver(this,new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); updateUI(context) ; } @Override public void onReceive(Context context, Intent intent) { temp=intent.getIntExtra("temperature", 0)/10.0D; updateUI(context) ; super.onReceive(context, intent); } private void updateUI(Context context) { RemoteViews thisViews = new RemoteViews(context.getApplicationContext() .getPackageName(), R.layout.widget_layout); thisViews.setTextViewText(R.id.update, temp + ""); ComponentName thisWidget = new ComponentName(context,TemperatureWidget.class); AppWidgetManager.getInstance(context).updateAppWidget(thisWidget,thisViews); } }Create widget_layout.xml under res/layout folder
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="8dip" android:background="@drawable/myshape" > <TextView android:id="@+id/update" style="@android:style/TextAppearance.Medium" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:gravity="center_horizontal|center_vertical" android:layout_margin="4dip" android:text="Static Text" > </TextView> </LinearLayout>Create myshape.xml under res/drawable folder
<?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <stroke android:width="2dp" android:color="#FFFFFFFF" /> <gradient android:angle="225" android:endColor="#DD2ECCFA" android:startColor="#DD000000" /> <corners android:bottomLeftRadius="7dp" android:bottomRightRadius="7dp" android:topLeftRadius="7dp" android:topRightRadius="7dp" /> </shape>Create widget_info.xml under res/xml folder ,We can create this xml file using " File-->New --> Android xml file " menu with resource type is AppWidget Provider option ,then set attribute android:widgetCategory="keyguard|home_screen"
<?xml version="1.0" encoding="utf-8"?> <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:initialLayout="@layout/widget_layout" android:minHeight="20dp" android:minWidth="20dp" android:updatePeriodMillis="30000" android:widgetCategory="keyguard|home_screen"> </appwidget-provider>Configure android manifest xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.javaorigin.widget" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <receiver android:name="TemperatureWidget" > <intent-filter > <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_info" /> </receiver> </application> </manifest>
nice man.continue posting
ReplyDeletei have one suggestion.need explanation about the code and what u does
ReplyDeleteGood job man.
ReplyDeletehttp://www.hifive-studio.com/
i am facing the issue while running this code Like:-01 08:03:01 - TemperatureWidget] \TemperatureWidget\bin\TemperatureWidget.apk installed on device
ReplyDelete[2015-04-01 08:03:01 - TemperatureWidget] Done!
i have one project i want to put my app icon on the lock screen how it is possible plz help me my id is aashusonava@gmail.com
ReplyDeleteFor more details contact me at akhilgite@gmail.com
Deletei have a suggestion that u also have to show the image of its output.
ReplyDeletefree android app source codes available in www.oortech.in
ReplyDeleteVery informative ..i suggest this blog to my friends..Thank you for sharing
ReplyDeleteAndroid Training in velachery | Android Training in chennai | Android Training in chennai with placement
Good blog for newly developer..easy way to approach the Android Home And Lock Screen Widget.Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.
ReplyDeleteAndroid Training in chennai | Android Training
Excellent post! how to add a AppName at the bottom of widget?? please tell me.
ReplyDeleteI am really happy with your blog because your article is very unique and powerful for new reader.
ReplyDeleteselenium training in chennai
selenium training in bangalore
myTectra Placement Portal is a Web based portal brings Potentials Employers and myTectra Candidates on a common platform for placement assistance
ReplyDeleteThis comment has been removed by the author.
ReplyDeletethank you so much for this nice information Article, Digitahanks for sharing your post with us.sap scm training in bangalore
ReplyDeleteThis is amazing and really inspiring goal.sap pm training in bangalore
ReplyDeleteIt is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful.sap crm training in bangalore
ReplyDeleteI have read your blog its very attractive and impressive. I like it your blog.sap ewm training in bangalore
ReplyDeleteGreat post!I am actually getting ready to across this information,i am very happy to this commands.Also great blog here with all of the valuable information you have.Well done,its a great knowledgez.
ReplyDeleteThank you for sharing such a nice post!
ReplyDeleteLearn DevOps Training from the Industry Experts we bridge the gap between the need of the industry. Softgen Infotech provide the Best DevOps Training in Bangalore with 100% Placement Assistance. Book a Free Demo Today.
Very interesting, good job and thanks for sharing such a good blog. your article is so convincing that I never stop myself to say something about it. You’re doing a great job. Keep it up…
ReplyDeleteLearn DevOps Training from the Industry Experts we bridge the gap between the need of the industry. Softgen Infotech provide the Best DevOps Training in Bangalore with 100% Placement Assistance. Book a Free Demo Today.
Very useful and information content has been shared out here, Thanks for sharing it.
ReplyDeletecloud computing training in bangalore
cloud computing courses in bangalore
cloud computing classes in bangalore
cloud computing training institute in bangalore
cloud computing course syllabus
best cloud computing training
cloud computing training centers
I enjoyed your blog Thanks for sharing such an informative post. We are also providing the best services click on below links to visit our website.
ReplyDeletedigital marketing company in nagercoil
digital marketing services in nagercoil
digital marketing agency in nagercoil
SEO company in nagercoil
SEO services in nagercoil
social media marketing in nagercoil
social media company in nagercoil
PPC services in nagercoil
digital marketing company in velachery
digital marketing company in velachery
digital marketing services in velachery
digital marketing agency in velachery
SEO company in velachery
SEO services in velachery
social media marketing in velachery
social media company in velachery
PPC services in velachery
online advertisement services in velachery
online advertisement services in nagercoil
web design company in nagercoil
web development company in nagercoil
website design company in nagercoil
website development company in nagercoil
web designing company in nagercoil
website designing company in nagercoil
best web design company in nagercoil
web design company in velachery
web development company in velachery
website design company in velachery
website development company in velachery
web designing company in velachery
website designing company in velachery
best web design company in velachery
Thanks for Sharing - ( Groarz branding solutions )
I have read Your Article and Learn a lot from it. I can Imagine the time it took to get all this expertise exposed . You can also look here to see where to easily get a HIGH QUALITY BANK STATEMENTS FOR MORTGAGE I've bookmark your site and furthermore include RSS. keep us refreshed all the time.
ReplyDeleteI am happy to find this post very useful for me, as it contains lot of information.
ReplyDeletecheck here
Learn Amazon Web Services for excellent job opportunities from Infycle Technologies, the Excellent AWS Training in Chennai. Infycle Technologies gives the most trustworthy AWS course in Chennai, with full hands-on practical training from professional trainers in the field. Along with that, the placement interviews will be arranged for the candidates, so that, they can meet the job interviews without missing them. To transform your career to the next level, call 7502633633 to Infycle Technologies and grab a free demo to know more
ReplyDelete