1:在清单注册:
android:label="@string/app_name"
>
2:xml 文件夹下demo_info.xml
android:updatePeriodMillis="1800000"
android:initialLayout="@layout/widget"
android:minHeight="288px"
android:minWidth="512px"
>
3.layout文件夹下widget.xml
android:layout_width="512px"
android:layout_height="294px"
android:orientation="vertical"
>
android:layout_width="match_parent"
android:layout_height="wrap_content" >
4 在src 下:
public class LenovoLeosWidgetDemoWidgetProvider extends AppWidgetProvider {
private static final String TAG = "LenovoLeosWidgetDemoWidgetProvider";
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Log.e(TAG, "----onUpdate-----");
// RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
// Intent intent = new Intent(context, TargetActivity.class);
// PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
for (int appWidgetId : appWidgetIds) {
// views.setOnClickPendingIntent(R.id.button, pendingIntent);
// appWidgetManager.updateAppWidget(appWidgetId, views);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.e(TAG, "action ================================== " + action);
super.onReceive(context, intent);
}
}
5:横竖屏监听 :
在application:
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Log.e("yy", "当前屏幕为横屏");
} else {
Log.e("yy", "当前屏幕为竖屏");
}
super.onConfigurationChanged(newConfig);
}
清单中:
application加上这条语句
android:configChanges="orientation|keyboardHidden"