zoukankan      html  css  js  c++  java
  • android widget 点击进入应用

    package com.ljapps.wifix.ui.provider;
    
    import android.app.PendingIntent;
    import android.appwidget.AppWidgetManager;
    import android.appwidget.AppWidgetProvider;
    import android.content.Context;
    import android.content.Intent;
    import android.net.Uri;
    import android.widget.RemoteViews;
    
    import com.ljapps.wifix.R;
    import com.ljapps.wifix.ui.activity.WifiXEntryActivity;
    
    /**
     * Created by Alter on 16/9/7.
     */
    public class WidgetIconProvider extends AppWidgetProvider {
        @Override
        public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
            final int N = appWidgetIds.length;
            for (int i = 0; i < N; i++) {
                int appId = appWidgetIds[i];
                Intent intent = new Intent(context, WifiXEntryActivity.class);
                intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appId);  // Identifies the particular widget...
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    
                intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
                PendingIntent pendIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    
                RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.layout_widget);
                views.setOnClickPendingIntent(R.id.widget_icon, pendIntent);
                appWidgetManager.updateAppWidget(appId,views);
            }
        }
    
        @Override
        public void onReceive(Context context, Intent intent) {
            super.onReceive(context, intent);
        }
    }
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent" android:layout_height="match_parent">
    <ImageView
        android:id="@+id/widget_icon"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:background="@drawable/ic_launcher"/>
    </RelativeLayout>
    <?xml version="1.0" encoding="utf-8"?>
    <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:initialLayout="@layout/layout_widget"
        android:minHeight="60dp"
        android:minWidth="60dp"
        android:resizeMode="horizontal|vertical"
        android:updatePeriodMillis="86400000"
        android:widgetCategory="home_screen|keyguard"></appwidget-provider>
    <receiver android:name=".ui.provider.WidgetIconProvider">
                <meta-data android:name="android.appwidget.provider"
                    android:resource="@layout/widget_icon_provider"></meta-data>
                <intent-filter>
                    <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                </intent-filter>
            </receiver>
  • 相关阅读:
    python中不可变数据类型和可变数据类型
    你分得清Python中:“索引和切片”吗?
    Python Django中一些少用却很实用的orm查询方法
    jQuery on()方法
    jquery.flexslider-min.js实现banner轮播图效果
    jQuery 树型菜单插件(Treeview)
    jQuery Growl 插件(消息提醒)
    jQuery Autocomplete 用户快速找到并从预设值列表中选择
    jQuery Accordion 插件用于创建折叠菜单
    jquery.validate.js 验证框架详解
  • 原文地址:https://www.cnblogs.com/qianyukun/p/5850013.html
Copyright © 2011-2022 走看看