Skip to content

Commit

Permalink
fix: avoid crash if intent sent with no extras
Browse files Browse the repository at this point in the history
(cherry picked from commit 034b389)
  • Loading branch information
mikehardy committed Nov 23, 2024
1 parent ede66ff commit 09640e6
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions AnkiDroid/src/main/java/com/ichi2/anki/IntentHandler2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,22 @@ import timber.log.Timber
class IntentHandler2 : AbstractIntentHandler() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Timber.v(intent.toString())
if (NoteEditor.intentLaunchedWithImage(intent)) {
Timber.i("Intent contained an image")
intent.putExtra(NoteEditor.EXTRA_CALLER, NoteEditor.CALLER_ADD_IMAGE)
}
val noteEditorIntent = NoteEditorLauncher.PassArguments(intent.extras!!).getIntent(this, intent.action)
noteEditorIntent.setDataAndType(intent.data, intent.type)
startActivity(noteEditorIntent)
finish()
if (intent.extras == null) {
Timber.w("Intent unexpectedly has no extras. Notifying user, defaulting to add note.")
showThemedToast(this, getString(R.string.something_wrong), false)
startActivity(NoteEditorLauncher.AddNote().getIntent(this))
finish()
} else {
val noteEditorIntent =
NoteEditorLauncher.PassArguments(intent.extras!!).getIntent(this, intent.action)
noteEditorIntent.setDataAndType(intent.data, intent.type)
startActivity(noteEditorIntent)
finish()
}
}
}

0 comments on commit 09640e6

Please sign in to comment.