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>
  • 相关阅读:
    使用yum命令报错
    CentOS6.8安装Python3.6.3
    解决 linux 下安装 node 报: command not found
    Python的pip源切换为国内阿里云镜像
    开源Java加密工具Jasypt 1.4发布
    JavaFX对Java开发者到底意味着什么?
    16 个印象深刻的 HTML5/CSS3/JavaScript 体验
    高效的Java异常处理
    Java开发的学习过历程
    Java中23种设计模式详解
  • 原文地址:https://www.cnblogs.com/qianyukun/p/5850013.html
Copyright © 2011-2022 走看看