Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Front card template android-app:// links not working in Preview screen since 2.18.0 #16405

Closed
3 of 5 tasks
hanpingchinese opened this issue May 15, 2024 · 8 comments · Fixed by #16409
Closed
3 of 5 tasks
Labels
2.18 Bug Help Wanted Requesting Pull Requests from volunteers Priority-High

Comments

@hanpingchinese
Copy link
Contributor

Checked for duplicates?

  • This issue is not a duplicate

Does it also happen in the desktop version?

  • This bug does not occur in the latest version of Anki

What are the steps to reproduce this bug?

  1. Install Hanping Chinese Dictionary Pro (I can send you a promo code, since it's a paid app).
  2. Add Chinese Shared Deck "Hanping Chinese HSK (1-6)" to AnkiDroid 2.18.0
  3. Tap on the "Hanping Chinese HSK" deck and tap play button - should hear the Chinese voice audio.
  4. Tap "Show Answer" and tap on the pinyin ("wei2 bei4") - should hear the Chinese voice audio.
  5. Tap Edit Note (overflow menu)
  6. Tap Preview icon
  7. Tap play button - should hear the Chinese voice audio but instead taken to Play Store app (to install Hanping Pro)
  8. Go back to Anki and tap "show answer" - should hear the Chinese voice audio

Expected behaviour

See above.

Actual behaviour

See above.

Debug info

AnkiDroid Version = 2.18.0 (464cf290cc77c3f2c562cb03b408b78a13be261b)

Backend Version = 0.1.38-anki24.04.1 (24.04.1 ccd9ca1a8309b80bcb50ddc5d99c7ce63440bce9)

Android Version = 14 (SDK 34)

ProductFlavor = play

Manufacturer = Google

Model = Pixel 7a

Hardware = lynx

Webview User Agent = Mozilla/5.0 (Linux; Android 14; Pixel 7a Build/AP1A.240405.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/124.0.6367.179 Mobile Safari/537.36

ACRA UUID = 32257909-1377-4d9a-9bbc-37d02f46eef1

FSRS Enabled = false

Crash Reports Enabled = true

(Optional) Anything else you want to share?

So there is something broken about question template in preview mode only.

Example link href:

android-app://com.embermitre.hanping.app.pro#Intent;action=com.hanpingchinese.cmn.intent.action.PLAY;S.p={{text:Pinyin}};S.s={{text:Simplified}};S.t={{text:Traditional}};S.LANG=cmn;S._SOURCE=anki;end

Note: you can actually test this with the free app Hanping Lite (instead of Hanping Pro). Just need to change the template links from .pro to .lite (i.e. android-app://com.embermitre.hanping.app.lite)

Research

  • I am reporting a bug specific to AnkiDroid (Android app)
  • I have checked the manual and the FAQ and could not find a solution to my issue
  • (Optional) I have confirmed the issue is not resolved in the latest alpha release (instructions)
@hanpingchinese
Copy link
Contributor Author

anki-bug-16405.mp4

@david-allison
Copy link
Member

@BrayanDSO

Relevant:

var intent: Intent? = null
try {
if (url.startsWith("intent:")) {
intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME)
} else if (url.startsWith("android-app:")) {
intent = Intent.parseUri(url, Intent.URI_ANDROID_APP_SCHEME)
}
if (intent != null) {
if (packageManager.resolveActivityCompat(
intent,
ResolveInfoFlagsCompat.EMPTY
) == null
) {
val packageName = intent.getPackage()
if (packageName == null) {
Timber.d(
"Not using resolved intent uri because not available: %s",
intent
)
intent = null
} else {
Timber.d(
"Resolving intent uri to market uri because not available: %s",
intent
)
intent = Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=$packageName")
)
if (packageManager.resolveActivityCompat(
intent,
ResolveInfoFlagsCompat.EMPTY
) == null
) {
intent = null
}
}
} else {
// https://developer.chrome.com/multidevice/android/intents says that we should remove this
intent.addCategory(Intent.CATEGORY_BROWSABLE)
}
}
} catch (t: Throwable) {
Timber.w("Unable to parse intent uri: %s because: %s", url, t.message)
}
if (intent == null) {
Timber.d("Opening external link \"%s\" with an Intent", url)
intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
} else {
Timber.d("Opening resolved external link \"%s\" with an Intent: %s", url, intent)
}
try {
startActivity(intent)
} catch (e: ActivityNotFoundException) {
Timber.w(e) // Don't crash if the intent is not handled
}

@BrayanDSO
Copy link
Member

BrayanDSO commented May 15, 2024

Why hanping doesn't use standard Android deep links? We are not in 2016 anymore. You can tell your app to accept android-app:// links without depending on AnkiDroid or any other app.

I don't see why such a scheme should be handled in AnkiDroid's end.

@hanpingchinese
Copy link
Contributor Author

hanpingchinese commented May 16, 2024

There are still legacy APKs out there that rely on android-app:// so regardless of how things should be done now, it's still worth supporting IMO.

Also it's worth noting that the android-app scheme has not been deprecated.

Should the scheme be handled in AnkiDroid's end? Yes, for the reason that it has done so historically and AnkiDroid has always been strong at supporting legacy decks.

Side note: one main reason of using android-app scheme is the ability to target a specific app. Furthermore, the app has multiple flavors some of which would potentially share the same deep links. I know it's possible to work around all this, but things get messy quickly.

Regardless, I hope the legacy factor mentioned above should be enough for this to be treated as a bug worth fixing.

@david-allison
Copy link
Member

This is a regression and we'll handle it

This wasn't a planned deprecation of functionality. We shouldn't break downstream decks (with the exception of necessary re-aligning with upstream Anki changes/functionality)

@hanpingchinese I'm a little stretched for time, please follow up if you don't see a PR by Sunday

@hanpingchinese
Copy link
Contributor Author

Just one more point. If an app handles the android-app scheme, then you end up with an Intent chooser because Google app also supports that scheme.

@BrayanDSO
Copy link
Member

that it has done so historically and AnkiDroid has always been strong at supporting legacy decks.

I don't think that sticking to the past per se is a reason for keeping features. Otherwise, Chess notation should be restored and the legacy TTS should be undeprecated, since they break a lot of decks and the workarounds are way harder than adding a simple deeplink, and need to be done by the users, not us.

But, the feature is nice because of X and Y, so it should be kept is a valid reason and I'm fine with it.

I still recommend deeplinks as a failproof measure instead of depending on AnkiDroid to avoid situations like this one.

@BrayanDSO BrayanDSO added the Help Wanted Requesting Pull Requests from volunteers label May 16, 2024
@MorenoTropical
Copy link
Contributor

Leave it to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.18 Bug Help Wanted Requesting Pull Requests from volunteers Priority-High
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants