Open youtube video at a specific time using android intent - android

I am opening a youtube video from my app, similar with this answer: https://stackoverflow.com/a/12439378/379865
I was wondering if it's possible to open the video at a specified time, so for instance have video running from 30 seconds at start, not from the beginning.

YouTube have a great way of indicating time in their URL for the videos.
So let's say a url of a video is
https://www.youtube.com/watch?v=Z149x12sXsw
You can reference the same URL with it playing automatically 30
seconds in by putting &t=0m30s at the end.
When you open the video, pass in the new url with the new
extension. It should look something like
https://www.youtube.com/watch?v=Z149x12sXsw&t=0m30s
The Intent will look something like startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=Z149x12sXs" + time))); where String time = "&t=0m30s";
Edit: Expansion for YouTube App.
public static void watchYoutubeVideo(String id, String time){
Intent appIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + id + time));
Intent webIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.youtube.com/watch?v=" + id + time));
try {
startActivity(appIntent);
} catch (ActivityNotFoundException ex) {
startActivity(webIntent);
}
}
Using another answer from that question. The same logic can be applied to any intent just add the Time string to the URI like shown above regardless of intention.

Try Opening url with url something similar to this
https://www.youtube.com/watch?v=u0IU8uQniX8&t=2m35s
where t= time in minutes and seconds
t=2m35s

Related

Waze - open waze.to links in app and start navigation,

I would like to open the Waze app from a web browser but the links I have in my db are in this format:
http://waze.to/li/hsv9hc540y
https://waze.to/li/hsv8v8wv81
When I click on these links from my mobile web browser they open the app but the navigation doesn't begin, it's only opens the app and that's it.
After reading the updated waze api I haven't found a way to navigate using the encrypted string hsv9hc540y only by latitude and longitude which I don't have.
How can I convert those waze.to links to the new deep links api using the encrypted string I have so it will open the app and init navigation?
Your deep links are not correct. To make them work, they need to look like this:
https://waze.com/ul/hsv9hc540y
https://waze.com/ul/hsv8v8wv81
For more info, check this link:
https://developers.google.com/waze/deeplinks/
try {
// Launch Waze
String mapRequest = "https://waze.com/ul?q=" + latLng.latitude + "," + latLng.longitude + "&navigate=yes&zoom=17";
Uri gmmIntentUri = Uri.parse(mapRequest);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.waze");
startActivity(mapIntent);
} catch (ActivityNotFoundException e)
{
// If Waze is not installed, open it in Google Play
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.waze"));
startActivity(intent);
}

How to launch Play Store in libgdx

Hi i am creating a simple game and i want yo know how to launch Play Store in ligbdx when someone would like to rate my game.
Please help!
Thanks
You have two options :
Either open directly by using complete URL (generic for all platform)
Gdx.net.openURI("https://play.google.com/store/apps/details?id=com.xyz.abc");
Use interfacing and implement platform specific APIs.
eg. like for Android
public void rate(){
Intent rateIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("https://play.google.com/store/apps/details?id=com.xyz.abc"));
//or
//Intent rateIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("https://play.google.com/store/apps/details?id="+getPackageName()));
startActivity(rateIntent);
}
It prompt a choose dialog, having browser and Playstore app (If PlayStore installed in device) option. choose PlayStore.
EDIT
try {
Intent viewIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=" + getPackageName()));
startActivity(viewIntent);
}catch (android.content.ActivityNotFoundException anfe){
String url="https://play.google.com/store/apps/details?id="+getPackageName();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
if (intent.resolveActivity(getPackageManager())!=null) {
startActivity(intent);
}
}

URL link Cardboard and youtube Android

I am trying to open a 360video from unity without using a “VideoTexture”, which means to use a URL and then, select the “cardboard experience”.
My question is if it is a way of launching directly the youtube application with the link of the youtube video (360) from Android, which will display the video in full screen using the gyroscope data.
Please write to michael.soler.beatty#gmail.com if needed
The video is
https://www.youtube.com/watch?v=EhueMB9EzoE
Thanks
This android code must be work:
public static void watchYoutubeVideo(String id){
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + id));
startActivity(intent);
} catch (ActivityNotFoundException ex) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.youtube.com/watch?v=" + id));
startActivity(intent);
}
}
You can write an android unity plugin or use android jni inside Unity.

How can i Search any web sites without typing http:// or www. (like other android browser's)

try {
ourBrowser.loadUrl("http://google.com");
} catch (Exception e) {
e.printStackTrace();
}
this code is ok i know but how can i search any site without using Http or www ... like other android browser's . example sometime we type Hello and Google give us all hello worlds with link's....... i m new in android world so please developer's help me out....?
i m also tried this method = ourBrowser.loadUrl("http://google.com"+url);
https://www.google.cz/search?q=search+term
is the thing you want or use it as intent:
Uri uri = Uri.parse("http://www.google.com/#q=fish");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Maybe it's what you need ?
public void launchUrl(String URL){
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.google.fr/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q="+URL));
startActivity(browserIntent);
}
And you will call it with
launchUrl("MysearchExample");

Rate Google Play application directly in app [duplicate]

This question already has answers here:
Use application to rate it on market [duplicate]
(4 answers)
Closed 3 years ago.
I need to make rate option in my android app.
I found this link
but I'm not sure that want I search. I want to just provide ability for users to rate my app on Google Play.
The rating is done through market app so that ratings can be trusted. If apps were allowed to handle the rating themselves, then the developer could manipulate the app's rating any time. So there is no way you can handle the rating yourself. You can only prompt the user to your app page on Google Play and ask them to rate your app for more support.
Use the built-in intent to launch market
private void launchMarket() {
Uri uri = Uri.parse("market://details?id=" + getPackageName());
Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);
try {
startActivity(myAppLinkToMarket);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, " unable to find market app", Toast.LENGTH_LONG).show();
}
}
Simple do this...
final String appPackageName = "your.package.name";
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
}
You can use 3rd party tool. Here are some commonly used solutions:
appirater: https://github.com/drewjw81/appirater-android/
apptentive: http://www.apptentive.com/
polljoy: https://polljoy.com
AppRater: https://github.com/delight-im/AppRater
public void launchMarket()
{
Uri uri = Uri.parse("market://details?id=" + this.getPackageName());
Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);
try
{
mContext.startActivity(myAppLinkToMarket);
}
catch (ActivityNotFoundException e)
{
Toast.makeText(this, " Sorry, Not able to open!", Toast.LENGTH_SHORT).show();
}
}
Users can't rate your app directly from within your app. They must go to Google Play and rate it. Like the link shows, you must redirect the user to view your app on Google Play:
mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
For the code below, I have used try and catch method. The try and catch method will work as follows. On button click, the try method will try to search for the Google play store app on your android phone and launches it if is already installed and navigates to your application on the play store. However, in case you don't have the play store app on your android phone, catch method is executed and launches browser installed on your application and navigates to your application on the play store. getPackageName() is an inbuilt function that gets your project package name. You can add it manually as a string.
Also see for amazon store
String package="com.example.android";
The full code.
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
Uri uri = Uri.parse("market://details?id="+getPackageName()+"");
Intent goMarket = new Intent(Intent.ACTION_VIEW, uri);
startActivity(goMarket);
}catch (ActivityNotFoundException e){
Uri uri = Uri.parse("https://play.google.com/store/apps/details?id="+getPackageName()+"");
Intent goMarket = new Intent(Intent.ACTION_VIEW, uri);
startActivity(goMarket);
}
}
});
I was searching for a feature similar to iOS, where the user doesn't need to be redirected to play store and again asked to write his reviews. Initially, I thought this was impossible but thankfully my understanding was outdated. Found this app which does that searching for code though.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.test(This is the package name)"));
startActivity(intent);
I always use a method like this one
private void launchMarket() {
Uri uri = Uri.parse("market://details?id=" + getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
try {
startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "couldn't launch the market", Toast.LENGTH_LONG).show();
}
}
Paste this simple code to go play store rating page from your Application
Intent intent1 = new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id="
+ MainActivity.this.getPackageName()));
startActivity(intent1);

Categories

Resources