handle youtube.com in app

This commit is contained in:
Roy Olav Purser 2021-05-19 09:03:57 +02:00
parent d443fc74bf
commit aa25a77d5f
Signed by: roypur
GPG Key ID: E14D26A036F21656
2 changed files with 15 additions and 2 deletions

View File

@ -10,8 +10,8 @@ android {
applicationId "it.purser.stream"
minSdkVersion 25
targetSdkVersion 29
versionCode 104
versionName "104.0"
versionCode 106
versionName "106.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

View File

@ -11,6 +11,9 @@ public class ShareActivity extends Activity {
private Uri getSharedLink() {
HashSet<String> domains = new HashSet<>();
domains.add("youtu.be");
domains.add("youtube.com");
domains.add("www.youtube.com");
domains.add("tv.nrk.no");
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
@ -20,6 +23,16 @@ public class ShareActivity extends Activity {
Uri uri = Uri.parse(txt);
String host = uri.getHost().toLowerCase(Locale.ROOT);
if(domains.contains(host)) {
if(host.contains("youtube.com")) {
Uri.Builder builder = new Uri.Builder();
builder.authority(host);
builder.scheme("https");
String path = uri.getQueryParameter("v");
if(path != null) {
builder.path(path);
return builder.build();
}
}
return uri;
}
} catch(Exception e) {}