Issue
I'm making a widget for my WebView
app, and it's got a list of buttons on it. Currently, It's firing an intent whenever their pressed. In that intent, I'm putting some string extra's, but when the onNewIntent
receives the intent, the value for the extra is NULL
. So I'm stuck on receiving the actual string extra.
Here's the code on my list provider:
override fun getViewAt(positionIndexNum: Int): RemoteViews {
........
val extrasObj = Bundle()
extrasObj.putString("shortcutUrl", listViewUrlArr[positionIndexNum]) // I've tried hardcoding this part and it still returns null.
extrasObj.putString("shortcutJs", listViewJsArr[positionIndexNum])
extrasObj.putString("shortcutId", listViewIdArr[positionIndexNum])
val fillInIntentObj = Intent()
fillInIntentObj.putExtras(extrasObj)
viewObj.setOnClickFillInIntent(listViewItemId, fillInIntentObj)
return viewObj
}
Here's the code from the onNewIntent
function:
override fun onNewIntent(intentObj: Intent) {
super.onNewIntent(intentObj)
val bundle = intentObj.extras
if (bundle != null) {
for (key in bundle.keySet()) {
Log.e("TAG", key + " : " + if (bundle[key] != null) bundle[key] else "NULL")
}
}
.....
}
That outputs in the logcat:
shortcutUrl : NULL
shortcutId : NULL
shortcutJs : NULL
I've also tried: intentObj.getStringExtra("shortcutId")
which still returns NULL
EDIT:
I also have this PendingIntent
code in the updateAppWidget
function:
val clickIntent = Intent(contextObj, MainActivity::class.java)
val clickPI = PendingIntent.getActivity(contextObj, 0,
clickIntent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT);
viewsObj.setPendingIntentTemplate(R.id.widget_list, clickPI)
Solution
I finally found a fix for this, I'm not sure how it really works but I changed:
PendingIntent.FLAG_IMMUTABLE
to
PendingIntent.FLAG_MUTABLE
in the PendingIntent
. Hopefully this helps someone else!
Answered By - Amy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.