Skip to content

Commit

Permalink
trigger widget update upon launch
Browse files Browse the repository at this point in the history
  • Loading branch information
VishnuSanal committed Nov 18, 2023
1 parent f55af77 commit 89d1b37
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import phone.vishnu.quotes.R;
import phone.vishnu.quotes.fragment.TourFragment;
import phone.vishnu.quotes.helper.SharedPreferenceHelper;
import phone.vishnu.quotes.receiver.QuoteWidget;

public class SplashActivity extends AppCompatActivity {

Expand All @@ -52,6 +53,8 @@ protected void onCreate(Bundle savedInstanceState) {
if (!sharedPreferenceHelper.isFirstRun() && sharedPreferenceHelper.isNewFirstRun())
sharedPreferenceHelper.resetSharedPreferences();

QuoteWidget.updateWidget(this);

if (sharedPreferenceHelper.isNewFirstRun() || sharedPreferenceHelper.isFirstRun())
showNewTour();
else initTasks();
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/phone/vishnu/quotes/receiver/QuoteWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,20 @@ private void widgetShareButtonClicked(Context context) {
.setAction(Constants.WIDGET_SHARE_ACTION)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}

public static void updateWidget(Context context) {
try {
PendingIntent.getBroadcast(
context,
0,
new Intent(context, QuoteWidget.class)
.setAction(Constants.WIDGET_UPDATE_ACTION),
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
? PendingIntent.FLAG_IMMUTABLE
: PendingIntent.FLAG_UPDATE_CURRENT)
.send();
} catch (PendingIntent.CanceledException e) {
e.printStackTrace();
}
}
}

0 comments on commit 89d1b37

Please sign in to comment.