Search code examples
androidandroid-intentgoogle-classroomandroid-deep-link

How to open Google Classroom Specific Course from another app in Android


Can I open Google Classroom app for a specific course from my app?

In iOS, e.g. for a Web URL https://classroom.google.com/c/BlahBlahBlah, SwiftUI Link() opens the course in Google Classroom app if installed, otherwise, opened in a web browser since https://classroom.google.com/ has apple-app-site-association, i.e. https://classroom.google.com/apple-app-site-association

How can I do the same scenario in Android (Jetpack Compose)?

First, I tried:

val uriHandler = LocalUriHandler.current
uriHandler.openUri("https://classroom.google.com/c/BlahBlahBlah")

But it opens a web browser whether the Google Classroom app is installed or not.

So, I tried following how to open google classroom in your android app programatically

val ctx: Context = LocalContext.current
val pkgMgr: PackageManager = ctx.packageManager

val pkgName: String = "com.google.android.apps.classroom"

// Check if installed
try {
   pkgMgr.getPackageInfo(pkgName, 0)
} catch (...) { ... }

val launchIntent = pkgMgr.getLaunchIntentForPackage(pkgName)
ctx.startActivity(launchIntent)

Now it opens Google Classroom if installed, but it doesn't navigate to the corresponding course.

How can I achieve this?

I did some hopeless random tries like

launchIntent?.putExtra("id", "BlahBlahBlah") 

or

launchIntent?.data = Uri.parse("https://classroom.google.com/c/BlahBlahBlah")

but no luck.

I also tried to find a way to build a deeplink to open a specific course in Google Classroom app, but no idea.

Any advice will be appreciated even if the scenario is slightly different.

Thanks.


Solution

  • The app should launch with what you have. Utilizing android app links is supposed to be simple.

    val myIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://classroom.google.com/c/BlahBlahBlah"))
    myIntent.setPackage("com.google.android.apps.classroom")
    startActivity(myIntent)
    

    Manually setting the package for the intent solves the issue with the app link not automatically routing to the correct app. This seems to be just an issue with Google Classroom, not Android or the intent.