我正在尝试获取我的小部件的所有ACTIVE实例的列表.在我的AppWidgetProvider的OnUpdate方法中,我正在执行以下操作:
// Get all ids
ComponentName thisWidget = new ComponentName(context, this.getClass());
int[] lastWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
问题是,如果您将小部件添加到主屏幕然后将其删除,getAppWidgetIds仍会返回一个列表,其中包含您刚刚删除的小部件的ID.
有没有办法只检索主屏幕上活动的小部件的ID?
虽然我很欣赏App Widget不WebView直接支持,但是它是否可以使用ImageView(支持),以及这里描述的技术来生成图像ImageView?该WebView不会直接使用,但只在后台使用,以用于提供图像ImageView.
android webview imageview appwidgetprovider android-appwidget
可能是我,但是当我根据android页面上给出的公式计算最小app小部件大小时,我得不到正确的小部件宽度; 公式如下:
width(n)=(70 xn) - 30
当我想要一个5x1小部件时,正确的宽度将是(5*70) - 30 = 320dp.然而,当在motorola Xoom上测试它时,它解析为4x1小部件.我已经测试了不同的值,400dp对于带有Honeycomb的motorola xoom上的5x1似乎很好,但后来我在常规Galaxy Tab上用Gingerbread测试它然后它解析为6x1(就像人们期望的那样).
这里有两个问题;
android android-3.0-honeycomb android-2.3-gingerbread android-4.0-ice-cream-sandwich android-appwidget
我正在使用Android应用小部件.我正在创建一个PendingIntent对象并在方法中使用它RemoteViews#setOnClickPendingIntent().这是未决的意图:
// The below code is called in the onUpdate(Context, AppWidgetManager, int[]) method of the AppWidgetProvider class.
// Explicit intent
Intent intent = new Intent(context, MyService.class);
intent.setAction(MY_ACTION);
intent.putExtra(EXTRA_KEY, VALUE);
// Create the pending intent
PendingIntent pendingIntent = PendingIntent.getService(context, appWidgetId, intent, 0);
// 'views' is a RemoteViews object provided by onUpdate in the AppWidgetProvider class.
views.setOnClickPendingIntent(R.id.root_layout, pendingIntent);
上面的代码在Android Oreo之前按预期工作.但是,在Android Oreo中,如果将应用程序从最近的位置移除,它将不再启动该服务.(不再有效).PendingIntent在Oreo的后台执行限制中不排除?
出于测试目的,我更换getService了getForegroundService但Service仍未启动.这两种方法都在日志中显示以下消息:
W/ActivityManager: Background start not allowed: service Intent { …android android-widget android-service android-appwidget android-8.1-oreo
我正在努力想出如何以编程方式删除主屏幕AppWidget(即用户实际上没有将其拖入垃圾箱).例如,考虑一个可以拥有多个帐户的应用,每个帐户都有任意数量的小部件 - 一旦删除帐户,小部件也应该被删除.
我试过从http://www.netmite.com/android/mydroid/cupcake/frameworks/base/services/java/com/android/server/AppWidgetService.java上看一个不起眼的例子,但似乎没有甚至触发OnDeleted,更不用说从主屏幕上删除AppWidget了.
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_DELETED);
intent.setComponent(info.componentName); // references AppWidgetProvider's class
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
sendBroadcast(intent);
有没有人对如何实现这一点有任何建议?一个例子是蜜蜂的膝盖.谢谢.
我创建了一个Contentprovide并实现了它的update()方法,如下所示:
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    final SQLiteDatabase db = mHelper.getWritableDatabase();
    int count = db.update(InslideDB.FOLDER_TABLE, values, selection, selectionArgs);
    /* To notify the observer */
    this.getContext().getContentResolver().notifyChange(URI, null);  
    return count;
}
如何在appwidget中收到通知?谢谢!
我正在尝试这个解析器,但没有Log(-------------------- Date Changed)打印:
class DataProviderObserver extends ContentObserver {
    private AppWidgetManager mAppWidgetManager;
    private ComponentName mComponentName;
    DataProviderObserver(AppWidgetManager mgr, ComponentName cn, Handler h) {
        super(h);
        mAppWidgetManager = mgr;
        mComponentName = cn;
    }
    @Override
    public void onChange(boolean selfChange) {
        super.onChange(selfChange);  //NOTE: Have to call this. dwy.
        // …我有一个Appwidget显示几天直到一个事件,如:
eventname(-231天)
如果可能,我想在一行中显示此字符串.如果eventname太长,我想将大括号中的完整术语显示为一个新行.所以它就像:
longeventname
(-231天)
代替:
longeventname(-231
天)
(或任何类似的)
有没有办法存档?我可以(-231天)"原子"吗?
string.getLength将无法工作,因为窗口小部件的大小会因设备而异.
android line-breaks textview android-layout android-appwidget
我正在尝试创建一个小部件.我就像这里描述的那样:https://stackoverflow.com/a/6093753/2180161
它部分工作,但我有一个非常奇怪的错误.我做了一个截屏视频,所以更容易理解我的意思:http: //c.maysi.de/c6H9
如您所见,有一些项目是随机添加的.(RemoteViews已添加到另一个RemoteViews对象)
 当我调整窗口小部件时,会发生同样的情况.
我在日志中打印的内容与预期的一样.没有错误的数据.滚动时也没有新的日志条目.
这是我的代码:
RemoteViewsFactory:
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class MyWidgetViewsFactory implements RemoteViewsService.RemoteViewsFactory {
    private static ArrayList<Item> items = new ArrayList<>();
    private static int itemnr = 0;
    private static int subitemnr = 0;
    private int appWidgetId;
    private Context context;
    public MyWidgetViewsFactory(Context context, Intent intent) {
        this.context = context;
        appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);
        //Some random data to display
        for (int i = …android listview android-widget android-listview android-appwidget
我知道这已被多次询问,但我从上到下阅读了文档,在这里阅读了所有答案,但没有一个帮助.说实话,每个答案都说明了如何解决这个问题.
现在回到我的问题.我想从某些活动更新小部件列表视图,我WidgetProvider#sendUpdateBroadcastToAllWidgets()为此目的创建了我从活动中调用的内容.
它最终调用,onUpdate()以便正确接收广播.但意见没有刷新.
我也尝试调用AppWidgetManager#notifyAppWidgetViewDataChanged()和刷新数据,WidgetFactory#onDataSetChanged()但从未调用过该方法.
所以我猜这一切都行不通,因为远程视图工厂被缓存但我不知道如何可靠地克服这一点.有什么想法吗?
那些背景呢?我总是要提供一个,但我真的不在乎哪一个.有关系吗?
谢谢
提供商
public class WidgetProvider extends AppWidgetProvider {
    public static void sendUpdateBroadcastToAllWidgets(Context context) {
        int allWidgetIds[] = AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, WidgetProvider.class));
        Intent intent = new Intent(context, WidgetProvider.class);
        intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds);
        context.sendBroadcast(intent);
    }
    @Override
    public void onUpdate(Context context, AppWidgetManager widgetManager, int[] widgetIds) {
        for (int id : widgetIds) {
            updateWidget(context, widgetManager, id);
        }
        super.onUpdate(context, widgetManager, widgetIds);
    }
    @Override
    public void onDeleted(Context context, int[] widgetIds) {
        WidgetPreferences prefs = …我有一个使用的appwidget ListView.我创建了一个扩展的类RemoteViewsService:
public class AppWidgetService extends RemoteViewsService {
    @Override
    public RemoteViewsFactory onGetViewFactory(Intent intent) {
        return (new AppWidgetListFactory(this.getApplicationContext(), intent));
    }
}
在我的AppWidgetProvider,我为每个小部件实例(每个appWidgetId)调用以下方法:
private static void fillInList(RemoteViews widget, Context context, int appWidgetId) {
    Intent intent = new Intent(context, AppWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    widget.setRemoteAdapter(R.id.appwidget_listview, intent);
}
的构造函数 AppWidgetListFactory
public AppWidgetListFactory(Context context, Intent intent) {
    this.context = context;
    appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
    System.out.println("New TVAPWLF for: " + appWidgetId);
    trains = WidgetData.getInstance().widgetMap.get(appWidgetId);
}
现在问题是,该fillInList方法被调用的方式与小部件的实例一样频繁,但该onGetViewFactory方法只被调用一次.这导致所有小部件显示相同的数据.
我怎样才能解决这个问题?
android ×10
android-4.0-ice-cream-sandwich ×1
imageview ×1
java ×1
line-breaks ×1
listview ×1
notify ×1
textview ×1
webview ×1