相关疑难解决方法(0)

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(就像人们期望的那样).

这里有两个问题;

  • 我可以俯瞰Gingerbread和Honeycomb有什么区别?
  • 既然我知道ICS小部件大小不再在小部件之间有填充,那么这里有一些经验法则吗?

android android-3.0-honeycomb android-2.3-gingerbread android-4.0-ice-cream-sandwich android-appwidget

16
推荐指数
2
解决办法
1万
查看次数

Android小部件在一段时间后停止工作?

我有一个带小部件的手电筒应用程序.小部件用于打开和关闭手电筒,不显示主要活动或任何内容.然而,几个小时后,小部件什么都不做.我的意思是如果你点击它,没有任何反应.我有两个来完成这个a Provider和a Receiver.

Provider:

public class WidgetProvider extends AppWidgetProvider {

  @
  Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager,
    int[] appWidgetIds) {

    Intent receiver = new Intent(context, FlashlightWidgetReceiver.class);
    receiver.setAction("COM_FLASHLIGHT");
    receiver.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, receiver, 0);

    RemoteViews views = new RemoteViews(context.getPackageName(),
      R.layout.appwidget_layout);
    views.setOnClickPendingIntent(R.id.imageButton, pendingIntent);

    appWidgetManager.updateAppWidget(appWidgetIds, views);

  }
}
Run Code Online (Sandbox Code Playgroud)

Receiver:

public class FlashlightWidgetReceiver extends BroadcastReceiver {
  private static boolean isLightOn = false;
  private static Camera camera;
  MediaPlayer mp;@
  Override
  public void onReceive(Context context, Intent intent) { …
Run Code Online (Sandbox Code Playgroud)

android widget broadcastreceiver appwidgetprovider

7
推荐指数
2
解决办法
2860
查看次数

如何在没有调用onAppWidgetOptionsChanged的设备上捕获小部件大小更改?

使用Android版4.1.2的三星Galaxy S3等设备有一个阻止onAppWidgetOptionsChanged被调用的错误.

那么,我们如何才能获得与尺寸变化相关的信息?

android android-widget

6
推荐指数
2
解决办法
3010
查看次数

启动Launcher后,AppWidget PendingIntent无法正常工作

我有一个AppWidget有2个待定意图.他们大部分时间都在工作,但过了一段时间他们就停止了回应.我唯一能够确定的是,它们在Launcher重启后瘫痪,即我使用Launcher Pro,有时会调整设置并且必须重新启动它.之后他们根本不工作.

这里是我onRecieve()onUpdate()方法:

   public void onReceive(Context context, Intent intent)
{
    super.onReceive(context, intent);
    String action = intent.getAction();
    if(action.equals("android.tristan.widget.digiclock.CLICK"))
    {
        PackageManager packageManager = context.getPackageManager();
        Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);

        String clockImpls[][] = {
                {"HTC Alarm Clock", "com.htc.android.worldclock", "com.htc.android.worldclock.AlarmClock" },
                {"Standar Alarm Clock", "com.android.deskclock", "com.android.deskclock.AlarmClock"},
                {"Froyo Nexus Alarm Clock", "com.google.android.deskclock", "com.android.deskclock.DeskClock"},
                {"Moto Blur Alarm Clock", "com.motorola.blur.alarmclock",  "com.motorola.blur.alarmclock.AlarmClock"}
        };

        boolean foundClockImpl = false;

        for(int i=0; i<clockImpls.length; i++) {
            String vendor = clockImpls[i][0];
            String packageName = clockImpls[i][1];
            String className = clockImpls[i][2]; …
Run Code Online (Sandbox Code Playgroud)

android onclick android-intent android-pendingintent android-appwidget

5
推荐指数
1
解决办法
2692
查看次数