Skip to content

Commit

Permalink
Fix crash when adding some widget
Browse files Browse the repository at this point in the history
  • Loading branch information
krasanen committed Jan 25, 2024
1 parent 18ccee6 commit af9973a
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions app/src/main/java/fr/neamar/kiss/forwarder/Widget.java
Original file line number Diff line number Diff line change
Expand Up @@ -512,16 +512,22 @@ private boolean canAddWidget() {
* @param data Intent holding widget id to add
*/
private void addAppWidget(Intent data) {
int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
if (BuildConfig.DEBUG) Log.i(TAG, "addAppWidget: appWidgetId" + appWidgetId);
//add widget
WidgetPreferences wp = addWidgetToLauncher(appWidgetId);
try {
int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
if (BuildConfig.DEBUG) Log.i(TAG, "addAppWidget: appWidgetId" + appWidgetId);
//add widget
WidgetPreferences wp = addWidgetToLauncher(appWidgetId);

// Save widget in preferences
// Save widget in preferences

SharedPreferences.Editor widgetPrefsEditor = widgetPrefs.edit();
widgetPrefsEditor.putString(String.valueOf(appWidgetId), WidgetPreferences.serialize(wp));
widgetPrefsEditor.apply();
SharedPreferences.Editor widgetPrefsEditor = widgetPrefs.edit();
widgetPrefsEditor.putString(String.valueOf(appWidgetId), WidgetPreferences.serialize(wp));
widgetPrefsEditor.apply();
}
catch (Exception e){
Toast.makeText(mainActivity, "Failed to add widget", Toast.LENGTH_SHORT).show();
Log.e(TAG, e.getMessage());
}
}

/**
Expand Down

0 comments on commit af9973a

Please sign in to comment.