How to open specific tiktok video link in Android? - java

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?

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.

Related

How to run another app from my own app? For example, I want to run Facebook when i click on a button in my app

I want to run another app from my own app, for example i want to run Facebook when i click on a button in my app.
please notice that i am new to android development
Use intent :
Intent open_app = getPackageManager().getLaunchIntentForPackage("PACKAGE_NAME_ANOTHER_APP"); // like facebook package(com.facebook.katana)
if (open_app != null) {
startActivity(open_app); // Please check package name is there or not because it can throw NullPointerException
}
if you want to recommend any app from playstore to user on click button
do this :
Uri uri = Uri.parse("https://play.google.com/store/apps/details?id=PACKAGE_NAME_OF_APP"); like facebook (com.facebook.katana)
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

Android open external IMDB application from my app

I have a button in my application which opens the imdb application in the phone with a imdb id I received from https://developers.themoviedb.org/3/getting-started/introduction
But I couldnt find anyway(using intents) to make my app recognize the imdb app and open it and if imdb app do not exist then I want to open the web site. How can I accomplish this?
I think I may be able to point you in the right direction. Just to be sure, you seem to be using TMDB but wish to open in the IMDB app?
The code below is from the Android documentation.
It will start your intent if the package manager can find an app with the appropriate intent filter installed on your device. If multiple apps are able to open this intent then an app chooser should pop up, unless the user has previously set a default for this kind of URI.
Intent sendIntent = new Intent(Intent.ACTION_SEND);
// Always use string resources for UI text.
// This says something like "Share this photo with"
String title = getResources().getString(R.string.chooser_title);
// Create intent to show the chooser dialog
Intent chooser = Intent.createChooser(sendIntent, title);
// Verify the original intent will resolve to at least one activity
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
If you add an else onto that then you can use a view intent like this :
Intent internetIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieUrl));
//Watch out here , There is a URI and Uri class!!!!
if (internetIntent.resolveActivity(getPackageManager()) != null){
startActivity(internetIntent);
}
I also found this (rather old) post about calling an explicit imdb uri
Imdb description
startActivity(android.intent.action.VIEW, imdb:///title/<titleID>);
// take note of the Uri scheme "imdb"
I hope this helps. If you post some more detail , code, links , I might be able to work through this with you.
If my answer is way off base then please be kind and set me right. We are all learning every day!
Good Luck.

Is there a way to open an URL in Private Window/Ingognito Window with Java?

I'm completely new in Java/Kotlin development (I try to learn both: basics and structure in Java, then I apply it to Kotlin).
I want to create an Android app in Android Studio 3.0 and I couldn't find an answer to my question.
Kotlin:
I have a button called button1.
button1.setOnClickListener {
web_page("http://google.com")
}
And this function:
fun web_page(url: String) {
val uri = Uri.parse(url)
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)
}
It works. But I want the link to open in an ingognito windows.
This link might be helpful to you
How to open a web page in Google chrome incognito from android app
" "Open new incognito tab" is currently limited to Chrome or first parties. "

Android: How to open an unknown file type

I am developing a file explorer app in android.
How to handle files with unknown extensions? When I try to open such kind of file, its throwing ActivityNotFound exception. But I want the system to pop up list of apps so that we can manually choose an application to open it.
Can anyone help me here?
I am starting activity to open the file by binding the file and its extension to the intent.
Intent intent = new Intent(Intent.ACTION_VIEW);
MimeTypeMap mime = MimeTypeMap.getSingleton();
String ext = file.getName().substring(file.getName().lastIndexOf(".") + 1);
String type = mime.getMimeTypeFromExtension(ext);
intent.setDataAndType(Uri.fromFile(new File(file.toString())), type);
try
{
startActivity(intent);
}
catch(Exception e){}
ActivityNotFound is thrown when no application is registered that can handle specific file type. This means that the list of apps you want to show will be empty.
The most appropriate way to deal with he situation is to catch ActivityNotFound exception and show a toast notifying the user there are no appropriate applications to open the file.
All android browsers proceed in this manner.
I will leave this link here, that targets the same problem and has a little more detail to it (second answer, read comments): Launching an Activity based on a file in android

Button to start the Gallery on Android

I'm trying to make a button in my App open the built in gallery.
public void onClick(View v) {
Intent intentBrowseFiles = new Intent(Intent.ACTION_VIEW);
intentBrowseFiles.setType("image/*");
intentBrowseFiles.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentBrowseFiles);
}
This results in an error message "The application Camera (process com.android.gallery) has stopped unexpectedly."
If I set the Intent action to ACTION_GET_CONTENT it manages to open the gallery but then simply returns the image to my app when a picture is selected which is not what I want.
I'm trying to make a button in my App open the built in browser.
Your question subject says "Gallery". Your first sentence in the question says "browser". These are not the same thing.
If I set the Intent action to ACTION_GET_CONTENT it manages to open the gallery but then simply returns the image to my app when a picture is selected which is not what I want.
Of course, actually telling us "what [you] want" would just be too useful, so you are making us guess.
I am going to go out on a limb and guess that you are trying to open the Gallery application just as a normal application. Note that there is no Gallery application in the Android OS. There may or may not be a Gallery application on any given device, and it may or may not be one from the Android open source project.
However, for devices that have the Android Market on them, they should support an ACTION_VIEW Intent with a MIME type obtained from android.provider.MediaStore.Images.Media.CONTENT_TYPE.

Categories