How to open youtube applications home activity from my android application? - android

I have an android application. I just need to open youtube application home activity from my android application. Please note I do not want to open any specific video or channel. Just want to open application. I have gone through this and this but all are for opening any video or channel.
Please suggest me if anyone knows this.
Note: Application is running on TV and android version is 4.4

for opening any app form your device you have to know the package name of that app......
By firing an intent of that package name you can open an app form your app but if intent does not get a package name than no intent is their for handle that intent so take care of it...
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("any package name you want to open");
startActivity( LaunchIntent );
In your case it is youtube so package name is :
com.google.android.youtube

open app using package name youtube package name is com.google.android.youtube so you can use below intent code
try {
Intent LaunchIntent = packageManager.getLaunchIntentForPackage("com.google.android.youtube");
startActivity(LaunchIntent);
} catch (Exception e) {
e.printStackTrace();
}
just surround with try catch if in case package not found to get package name of any app use this Application on Google Play
same code work for Android TV

Actually the package name for youtube app in TV was not same as that in phones.
the package name for youtube app on TV is "com.google.android.youtube.googletv" so following code worked for me.
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.google.android.youtube.googletv");
startActivity( LaunchIntent );

This will work on a device but not the emulator
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=cxLG2wtE7TM")));

Try this :
public static void openInstalledApp(Context context, String bundle_id) {
PackageManager pm = context.getPackageManager();
Intent appStartIntent = pm.getLaunchIntentForPackage(bundle_id);
if (null != appStartIntent) {
context.startActivity(appStartIntent);
}
}
And use it :
openInstalledApp(<your_context>,"com.google.android.youtube");
Where in second param you can pass any bundleID which is installed in your device and you wants to open it.

Related

using deep linking in android with adds

How to open specific page of another app on clicking add in app in android ? I am creating an android app in which add are showing .when clicking on that add it opens the play store. But i want to open specific page of that app using deeplinking. e.g am getting snapdeal offers add in my application when i click on that add it open the specific page of snapdeal.How to do that ?
Add the package name of the app you want to open in playstore:
String appPackageName = "package_xy"; // eg. com.twitter.android
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
}catch (android.content.ActivityNotFoundException e) {
//if playstore app not installed
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
}
So you probably would need your advertisement to send the package name of their app with it. Or just an url to open (maybe send the playstore browser link in the catch above if its an app, so you could detect the play.google.com part and replace accordingly or just open the plain website if its not a playstore url).
You asked what happens if the app is already installed: Still the same. You should check for it first:
Intent i;
PackageManager manager = getPackageManager();
String appPackageName = "package_xy";
try {
i = manager.getLaunchIntentForPackage(appPackageName);
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e)
{
//open playstore instead
}
So this is only one of many ways. If the app is not found on the device, the try will fail and catch is executed. If it is found it will be opened.
In the case of twitter I even could open it with a deeplink like this:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://status?status_id="+id));
For some things like PDF there are ways to open the applicationpicker, but I don't think thats what you need in this case.
You should be fine if you use the above code. Just put the first snippet in the catch of the second one and you should be fine.

Launching Android Netflix App And Passing Video Id

In the app I am working on I want to support Netfilx streaming. I intend on doing this by simply starting Netflix and passing a specific URI so it plays a specific video when started. Simple right? Well, the issue is I'm not sure how to pass the video id info in the Intent I use to start the Activity.
I've read the post here , but am unsure where to use this. I used Intent.setData() since it accepts a URI, but to no avail.
Here is what I have been doing (I am hard coding the movie data, this is just for testing purposes) :
// the Netflix intent
Intent intent = getPackageManager().getLaunchIntentForPackage("com.netflix.mediaclient");
//the uri
Uri uri = Uri.parse("http://movies.netflix.com/WiPlayer?movieid=70266228&trkid=13462049&ctx=0%2C1%2Ce2bd7b74-6743-4d5e-864f-1cc2568ba0da-61921755");
intent.setData(uri);
//launches but does not go to the video
startActivity(intent);
I've also tried using the URI protocol in the link above like so:
Uri uri = Uri.parse("nflx://movies.netflix.com/WiPlayer?movieid=70266228&trkid=13462049&ctx=0%2C1%2Ce2bd7b74-6743-4d5e-864f-1cc2568ba0da-61921755");
but still am not seeing the video play.
I feel like I am missing something simple here, although I have had very little luck Googling for this, I could find next to nothing about starting the Netflix Android app from another application. The Netflix developer resources don't have any info on this.
Does anyone have any suggestions on how I can do this or where I should be looking for documentation on this? Any help would be appreciated. Thanks much!
Just some Android Apps intent names to help anyone.
Format: appName, packageName, className
Skype: com.skype.raider, com.skype.raider.Main
Netflix: com.netflix.mediaclient, com.netflix.mediaclient.ui.launch.UIWebViewActivity
ESexplorer: com.estrongs.android.pop, com.estrongs.android.pop.view.FileExplorerActivity
Youtube: com.google.android.youtube,com.google.android.youtube.HomeActivity
Chrome: com.android.chrome,com.google.android.apps.chrome.Main
VLC: org.videolan.vlc, org.videolan.vlc.gui.MainActivity
MBOXSettings: com.mbx.settingsmbox, com.mbx.settingsmbox.SettingsMboxActivity
I've managed to do this. With the following code. First you need the movieId (or videoId) for netflix, then compose the URL to watch.
String netFlixId = "43598743"; // <== isn't a real movie id
String watchUrl = "http://www.netflix.com/watch/"+netFlixId;
Then with this intent
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.netflix.mediaclient", "com.netflix.mediaclient.ui.launch.UIWebViewActivity");
intent.setData(Uri.parse(watchUrl));
startActivity(intent);
}
catch(Exception e)
{
// netflix app isn't installed, send to website.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(item.url));
startActivity(intent);
}
I haven't tried with TV Shows yet. But this works beautifully. If you want to send to the profile page of the movie.. Send it to a url formatted this way
http://www.netflix.com/title/324982
I also found out how to search for a title.
try {
Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.setClassName("com.netflix.mediaclient", "com.netflix.mediaclient.ui.search.SearchActivity");
intent.putExtra("query", item.label);
startActivity(intent);
}
catch(Exception e)
{
Toast.makeText(this, "Please install the NetFlix App!", Toast.LENGTH_SHORT).show();
}
Here is how to start a movie from an ADB command for com.netflix.mediaclient
adb shell am start -n com.netflix.mediaclient/.ui.launch.UIWebViewActivity -a android.intent.action.VIEW -d http://www.netflix.com/watch/60000724
I still can't find a way to do it for com.netflix.ninja (Netflix for Android TV)

Setting default browser for activity programmatically

I'm developing an android app and among other functionality I need to open some urls in external web browser. Can I programmatically set a default application for that, so the user won't be able to choose from the list of available browsers? I mean, I want to set default browser only for my app but not for the whole operating system.
Yes, for this you can force your application to always open native android browser only. For this you have to identify the launching Activity of Browser application, something like this:
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.google.android.browser","com.google.android.browser.BrowserActivity"));
intent.setAction("android.intent.action.VIEW");
intent.addCategory("android.intent.category.BROWSABLE");
Uri uri = Uri.parse(url);
intent.setData(uri);
try
{
startActivity(intent);
}
catch (Exception e)
{
e.printStackTrace();
}
You can use .setPackage for the intent: http://developer.android.com/reference/android/content/Intent.html#setPackage(java.lang.String) . Call it with the browser's package name (defined in its manifest, package attribute).
I'm using something similar for firing up the Google+ application for sharing a string:
Intent shareIntent = ShareCompat.IntentBuilder.from(getActivity())
.setText("Dummy string to share")
.setType("text/plain")
.getIntent()
.setPackage("com.google.android.apps.plus");
startActivity(shareIntent);
In my example, "com.google.android.apps.plus" is the package name for the Google+ application.
Sharedpreference for Browser class is "MODE_private" , so we can't access the home_page changing steps directly programatically,
iff we want to do, we should do through Browser.java opensource code and we should get some idea from there itself.

How do I open android built in downloads app?

So I'm downloading stuff and it gets put into the built in downloads app since thats how the download manager works. I just want to the user to click a button which opens the built in downloads app.
Heres my try:
btnDownloads.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
PackageManager pakMan=MainActivity.context.getPackageManager();
Log.d("bebr", "Making pak");
if(pakMan!=null){
Intent downloadsIntent=new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(new ComponentName("com.android.downloads","com.android.downlods.Downloads"));
ResolveInfo resolved=pakMan.resolveActivity(downloadsIntent, PackageManager.MATCH_DEFAULT_ONLY);
Log.d("bebr","Resolving");
if(resolved!=null){
Log.d("bebr", "Starting");
startActivity(downloadsIntent);
}
}
}
});
Ok finally managed to get the solution:
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(LaunchIntent);
Use the DownloadManager.ACTION_VIEW_DOWNLOADS constant:
startActivity(new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS));
You'd have to know the package name to launch the Downloads application. I am not certain that it is the same on every device either (though it may be). You can find it by watching the Logcat and launching it you should see some line in the log that has the package name in it.
However you can skip the downloads app completely and launch the package installer directly (which is what will happen when the user selects your apk in the downloads app)
just fill in the path to the file in the following snippet:
File appFile = new File("/path/to/your/file.apk");
Uri packageURI = Uri.parse("file:/"+ appFile.getAbsolutePath());
Intent installIntent = new Intent(Intent.ACTION_VIEW);
installIntent.setDataAndType(Uri.fromFile(appFile),"application/vnd.android.package-archive");
startActivity(installIntent);

How can I check if the Android Market is installed on my user's device?

How could I write a code which can tell me that android market is installed on your android phone?
There are two ways. You can use the already mentioned getPackageManager() and getApplicationInfo() (if the package is not found, a PacketManager.NameNotFoundException will be thrown - see here). Android Market's package name is com.android.vending.
However, you can also create a dummy intent for searching the market and check how it is handled. If the resulting list has at least one entry, you can be sure that Android Market is installed:
Intent market = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=dummy"));
PackageManager manager = getPackageManager();
List<ResolveInfo> list = manager.queryIntentActivities(mmarket, 0);
Here's what I did (assumes browser exists):
Intent market = new Intent(Intent.ACTION_VIEW).setData(Uri
.parse("market://details?id=com.example.app"));
Intent website = new Intent(Intent.ACTION_VIEW).setData(Uri
.parse("http://play.google.com/store/apps/details?id=com.example.app"));
try {
startActivity(market);
} catch (ActivityNotFoundException e) {
startActivity(website);
}

Categories

Resources