Skip to content
All gists
Back to GitHub
Sign in
Sign up
Sign in
Sign up
{{ message }}
Instantly share code, notes, and snippets.
agustinfece
/
SharedStorage.java
Secret
Created
Jun 24, 2021
Star
0
Fork
0
Star
Code
Revisions
1
Embed
What would you like to do?
Embed
Embed this gist in your website.
Share
Copy sharable link for this gist.
Clone via HTTPS
Clone with Git or checkout with SVN using the repository’s web address.
Learn more about clone URLs
Download ZIP
SharedStorage.java
Raw
SharedStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
package
com
.
widgetasap
;
import
com
.
facebook
.
react
.
bridge
.
NativeModule
;
import
com
.
facebook
.
react
.
bridge
.
ReactApplicationContext
;
import
com
.
facebook
.
react
.
bridge
.
ReactContext
;
import
com
.
facebook
.
react
.
bridge
.
ReactContextBaseJavaModule
;
import
com
.
facebook
.
react
.
bridge
.
ReactMethod
;
import
android
.
app
.
Activity
;
import
android
.
appwidget
.
AppWidgetManager
;
import
android
.
content
.
ComponentName
;
import
android
.
content
.
Context
;
import
android
.
content
.
Intent
;
import
android
.
content
.
SharedPreferences
;
import
android
.
util
.
Log
;
public
class
SharedStorage
extends
ReactContextBaseJavaModule
{
ReactApplicationContext
context
;
public
SharedStorage
(
ReactApplicationContext
reactContext
) {
super
(
reactContext
);
context
=
reactContext
;
}
@
Override
public
String
getName
() {
return
"SharedStorage"
;
}
@
ReactMethod
public
void
set
(
String
message
) {
SharedPreferences
.
Editor
editor
=
context
.
getSharedPreferences
(
"DATA"
,
Context
.
MODE_PRIVATE
).
edit
();
editor
.
putString
(
"appData"
,
message
);
editor
.
commit
();
Intent
intent
=
new
Intent
(
getCurrentActivity
().
getApplicationContext
(),
MyWidget
.
class
);
intent
.
setAction
(
AppWidgetManager
.
ACTION_APPWIDGET_UPDATE
);
int
[]
ids
=
AppWidgetManager
.
getInstance
(
getCurrentActivity
().
getApplicationContext
()).
getAppWidgetIds
(
new
ComponentName
(
getCurrentActivity
().
getApplicationContext
(),
MyWidget
.
class
));
intent
.
putExtra
(
AppWidgetManager
.
EXTRA_APPWIDGET_IDS
,
ids
);
getCurrentActivity
().
getApplicationContext
().
sendBroadcast
(
intent
);
}
}
Sign up for free
to join this conversation on GitHub
. Already have an account?
Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.