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

Allow JS to send Intent to other android app #17416

Open
Arthur-Milchior opened this issue Nov 11, 2024 · 4 comments
Open

Allow JS to send Intent to other android app #17416

Arthur-Milchior opened this issue Nov 11, 2024 · 4 comments

Comments

@Arthur-Milchior
Copy link
Member

What if... there was a javascript API to create and send an Intent? That is, allow javascript to do Android inter-app RPCs...

...and there was a metronome app that responded to Intents to "start metronome at NNN bpm" and "stop metronome"

There are a number of metronome apps on github and responding to an Intent to start/stop seems pretty easy?
Adding a javascript API to send an Intent seems pretty easy?

Now we've got two excellent features where they belong (IMHO) and we do not have a metronome feature mushrooming within AnkiDroid

?

Originally posted by @mikehardy in #17412

@mikehardy What is the second excellent feature?

@mikehardy
Copy link
Member

The intent handling on the other side, in the metronome app of course! The link I posted makes me think that's maybe already handled in one app at least...

@david-allison
Copy link
Member

I believe this already exists:

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)
}

@mikehardy
Copy link
Member

🤔 looks like a start but doesn't seem to allow extras (to send tempo) and does a start activity, I wonder if that would foreground the app etc which would be a review irritation. Not sure how to send an intent in the background though. Anyway, this is definitely going in the direction I was thinking, vs a metronome in ankidroid

@Arthur-Milchior
Copy link
Member Author

Oh. When you mentioned "two features" I thought you meant that there was the metronome, and another feature we may want to start through API that I didn't know of

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants