Merhaba arkadaşlar androidde widget yapmaya çalışıyorum widgetiekranda gösteriyorum herşey tamam ama Buttona tıklanma olaynı yakalıyamıyorum acaba sorun nerede?

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.Button; import android.widget.RemoteViews; import android.widget.Toast;

import java.util.Date;

public class new_widget extends AppWidgetProvider {

public static String WIDGET_BUTTON ="R.id.button2";
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                     int[] appWidgetIds) {
    // TODO Auto-generated method stub
    super.onUpdate(context, appWidgetManager, appWidgetIds);
    Log.d("Widget", "onUpdate çalıştı");

    Log.d("Widget", "onUpdate çalıştı");

        Log.d("Widget", "onUpdate çalıştı");

        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
        Intent intent2 = new Intent(WIDGET_BUTTON);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent2, PendingIntent.FLAG_UPDATE_CURRENT);
        views.setOnClickPendingIntent(R.id.button2, pendingIntent );

}
@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    super.onReceive(context, intent);

        Log.d("Widget", "onReceive çalıştı");
        if (WIDGET_BUTTON.equals(intent.getAction())) {
            Log.d("Widget", "Button clşck çalıştı");

        }

}

}

soruldu: 12 Tem '14, 03:43

binary's gravatar image

binary
256192531
cevap kabul oranı: 0%

(12 Tem '14, 05:35) ismailkocacan ismailkocacan's gravatar image

ordaki cevapta olmadı acaba nerede hata var

package com.example.Widget;

/* * Created by bekir on 11.07.2014. / import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.util.Log; import android.widget.Button; import android.widget.RemoteViews; import android.widget.Toast;

import java.util.Date;

public class new_widget extends AppWidgetProvider { public static String ACTION_WIDGET_RECEIVER = "R.id.button2";

public static int appid[];
public static RemoteViews rview;
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                     int[] appWidgetIds){
    updateWidgetState(context, "");
}
@Override
public void onReceive(Context paramContext, Intent paramIntent)
{
    Log.d("Bir tıklama yakalandı","onreceive");
    String str = paramIntent.getAction();
    if (paramIntent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
        updateWidgetState(paramContext, str);
    }
    else
    {
        if ("android.appwidget.action.APPWIDGET_DELETED".equals(str))
        {
            int i = paramIntent.getExtras().getInt("Widget", 0);
            if (i == 0)
            {

            }
            else
            {
                int[] arrayOfInt = new int[1];
                arrayOfInt[0] = i;
                onDeleted(paramContext, arrayOfInt);
            }
        }
        super.onReceive(paramContext, paramIntent);
    }
}
static void updateWidgetState(Context paramContext, String paramString)
{
    RemoteViews localRemoteViews = buildUpdate(paramContext, paramString);
    ComponentName localComponentName = new ComponentName(paramContext,new_widget.class);
    AppWidgetManager.getInstance(paramContext).updateAppWidget(localComponentName, localRemoteViews);
}
private static RemoteViews buildUpdate(Context paramContext, String paramString)
{
     Toast.makeText(paramContext, "buildUpdate() ::"+paramString, Toast.LENGTH_SHORT).show();
    rview = new RemoteViews(paramContext.getPackageName(), R.layout.main);
    Intent active = new Intent(paramContext, new_widget.class);
    active.setAction(ACTION_WIDGET_RECEIVER);
    active.putExtra("msg", "Message for Button 1");
    PendingIntent configPendingIntent = PendingIntent.getActivity(paramContext, 0, active, 0);

    rview.setOnClickPendingIntent(R.id.button2, configPendingIntent);
    if(paramString.equals(ACTION_WIDGET_RECEIVER))
    {
        //your code for update and what you want on button click

Log.d("Bir tıklama yakalandı","null"); } return rview; } @Override public void onEnabled(Context context){ super.onEnabled(context); Toast.makeText(context, "onEnabled() ", Toast.LENGTH_SHORT).show(); } // Called each time an instance of the App Widget is removed from the host @Override public void onDeleted(Context context, int [] appWidgetId){ super.onDeleted(context, appWidgetId); Toast.makeText(context, "onDeleted() ", Toast.LENGTH_SHORT).show(); } // Called when last instance of App Widget is deleted from the App Widget host. @Override public void onDisabled(Context context) { super.onDisabled(context); Toast.makeText(context, "onDisabled() ", Toast.LENGTH_SHORT).show(); }

}

permanent link

cevaplandı: 12 Tem '14, 06:47

binary's gravatar image

binary
256192531
cevap kabul oranı: 0%

Cevabınız
toggle preview

Bu soruyu takip et

E-Posta üzerinden:

Üyelik girişi yaptıktan sonra abonelik işlemlerini yapabilirsiniz

RSS üzerinden:

Cevaplar

Cevaplar ve Yorumlar

Yazı Formatlama

  • *italic* ya da _italic_
  • **bold** ya da __bold__
  • link:[text](http://url.com/ "başlık")
  • resim?![alt text](/path/img.jpg "başlık")
  • liste: 1. Foo 2. Bar
  • temel HTML etiketleri de kullanılabilir

Bu sorunun etiketleri:

×818
×4
×1

Soruldu: 12 Tem '14, 03:43

Görüntüleme: 567 kez

Son güncelleme: 12 Tem '14, 06:47

powered by BitNami OSQA