javaandroidandroid-intentopenurltiktok

How to open specific tiktok video link in Android?


I basically want my button to open tiktok video link (link should be opened by tiktok app, not default browser or webview) on click. How to program that button in Android Studio?


Solution

  • maybe a late answer, but what you can do for not only TikTok, but any other app you want to open it from your Android application is to use the package name of it and open it using intent normally, example code to open Instagram for example.

    url = "https://instagram.com/p/imagecode"
    Uri uri = Uri.parse(url);
    Intent likeIng = new Intent(Intent.ACTION_VIEW, URI);
    likeIng.setPackage("com.instagram.android"); // -> here is the part 
    try {
         startActivity(likeIng);
     } catch (ActivityNotFoundException e) {
        //catch the Error if the app not installed.
     }
    

    you can get the package name from Google play URL itself it contains the package name, for TikTok, the package name is com.ss.android.ugc.trill so you can use it to open it using the above code, I did not test it with TikTok, but it's tested with Instagram, so I think the same logic applies.