How to pass a value from home screen widget to the application?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am working with an android project for which I want to create a widget. Using this widget I have to control some actions of the control (that is by pressing the stop button from widget the app should stop working of some action). For that I have to pass some value to app from the widget on a button click. So far I am able to do the following:
- open an activity on button click
- open an URL on button click
- make a toast on home screen on button click
Any help is appreciated,thank you.
java android android-studio widget android-widget
add a comment |
I am working with an android project for which I want to create a widget. Using this widget I have to control some actions of the control (that is by pressing the stop button from widget the app should stop working of some action). For that I have to pass some value to app from the widget on a button click. So far I am able to do the following:
- open an activity on button click
- open an URL on button click
- make a toast on home screen on button click
Any help is appreciated,thank you.
java android android-studio widget android-widget
add a comment |
I am working with an android project for which I want to create a widget. Using this widget I have to control some actions of the control (that is by pressing the stop button from widget the app should stop working of some action). For that I have to pass some value to app from the widget on a button click. So far I am able to do the following:
- open an activity on button click
- open an URL on button click
- make a toast on home screen on button click
Any help is appreciated,thank you.
java android android-studio widget android-widget
I am working with an android project for which I want to create a widget. Using this widget I have to control some actions of the control (that is by pressing the stop button from widget the app should stop working of some action). For that I have to pass some value to app from the widget on a button click. So far I am able to do the following:
- open an activity on button click
- open an URL on button click
- make a toast on home screen on button click
Any help is appreciated,thank you.
java android android-studio widget android-widget
java android android-studio widget android-widget
edited Nov 29 '18 at 6:50
Gayan Mettananda
1,110814
1,110814
asked Nov 29 '18 at 6:19
mohammed shefeeqmohammed shefeeq
36
36
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I'm not sure with this problem because I have not try widget yet.
When button click, send a boardcast message. And your app needs to run a service to receive the message. You can put your values in the message?
Wish this link may give you some ideas:
http://rxwen.blogspot.com/2012/10/communication-between-android-widget.html
There is a similar question:Android - Communications between a widget and its app
Good luck!
let me try this,thank you :)
– mohammed shefeeq
Nov 29 '18 at 7:10
add a comment |
I have successfully completed this part of my project.There are two scenarios
- When we are passing values the app will be launched. That is we are passing the values directly to an activity
- With out launching the app we can pass the values.Here we are using service
In both situation we can use two method
- Using
sharedpreferences
- Using
Intent(putExtra())
If you want pass the value directly to an activity(the App will be launched while passing the value) you can use second method above mentioned and call the activity(which activity you wanted to be launched) as follows:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget);
Intent intent = new Intent(context,MainActivity.class);
PendingIntent pendingIntent = PendingIntent(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.PunchIn, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
this code to launch MainActivity from widget button click. In Inten you can use putExtra() to pass values.better to not use sharedpreference here.
For passing value with out launchingthe app,you can call service from widget button then you can add whatever code you want to add in the service.class
file. you can call the service as follows:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget);
Intent intent = new Intent(context,MyService.class);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.PunchIn, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
from this service class you can pass values to the application using SharedPrefernce
or putExtra()
.
if you want to make a button widget which work same as button click of the app you can use second method. Here you can call a service on on button click as mentioned above, Then write code for the button click in the service class.
i am new to android,i worked with widget in my project for that researched a lot and it took lots of time. so thought about posting this which will help anyone like me. if you found any error/mistake please correct me.happy to correct my mistake.
Thank you
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53532942%2fhow-to-pass-a-value-from-home-screen-widget-to-the-application%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm not sure with this problem because I have not try widget yet.
When button click, send a boardcast message. And your app needs to run a service to receive the message. You can put your values in the message?
Wish this link may give you some ideas:
http://rxwen.blogspot.com/2012/10/communication-between-android-widget.html
There is a similar question:Android - Communications between a widget and its app
Good luck!
let me try this,thank you :)
– mohammed shefeeq
Nov 29 '18 at 7:10
add a comment |
I'm not sure with this problem because I have not try widget yet.
When button click, send a boardcast message. And your app needs to run a service to receive the message. You can put your values in the message?
Wish this link may give you some ideas:
http://rxwen.blogspot.com/2012/10/communication-between-android-widget.html
There is a similar question:Android - Communications between a widget and its app
Good luck!
let me try this,thank you :)
– mohammed shefeeq
Nov 29 '18 at 7:10
add a comment |
I'm not sure with this problem because I have not try widget yet.
When button click, send a boardcast message. And your app needs to run a service to receive the message. You can put your values in the message?
Wish this link may give you some ideas:
http://rxwen.blogspot.com/2012/10/communication-between-android-widget.html
There is a similar question:Android - Communications between a widget and its app
Good luck!
I'm not sure with this problem because I have not try widget yet.
When button click, send a boardcast message. And your app needs to run a service to receive the message. You can put your values in the message?
Wish this link may give you some ideas:
http://rxwen.blogspot.com/2012/10/communication-between-android-widget.html
There is a similar question:Android - Communications between a widget and its app
Good luck!
answered Nov 29 '18 at 7:08
David_JiangDavid_Jiang
133
133
let me try this,thank you :)
– mohammed shefeeq
Nov 29 '18 at 7:10
add a comment |
let me try this,thank you :)
– mohammed shefeeq
Nov 29 '18 at 7:10
let me try this,thank you :)
– mohammed shefeeq
Nov 29 '18 at 7:10
let me try this,thank you :)
– mohammed shefeeq
Nov 29 '18 at 7:10
add a comment |
I have successfully completed this part of my project.There are two scenarios
- When we are passing values the app will be launched. That is we are passing the values directly to an activity
- With out launching the app we can pass the values.Here we are using service
In both situation we can use two method
- Using
sharedpreferences
- Using
Intent(putExtra())
If you want pass the value directly to an activity(the App will be launched while passing the value) you can use second method above mentioned and call the activity(which activity you wanted to be launched) as follows:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget);
Intent intent = new Intent(context,MainActivity.class);
PendingIntent pendingIntent = PendingIntent(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.PunchIn, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
this code to launch MainActivity from widget button click. In Inten you can use putExtra() to pass values.better to not use sharedpreference here.
For passing value with out launchingthe app,you can call service from widget button then you can add whatever code you want to add in the service.class
file. you can call the service as follows:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget);
Intent intent = new Intent(context,MyService.class);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.PunchIn, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
from this service class you can pass values to the application using SharedPrefernce
or putExtra()
.
if you want to make a button widget which work same as button click of the app you can use second method. Here you can call a service on on button click as mentioned above, Then write code for the button click in the service class.
i am new to android,i worked with widget in my project for that researched a lot and it took lots of time. so thought about posting this which will help anyone like me. if you found any error/mistake please correct me.happy to correct my mistake.
Thank you
add a comment |
I have successfully completed this part of my project.There are two scenarios
- When we are passing values the app will be launched. That is we are passing the values directly to an activity
- With out launching the app we can pass the values.Here we are using service
In both situation we can use two method
- Using
sharedpreferences
- Using
Intent(putExtra())
If you want pass the value directly to an activity(the App will be launched while passing the value) you can use second method above mentioned and call the activity(which activity you wanted to be launched) as follows:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget);
Intent intent = new Intent(context,MainActivity.class);
PendingIntent pendingIntent = PendingIntent(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.PunchIn, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
this code to launch MainActivity from widget button click. In Inten you can use putExtra() to pass values.better to not use sharedpreference here.
For passing value with out launchingthe app,you can call service from widget button then you can add whatever code you want to add in the service.class
file. you can call the service as follows:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget);
Intent intent = new Intent(context,MyService.class);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.PunchIn, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
from this service class you can pass values to the application using SharedPrefernce
or putExtra()
.
if you want to make a button widget which work same as button click of the app you can use second method. Here you can call a service on on button click as mentioned above, Then write code for the button click in the service class.
i am new to android,i worked with widget in my project for that researched a lot and it took lots of time. so thought about posting this which will help anyone like me. if you found any error/mistake please correct me.happy to correct my mistake.
Thank you
add a comment |
I have successfully completed this part of my project.There are two scenarios
- When we are passing values the app will be launched. That is we are passing the values directly to an activity
- With out launching the app we can pass the values.Here we are using service
In both situation we can use two method
- Using
sharedpreferences
- Using
Intent(putExtra())
If you want pass the value directly to an activity(the App will be launched while passing the value) you can use second method above mentioned and call the activity(which activity you wanted to be launched) as follows:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget);
Intent intent = new Intent(context,MainActivity.class);
PendingIntent pendingIntent = PendingIntent(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.PunchIn, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
this code to launch MainActivity from widget button click. In Inten you can use putExtra() to pass values.better to not use sharedpreference here.
For passing value with out launchingthe app,you can call service from widget button then you can add whatever code you want to add in the service.class
file. you can call the service as follows:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget);
Intent intent = new Intent(context,MyService.class);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.PunchIn, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
from this service class you can pass values to the application using SharedPrefernce
or putExtra()
.
if you want to make a button widget which work same as button click of the app you can use second method. Here you can call a service on on button click as mentioned above, Then write code for the button click in the service class.
i am new to android,i worked with widget in my project for that researched a lot and it took lots of time. so thought about posting this which will help anyone like me. if you found any error/mistake please correct me.happy to correct my mistake.
Thank you
I have successfully completed this part of my project.There are two scenarios
- When we are passing values the app will be launched. That is we are passing the values directly to an activity
- With out launching the app we can pass the values.Here we are using service
In both situation we can use two method
- Using
sharedpreferences
- Using
Intent(putExtra())
If you want pass the value directly to an activity(the App will be launched while passing the value) you can use second method above mentioned and call the activity(which activity you wanted to be launched) as follows:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget);
Intent intent = new Intent(context,MainActivity.class);
PendingIntent pendingIntent = PendingIntent(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.PunchIn, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
this code to launch MainActivity from widget button click. In Inten you can use putExtra() to pass values.better to not use sharedpreference here.
For passing value with out launchingthe app,you can call service from widget button then you can add whatever code you want to add in the service.class
file. you can call the service as follows:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget);
Intent intent = new Intent(context,MyService.class);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.PunchIn, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
from this service class you can pass values to the application using SharedPrefernce
or putExtra()
.
if you want to make a button widget which work same as button click of the app you can use second method. Here you can call a service on on button click as mentioned above, Then write code for the button click in the service class.
i am new to android,i worked with widget in my project for that researched a lot and it took lots of time. so thought about posting this which will help anyone like me. if you found any error/mistake please correct me.happy to correct my mistake.
Thank you
answered Dec 11 '18 at 14:08
mohammed shefeeqmohammed shefeeq
36
36
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53532942%2fhow-to-pass-a-value-from-home-screen-widget-to-the-application%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown