problem about appwidget-Collection of common programming errors


  • ManicBlowfish
    android resources android-widget appwidget
    I need to determine the screen density at runtime in an Android AppWidget. I’ve set up an HDPI emulator device (avd). If set up a regular executable project, and insert this code into the onCreate method:DisplayMetrics dm = getResources().getDisplayMetrics(); Log.d(“MyTag”, “screen density ” + dm.densityDpi);This outputs “screen density 240” as expected.However, if I set up an AppWidget project, and insert this code into the onUpdate method:DisplayMetrics dm = context.getResources().getDisplay

  • Jose_GD
    android appwidget viewstub
    I wonder whether it’s possible to inflate a ViewStub using a layout with unsupported views inside an Android appwidget (for example, an ScrollView or WebView).I know that only views with the @RemoteView annotation in its declaration are available to the RemoteViews mechanism, but this restriction remains when inflating layouts at runtime?

  • Karakuri

  • skaffman
    android appwidget
    In my app widget, I have a LinearLayout whose height and width are set to fill_parent. Is there a way to get at runtime, the actual size that has been allocated to this view?

  • rgrandy
    android android-widget screen-orientation appwidget
    I have code in an appwidget that I want to run when the phone’s orientation changes on the home screen, ie like when the keyboard flips out. I have an image that I want to change in an imageview in my appwidget. I can’t use different layouts linked to the orientation (ie “layout” and “layout-land”) because I don’t know the name of the image file until runtime, it is created at runtime. Is there anyway to trigger code to run only if the home screen is shown, my appwidget is active and the orienta

  • Frozen Spider
    java android resize appwidget
    I know that one cannot change the size of an app widget. But what to do if I need to? I know that there can be several receivers in AndroidManifest.xml, each with its own provider_info.xml, but users can switch between them only while adding widget on the homescreen. Is there any way to switch between different app widget providers at runtime?

  • Oliver
    android appwidget
    Dear all, I am trying to set the position of a TextView within an appwidget. Basically, the direct access to properties af the TextView works:myRemoteView.setTextColor(R.id.myTextView, Color.WHITE); //worksAlso indirectly, I can access the TextView properties:myRemoteView.setInt(R.id.myTextView, “setTextColor”, Color.BLUE); // worksAnd setting float values also works:myRemoteView.setFloat(R.id.myTextView, “setTextSize”, 25); // worksNow I’m trying to shift the x position of the TextView by 5 p

  • wufoo
    android service appwidget
    I have an android Activity extending AppWidgetProvider in which I’d like to keep a count of how many times onReceive() is called. The problem is, every once in a while there is an entry in Logcat saying “No longer want blah.foo.bar.baz” and shortly afterwards an entry saying “Scheduling restart of crashed service blah.foo.bar.baz”. Android kills and then restarts my process which causes all my variables to initialize to default values. Only way I can think of to maintain variable state is to wr

  • Santhosh_pulliman
    android appwidget backlight screen-brightness
    I have created a simple Appwidget to control the brightness of the screen by this code:android.provider.Settings.System.putInt(context.getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS, 50);When i click the widget, there is no change in the brightness of the backlight immediately. But when i lock and unlock the phone, it works. I read Changing screen brightness programmatically (as with the power widget) that using dummy activity will give the solution. So i created an act

  • Aakash
    java android appwidget
    What am I doing?I am updating an AppWidget using an IntentService. What is the problem?Everything works perfectly well except for some rare times probably every 12-15 hours or I might say random, the widget updates don’t happen. After debugging through the situation here is the logcat message which appears to be the problem.05-27 20:21:13.122: WARN/ActivityManager(97): Scheduling restart of crashed service com.myapp.android/.myAppWidget$UpdateService in 5000msBelow are some more logcat messages

  • Craigy
    android appwidget
    Hello(sorry about that) all, I’m working on a code that will allow me to enter a number in a settings screen for an app widget. That will then we saved and stored as a variable to be used in the main app for which the widget was made. I’m wondering how I can bundle the number chosen and transfer it over to the app/widget to be run.import android.app.Activity; import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.Inte

  • Holoceo
    android widget appwidget android-appwidget
    I’m making widget, that will be updated by Intent.ACTION_TIME_TICK. So I registered reciever (my AppWidgetProvider):private IntentFilter intentFilter = new IntentFilter(Intent.ACTION_TIME_TICK);@Overridepublic void onEnabled(Context context) {super.onEnabled(context);context.getApplicationContext().registerReceiver(this, intentFilter); }Everything works fine. But when i try to unregister reciever, app crashes:@Override public void onDisabled(Context context) { context.getApplicationContext()

  • aseq
    android appwidget
    In an appwidget I develop I have a problem that when I start a map activity in Android 2.1 and 1.5 it causes a crash. I only notriced this in 1.5 and 2.1, it may happen in 1.6 but I haven’t tested yet. The problem magically disappears if I let the app run for a while, say 30 minutes to an hour before touching it.I am pretty convinced this is not a bug in my app, but an Android bug. Is there a way to work around it?Stack trace:I/ActivityManager( 576): Starting activity: Intent { flags=0x10000000

  • aseq
    android appwidget
    I’m working on an android appwidget and it works fine in all android versions I tried (emulator 1.5, 1.6, 2.3), but not 2.1 (physical device, LG GT540 upgraded to 2.1). I tested it on a Samsung GT I5801 fresh out of the box with the 2.1 OS and it worked, probably because tat particular revision the 2.1 version is older (or else Samsung themselves added the fix).By the way, this I think is the fix to the exact bug I am referring to (looks like the link is broken as of 12-12-2012): http://android.

  • Wesley
    java android appwidget
    Hi I have an Activity 1 which needs to send data to Appwidget (widget) which has a text view.For sending data between activites i know that we can use intent.putExtra(“mydata”, dataString); and recive the same with String data = bundle.getString(“mydata”); But in my case i need to send data (String) to app Widget.When i use Bundle dataFromPrevious = getIntent().getExtras(); String newString = dataFromPrevious.getString(“mydata”);inside AppWidgetProvider it throws an error in getIntent saying get

  • Jakob
    java android android-widget appwidget
    I’m trying to pass a string value from a widget configuration class to appWidgetProvider class. I’ve read that you pass a string between classes like this:In current activity, create an intentIntent i = new Intent(getApplicationContext(), ActivityB.class); i.putExtra(key, value); startActivity(i);then in the other activity, retrieve those values.Bundle extras = getIntent().getExtras(); if(extras !=null) {String value = extras.getString(key); }(for the “key” I declared a string)but when writing

  • Martijn
    android appwidget
    i am trying to create a streaming media player widget. I am able to get it playing, but pushing stop gives (or gave) me a NullpointerException (but PAUSE and STOP do show up nicely in Logcat). So the Mediaplayer launches away and it is gone, with me unable to grab it back. It must be something small that i am doing wrong, but i just can’t get my finger behind it. Any idea?public class MyWidget extends AppWidgetProvider implements MediaPlayer.OnCompletionListener, MediaPlayer.OnPreparedListener,

Web site is in building