博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
生成桌面插件
阅读量:4931 次
发布时间:2019-06-11

本文共 3438 字,大约阅读时间需要 11 分钟。

package org.app.qqmusicplayer;import android.app.PendingIntent;import android.appwidget.AppWidgetManager;import android.appwidget.AppWidgetProvider;import android.content.ComponentName;import android.content.Context;import android.content.Intent;import android.util.Log;import android.widget.RemoteViews;public class AppWidget extends AppWidgetProvider {    private static final String PLAY_ACTION = "com.app.playmusic";    private static final String NEXT_ACTION = "com.app.nextone";    private static final String lAST_ACTION = "com.app.lastone";    private static final String START_APP = "com.app.startapp";    @Override    public void onDeleted(Context context, int[] appWidgetIds) {        Log.i("info", "onDeleted...");        super.onDeleted(context, appWidgetIds);    }    @Override    public void onDisabled(Context context) {        Log.i("info", "onDisabled...");        super.onDisabled(context);    }    @Override    public void onEnabled(Context context) {        Log.i("info", "onEnabled...");        super.onEnabled(context);    }    @Override    public void onReceive(Context context, Intent intent) {        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidgetlayout);        if (intent.getAction().equals("com.app.pause")){            views.setImageViewResource(R.id.playButton, R.drawable.play_button);        } else if (intent.getAction().equals("com.app.play")){            views.setImageViewResource(R.id.playButton, R.drawable.pause_button);        } else if (intent.getAction().equals("com.app.musictitle")){            String musicName = intent.getExtras().getString("title");            if (musicName.length()>6){                musicName = musicName.substring(0, 5)+"...";            }            views.setTextViewText(R.id.title, musicName);        }        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);         ComponentName componentName = new ComponentName(context,AppWidget.class);         appWidgetManager.updateAppWidget(componentName, views);        Log.i("info", "onReceive...");        super.onReceive(context, intent);    }    @Override    public void onUpdate(Context context, AppWidgetManager appWidgetManager,            int[] appWidgetIds) {        Log.i("info", "onUpdate...");        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidgetlayout);        /**设置播放键的动作*/        views.setImageViewResource(R.id.playButton, R.drawable.play_button);        Intent playIntent = new Intent(PLAY_ACTION);        PendingIntent playPending = PendingIntent.getBroadcast(context, 0, playIntent, 0);        views.setOnClickPendingIntent(R.id.playButton, playPending);        /**设置上一首按钮的动作*/        Intent lastIntent = new Intent(lAST_ACTION);        PendingIntent lastPending = PendingIntent.getBroadcast(context, 0, lastIntent, 0);        views.setOnClickPendingIntent(R.id.lastButton, lastPending);        /**设置下一首按钮的动作*/        Intent nextIntent = new Intent(NEXT_ACTION);        PendingIntent nextPending = PendingIntent.getBroadcast(context, 0, nextIntent, 0);        views.setOnClickPendingIntent(R.id.nextButton, nextPending);                /**获取正在播放的音乐名*/        Intent intent = new Intent();        intent.setAction(START_APP);        context.sendBroadcast(intent);                appWidgetManager.updateAppWidget(appWidgetIds, views);    }}

 

转载于:https://www.cnblogs.com/ct732003684/archive/2013/01/09/2853371.html

你可能感兴趣的文章
[AtCoder3856]Ice Rink Game - 模拟
查看>>
03、MySQL—数据表操作
查看>>
SQL 将一个表中的所有记录插入到一个临时表中
查看>>
nmea协议
查看>>
js 中对象的特性
查看>>
hdoj3714【三分】
查看>>
D-【乐】k进制数(同余)
查看>>
解决T4-1 solaris11无法启动问题
查看>>
CSS 伪元素
查看>>
Asp.net IsPostBack
查看>>
ASP.NET MVC使用Ninject
查看>>
Android透明无边框圆形进度条之最简单实现
查看>>
Dynamics CRM2016 Web API之Expand related entities & $ref & $count
查看>>
MEF 编程指南(八):过滤目录
查看>>
css样式中position和_position的区别
查看>>
hdu 3065 病毒侵袭持续中 AC自动机
查看>>
ajax返回json数据示例
查看>>
DAY9 函数初识(各种参数的用法)
查看>>
9-19练习
查看>>
【zz】贝叶斯推断及其互联网应用
查看>>