Widget setOnClickPendingIntent not working

by Kasra Rahjerdi » Mon, 08 Mar 2010 12:20:20 GMT


Sponsored Links
 Hello,
I have a simple widget and I'm trying to pop up another activity when
it's clicked. My widget is not focusable or clickable even though in
the XML layout I explicity set it to be and when my widget is clicked
nothing happens.

My manifest has:
<receiver android:name=".WidgetConfigurator" android:label="@string/
app_name">
            <intent-filter>
                <action
android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
            <meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget" />
        </receiver>

My layout is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=" http://schemas.android.com/apk/res/ 
android"
    android:id="@+id/widgetlayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/widget_background"
    android:paddingLeft="19dip"
    android:paddingTop="21dip"
    android:clickable="true"
    android:focusable="true" >

        <TextView android:id="@+id/widgettext"
            android:text="Click here to set the text."
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_alignParentLeft="true"
            android:maxWidth="284dip"
            android:maxHeight="58dip"
            android:textSize="12dip"
            android:textColor="@android:color/black"
            />

</RelativeLayout>

And my AppWidgetProvider's onUpdate code contains:
        @Override
        public void onUpdate(Context ctx, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
                if(man == null)
                        onEnabled(ctx);

                Log.i(TAG, "Updating");
                RemoteViews updateViews = new RemoteViews(ctx.getPackageName(),
R.layout.widget);

                Random rand = new Random();
                for(int k = 0; k < appWidgetIds.length; k++) {
                int i = rand.nextInt(count);

                Intent intent = new Intent(ctx, WidgetClick.class);
                        PendingIntent pendingIntent = 
PendingIntent.getBroadcast(ctx, 0,
intent, 0);

                updateViews.setOnClickPendingIntent(R.id.widgetlayout,
pendingIntent);
                        updateViews.setTextViewText(R.id.widgettext,
storiesArray.get(i));

                        appWidgetManager.updateAppWidget(appWidgetIds, 
updateViews);
                }
        }


Everything in my onUpdate works perfectly other than the
setOnClickPendingIntent command. Am I doing something wrong?

--



Widget setOnClickPendingIntent not working

by String » Mon, 08 Mar 2010 19:07:48 GMT


 On Mar 8, 4:20am, Kasra Rahjerdi <johncena4presid...@gmail.com>




Try changing your PendingIntent.getBroadcast() call to a
getActivity(). If you're trying to start an activity, that would seem
to make more sense - and that's what works for my appwidgets.

String

--


Sponsored Links


Widget setOnClickPendingIntent not working

by Kasra Rahjerdi » Tue, 09 Mar 2010 02:22:00 GMT


 Good catch! Thank you. I've fixed this yet it has made no difference.
I can not even focus onto my widget and clicking it doesn't show any
highlight or anything either.





--



Widget setOnClickPendingIntent not working

by Kasra Rahjerdi » Thu, 11 Mar 2010 09:47:43 GMT


 I've made some progress. If I set my application up to do widget
updating in onRecieve everything works, similar code in the onUpdate
function does not.

--



Other Threads

1. Broken Nexus One given to me at Developer Lab..

If you still did not manage to get warranty from HTC, you can consider
selling it to me and buy a new Nexus one?





-- 

2. app2sd is working on nexDesire!

yes!

makasih semua.......

sekali lagi, makasih pisan....*terharu baru*

-- 
"Indonesian Android Community [id-android]" 

3. Memory leak in shared library - any way to find out

4. Say goodbye to blapk market

5. New Birthday Calendar

6. eBuddy, tanya

7. Fring