start activity class before widget provider - android

I make a widget. I want to start with a widget for the first time start up
activity (gallery) which can be used select theme widget. And after selecting disappeared, and appeared widget as the widget HTC clock or HTC calendar. Does anyone know how to do this?
Thank

update your onUpdate method of AppWidgetProvider:
#Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
for (int appWidgetId : appWidgetIds) {
appid = appWidgetIds;
rview = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
Intent launchAppIntent = new Intent(context,Activityselecttheme.class);
launchAppIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
appWidgetId);
PendingIntent pendingActivity = PendingIntent.getActivity(context,
0, launchAppIntent, 0);
rview.setOnClickPendingIntent(R.id.widget, pendingActivity);
appWidgetManager.updateAppWidget(appWidgetId, rview);
}
}

Related

partiallyUpdateAppWidget on RemoteViews not working

In the RemoteViews for an AppWidget I have an AdapterViewFlipper which is supposed to flip when the user clicks a button in the AppWidget. According to the official documentation this should be done by calling the showNext on the RemoteViews. The AppWdiget should then be updated with partiallyUpdateAppWidget which even has the showNext() function as an example in the documentation. I've tried implementing this and I'm most likely making some silly mistake that I can't seem to figure out.
public class WidgetProvider extends AppWidgetProvider {
public static final String NEXT = "next";
#Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for (int appWidgetId : appWidgetIds) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
Intent nextIntent = new Intent(context, WidgetProvider.class);
nextIntent.setAction(NEXT);
views.setOnClickPendingIntent(R.id.next_button,
PendingIntent.getBroadcast(context, appWidgetId, nextIntent,
PendingIntent.FLAG_UPDATE_CURRENT));
views.setRemoteAdapter(R.id.view_flipper, new Intent(context,
WidgetRemoteViewService.class));
appWidgetManager.updateAppWidget(appWidgetId, views);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
#Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(NEXT)) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
remoteViews.showNext(R.id.view_flipper);
AppWidgetManager.getInstance(context).partiallyUpdateAppWidget(
AppWidgetManager.getInstance(context).getAppWidgetIds(
new ComponentName(context, WidgetProvider.class)),
remoteViews);
}
super.onReceive(context, intent);
}
}
When replacing partiallyUpdateAppWidget with updateAppWidget the next button is working until the orientation changes or the phone goes to sleep which forces a redraw of the last stored RemoteViews. This leads me to believe the mistake I'm making has to do with partial update but I can't figure out what I'm doing wrong.
In which API level are you testing?
Maybe the problem with withpartiallyUpdateAppWidget is related to this open issue issuetracker.google.com/issues/37136552

Changing Widget Image by OnClick (or PendingIntent ?)

I would like my Appwidget in addition to the main function nor (Widget)images changed.
When calling the function PendingIntent pendingIntent = PendingIntent.getActivity(context, 1001, new Intent(context, Counter.class), 0); should also change the widget to the new image.
Then, when the requested activity exits, the widget will switch to the old image. The Counter.class itself has no layout - so I can still see the homescreen with the widget when activity is running. Why would that the widget displays through changing the picture that the activity is running or rather not.
But I have no idea how to do it.
My WidgetProvider code:
#Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
for (int i = appWidgetIds.length; --i >= 0;) {
int appWidgetId = appWidgetIds[i];
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, Counter.class), 0);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.count_widget);
remoteViews.setOnClickPendingIntent(R.id.countWidget, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}
}
P.S. Sorry for my English :)

Clicking on a widget

HI i am having right trouble handling a click on a widget! I have got it so I can print a message to logcat when it is clicked on but I cant say change the text of a textview or show a button.
My main goal is to get a button to become visible when clicking on the widget and from here open a settings menu or share options for social media.
Here is my On Update code (DaysTillWidget.class)
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
for (int appWidgetId : appWidgetIds) {
setAlarm(context, appWidgetId, UPDATE_RATE);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
Intent clickIntent = new Intent(context, DaysTillWidget.class);
clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, appWidgetId, clickIntent, 0);
views.setOnClickPendingIntent(R.id.imageView2, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
}
and here is the onRecieve code in the same Class
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction()==null) {
Bundle extras = intent.getExtras();
if(extras!=null) {
int widgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
// do something for the widget that has appWidgetId = widgetId
System.out.println("is this it?" + widgetId);
RemoteViews RemoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
}
}
else {
super.onReceive(context, intent);
}
}
Any ideas on how I can get to my main goal?! I have spent hours reading peoples posts with similar problems but just cant get anything to work!
Im not sure if my project setup it correct or not but so far I have got everything else working? I have a service Class and a config class.
If I cant get the button to show and hide I would like to relaunch the config activity with the sharedprefernces for that widgetId
If you need to see any more code please let me know
Thanks in advance

Android: Making a phone call from home screen widget

I have a widget and I want it to make a phonecall to a particular number when the user clicks on the widget. How do i do this? Please help.
I was able to get it working with this code:
#Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Log.d(LOG_TAG, "onUpdate(): ");
for (int appWidgetId : appWidgetIds) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+number));
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, callIntent, 0);
// Get the layout for the App Widget and attach an on-click listener to the button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.caller);
views.setOnClickPendingIntent(R.id.callButton, pendingIntent);
// Tell the AppWidgetManager to perform an update on the current App Widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
public static Intent newPhoneCallIntent(String phoneNumber){
Intent callintent = new Intent(Intent.ACTION_DIAL);
callintent.setData(Uri.parse("tel:"+phoneNumber));
return callintent;
}
startActivity(newPhoneCallIntent("5555555555"));

Widget Not showing up after phone restart

I created a widget that works great until I restart the phone, then the widget doesn't display it is invisible but if i hold and click i can throw it in the garbage
I have a function that is called from my configure activity in my widgetprovider that does the following:
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId, int version)
{
if(savedType == -1)
savedType = version;
// android.os.Debug.waitForDebugger();
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
Intent configIntent = new Intent(context, Configure.class);
configIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Uri data = Uri.withAppendedPath(
Uri.parse(appWidgetId + "://widget/id/")
,String.valueOf(appWidgetId));
configIntent.setData(data);
PendingIntent pendingIntent = PendingIntent.getActivity
(context, 0, configIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.MainImage,pendingIntent);
views.setImageViewResource(R.id.MainImage, lv_images[version]);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
I had my onUpdate not doing anything because there is never anything to update but thinking this would be called after a phone restart i copied the code i had in the function
for(int i = 0; i < appWidgetIds.length; ++i)
{
updateAppWidget(context, appWidgetManager, appWidgetIds[i], savedType);
}
but this didn't seem to do much either.... suggestions?
When phone restart, it will call onEnable instead of onUpdate.
--update--
int[] allids = AppWidgetManager
.getInstance(Context)
.getAppWidgetIds(new ComponentName(Context, YourAppWidgetProvider.class);
This will get all ids that is under the control of YourAppWigetProvider. Read more on this

Categories

Resources