0

I have installed Spotify app in my android phone. Below code was not able to launch or open Spotify app programmatically. Please help.

Android Intent:
PackageName: com.spotify.music
ActionName: android.intent.action.VIEW


  val intent = Intent(Intent.action.VIEW) 

  intent.setPackage("com.spotify.music")

if (intent.resolveActivity(packageManager) == null) {
            Toast.makeText(this,"Please install Spotify App first.",Toast.LENGTH_SHORT).show()
            return
        }


  startActivity(intent)
MilkBottle
  • 4,242
  • 13
  • 64
  • 146

1 Answers1

0

To open any application using the package name, you can follow this: https://stackoverflow.com/a/7574735/4566483.

For Spotify:

val launchIntent = packageManager.getLaunchIntentForPackage("com.spotify.music")
if (launchIntent != null) { 
    startActivity(launchIntent)
}
Pedrox
  • 26
  • 3
  • Hi, your code is in Java. After converting it to Kotlin, it wont run. Can you provide Kotlin code ,please. Thanks – MilkBottle Jan 26 '22 at 06:50
  • Of course! I've edited with example with Kotlin. – Pedrox Jan 26 '22 at 07:10
  • Hi, silly me, I think your code and my code should work. I thought I had installed spotify in Android but I didnot so I got error . I installed it in iphone. Anyway, thanks your code works fine. Thanks – MilkBottle Jan 26 '22 at 07:43