Created
November 21, 2013 11:05
-
-
Save ishitcno1/7579790 to your computer and use it in GitHub Desktop.
Implement android widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<receiver android:name=".MyAppWidgetProvider"> | |
<intent-filter> | |
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> | |
</intent-filter> | |
<meta-data | |
android:name="android.appwidget.provider" | |
android:resource="@xml/appwidget_info" /> | |
</receiver> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="vertical" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<ImageView | |
android:id="@+id/iv_appwidget" | |
android:layout_height="wrap_content" | |
android:layout_width="wrap_content" | |
android:src="@drawable/ic_launcher" | |
android:layout_gravity="center" | |
/> | |
<TextView | |
android:layout_height="wrap_content" | |
android:layout_width="wrap_content" | |
android:layout_gravity="center" | |
android:paddingTop="7dp" | |
android:gravity="center" | |
android:text="@string/widget_label" | |
android:textColor="@android:color/white" | |
android:shadowColor="@android:color/black" | |
android:shadowRadius="2"/> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" | |
android:minWidth="48dp" | |
android:minHeight="48dp" | |
android:updatePeriodMillis="0" | |
android:previewImage="@drawable/ic_launcher" | |
android:initialLayout="@layout/appwidget" | |
android:widgetCategory="home_screen" | |
android:resizeMode="horizontal|vertical"> | |
</appwidget-provider> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.PendingIntent; | |
import android.appwidget.AppWidgetManager; | |
import android.appwidget.AppWidgetProvider; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.widget.RemoteViews; | |
public class MyAppWidgetProvider extends AppWidgetProvider { | |
@Override | |
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { | |
Intent intent = new Intent(context, AIntentService.class); | |
PendingIntent pi = PendingIntent.getService(context, 0, intent, 0); | |
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget); | |
views.setOnClickPendingIntent(R.id.iv_appwidget, pi); | |
appWidgetManager.updateAppWidget(appWidgetIds[0], views); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment