Hi all,
I am trying to display an appwidget in my application.
There are two classes in my application.
First class broadcasts an intent to the send class.
The second class extends an AppWidgetProvider which is a
broadcastreceiver.
In the second class i am overriding the "onReceive" function.
In the "onReceive" function, i am trying to display the appwidget
using remoteviews.
Following is the code for the onReceive function that i have
implemented.
@Override
public void onReceive ( Context context,Intent intent ) {
super.onReceive( context,intent );
String action = intent.getAction();
String message="";
//String packagename="";
//int appwidgetid;
//String RESULT_OK = "sucessfull";
Log.i("test", "message received");
if( "android.appwidget.action.APPWIDGET_ENABLED".equals
( action ) ) {
Toast.makeText( context, "Broadcast sucessfull...",
Toast.LENGTH_LONG).show();
if ( intent.hasExtra(broadcast.MESSAGE)) {
message =
(String)intent.getCharSequenceExtra(broadcast.MESSAGE);
Toast.makeText( context, message,
Toast.LENGTH_LONG).show();
}
ComponentName component;
component = new ComponentName(context,receiver.class);
RemoteViews views = new
RemoteViews(context.getPackageName
(),R.layout.widget_provider);
views.setViewVisibility(R.layout.widget, 0);
views.setTextViewText(R.id.message, message);
}
}
}
The R.layout.widget_provider is the file which contains the
appwidgetprovider layout.
The R.layout.widget is the file which contains the layout inside the
appwidget.
The R.id.message is a textview inside the appwidget layout.
I am able to see the two toast messages.
But I am not able to see the appwidget being displayed.
My questions are:
1.Is it possible to display the appwidget inside an application?
2.If yes is this the correct way to do it?
Can anybody help me on this?
Thanks,
Anand
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en