开发者

make android widget invisible when start activity

i have widget and when i click on it i'm starting new activity with transparent backround and i wanna hide that widget so only the activity is present on the homescreen or find a way to put the activity window on the top of the widget but i cant 开发者_高级运维use intent.getSourceBounds method cause i'm not using API level 7 or above


Try with the following code sample

if you have created Remote views using the following code

RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);

set visibility of the whole widget using following code

views.setViewVisibility(R.id.widget_counter, View.INVISIBLE);


I found the solution

     public class homeWidget extends AppWidgetProvider {
public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget";
 @Override
    public void onUpdate( Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds )
    {
        RemoteViews remoteViews;
        ComponentName watchWidget;

        Intent active = new Intent(context, homeWidget.class);
        active.setAction(ACTION_WIDGET_RECEIVER);
        PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);


        remoteViews = new RemoteViews( context.getPackageName(), R.layout.widget );
        watchWidget = new ComponentName( context, homeWidget.class );

        remoteViews.setOnClickPendingIntent(R.id.buttonWidget1, actionPendingIntent);



        appWidgetManager.updateAppWidget( watchWidget, remoteViews );
    }
 @Override
 public void onEnabled(Context context){
     AppWidgetManager mgr = AppWidgetManager.getInstance(context); 
     RemoteViews remoteViews;
        ComponentName watchWidget;

        Intent active = new Intent(context, homeWidget.class);
        active.setAction(ACTION_WIDGET_RECEIVER);
        PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);


        remoteViews = new RemoteViews( context.getPackageName(), R.layout.widget );
        watchWidget = new ComponentName( context, homeWidget.class );

        remoteViews.setOnClickPendingIntent(R.id.buttonWidget1, actionPendingIntent);

        mgr.updateAppWidget(watchWidget,remoteViews);

 }
 @Override
 public void onReceive(Context context, Intent intent) {
     AppWidgetManager mgr = AppWidgetManager.getInstance(context); 
     if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
         Log.i("proverka", "uleva");
         Intent intent1 = new Intent(context,widget_activity.class);
         PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent1, 0);
         RemoteViews remoteViews;
         remoteViews = new RemoteViews( context.getPackageName(), R.layout.widget );

         ComponentName watchWidget;
         watchWidget = new ComponentName( context, homeWidget.class );

         remoteViews.setViewVisibility(R.id.LinearLayout01, View.GONE);
         try {
            pendingIntent.send();
        } catch (CanceledException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }



         mgr.updateAppWidget(watchWidget,remoteViews);
         }
         super.onReceive(context, intent);
 }

 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜