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>
  • 相关阅读:
    解决Eclipse中“诡异”的错误:找不到或无法加载主类
    eclipse 中的注释 快捷键 多行注释快捷键 单行注释快捷键
    将Eclipse设置为黑色主题
    Javac提示不是内部或外部命令
    js粒子旋涡
    canvas黑客帝国代码雨特效 | jQuery特效|手机微信网站特效| 网页特效库
    python笔记--冒泡排序升级版
    MySQL5.7(二)数据库的基本操作
    Linux命令应用大词典-第1章 登录、退出、关机和重启
    第1章 Linux命令行简介
  • 原文地址:https://www.cnblogs.com/qianyukun/p/5850013.html
Copyright © 2011-2022 走看看