diff options
author | David Luhmer <david-dev@live.de> | 2021-11-23 11:47:32 +0300 |
---|---|---|
committer | David Luhmer <david-dev@live.de> | 2021-11-23 11:47:32 +0300 |
commit | df3522cbd18f8bbcbd6ebe0d333ea945c8084d71 (patch) | |
tree | d53dbea9f6ecab668eed92aaeaed89b22d6953da /News-Android-App/src/main/java | |
parent | 090999ed7b5fcc39e4895d6f36f5c71761a0ab7e (diff) |
fix crash of widget on android 12
Diffstat (limited to 'News-Android-App/src/main/java')
3 files changed, 25 insertions, 11 deletions
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java index 9357ae86..089ceb7b 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java @@ -159,15 +159,22 @@ public class NewsDetailActivity extends PodcastFragmentActivity { //If the Activity gets started from the Widget, read the item id and get the selected index in the cursor. if (intent.hasExtra(WidgetProvider.RSS_ITEM_ID)) { + boolean foundArticle = false; long rss_item_id = intent.getExtras().getLong(WidgetProvider.RSS_ITEM_ID); for (RssItem rssItem : rssItems) { if (rss_item_id == rssItem.getId()) { getSupportActionBar().setTitle(rssItem.getTitle()); + foundArticle = true; break; } else { item_id++; } } + // if article can't be found for whatever reason just use index 0 and prevent app from crashing + if(!foundArticle) { + item_id = 0; + Log.e(TAG, "RSS Item with ID " + rss_item_id + " cannot be found"); + } } // Create the adapter that will return a fragment for each of the three diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetNewsViewsFactory.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetNewsViewsFactory.java index e67d6a9f..38a1e564 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetNewsViewsFactory.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetNewsViewsFactory.java @@ -26,6 +26,7 @@ import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.Intent; import android.graphics.Typeface; +import android.os.Bundle; import android.text.Html; import android.text.SpannableStringBuilder; import android.text.style.StyleSpan; @@ -135,26 +136,26 @@ public class WidgetNewsViewsFactory implements RemoteViewsService.RemoteViewsFac */ + Bundle mBundle = new Bundle(); + mBundle.putLong(WidgetProvider.RSS_ITEM_ID, id); + + //Get a fresh new intent Intent rowIntent = new Intent(); - //Load it with whatever extra you want - rowIntent.putExtra(WidgetProvider.RSS_ITEM_ID, id); + rowIntent.putExtras(mBundle); //Set it on the list remote view rv.setOnClickFillInIntent(R.id.widget_row_layout, rowIntent); - //Get a fresh new intent Intent ei = new Intent(); - //Load it with whatever extra you want - ei.putExtra(WidgetProvider.RSS_ITEM_ID, id); + ei.putExtras(mBundle); //Set it on the list remote view rv.setOnClickFillInIntent(R.id.cb_lv_item_read_wrapper, ei); //Get a fresh new intent Intent iCheck = new Intent(); - //Load it with whatever extra you want - iCheck.putExtra(WidgetProvider.RSS_ITEM_ID, id); iCheck.putExtra(WidgetProvider.ACTION_CHECKED_CLICK, true); + iCheck.putExtras(mBundle); rv.setOnClickFillInIntent(R.id.cb_lv_item_read, iCheck); } catch(Exception ex) { Log.e(TAG, "Error while getting view for widget at position: " + position, ex); diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetProvider.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetProvider.java index 57361381..4dc3beae 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetProvider.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetProvider.java @@ -29,6 +29,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; +import android.os.Bundle; import android.util.Log; import android.widget.RemoteViews; @@ -111,8 +112,14 @@ public class WidgetProvider extends AppWidgetProvider { } */ else if (action.equals(ACTION_LIST_CLICK)) { try { - long rssItemId = intent.getExtras().getLong(RSS_ITEM_ID); + Bundle bundle = intent.getExtras(); + if (bundle != null) { + for (String key : bundle.keySet()) { + Log.e(TAG, key + ": " + (bundle.get(key) != null ? bundle.get(key) : "NULL")); + } + } + long rssItemId = intent.getExtras().getLong(RSS_ITEM_ID, -1); if (intent.hasExtra(ACTION_CHECKED_CLICK)) { DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(context); @@ -120,7 +127,6 @@ public class WidgetProvider extends AppWidgetProvider { rssItem.setRead_temp(!rssItem.getRead_temp()); //rssItem.setRead_temp(true); - AppWidgetManager.getInstance(context) .notifyAppWidgetViewDataChanged(anAppWidgetId, R.id.list_view); @@ -208,13 +214,13 @@ public class WidgetProvider extends AppWidgetProvider { final PendingIntent onListClickPendingIntent = PendingIntent.getBroadcast(context, 0, onListClickIntent, - PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT); rv.setPendingIntentTemplate(R.id.list_view, onListClickPendingIntent); /* Intent intentWidget = new Intent(context, WidgetProvider.class); - PendingIntent pendingWidgetIntent = PendingIntent.getBroadcast(context, 0, intentWidget, PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent pendingWidgetIntent = PendingIntent.getBroadcast(context, 0, intentWidget, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT); rv.setOnClickPendingIntent(R.id.cb_lv_item_read_wrapper, pendingWidgetIntent); */ |