Skip to content

Commit f329b32

Browse files
committed
Correctly open urls in browser on Android 11+
1 parent e0cb289 commit f329b32

File tree

83 files changed

+125
-267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+125
-267
lines changed

app/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<queries>
1616
<intent>
1717
<action android:name="android.intent.action.VIEW" />
18-
<data android:scheme="http|https|market" />
18+
<data android:scheme="http" />
1919
</intent>
2020
</queries>
2121

app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt

+3-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.view.MenuItem
66
import android.view.View
77
import android.view.ViewGroup
88
import android.widget.Button
9+
import androidx.annotation.StringRes
910
import androidx.appcompat.app.AppCompatActivity
1011
import androidx.fragment.app.Fragment
1112
import androidx.fragment.app.FragmentActivity
@@ -57,13 +58,9 @@ class AboutActivity : AppCompatActivity() {
5758
* A placeholder fragment containing a simple view.
5859
*/
5960
class AboutFragment : Fragment() {
60-
private fun Button.openLink(url: Int) {
61+
private fun Button.openLink(@StringRes url: Int) {
6162
setOnClickListener {
62-
ShareUtils.openUrlInBrowser(
63-
context,
64-
requireContext().getString(url),
65-
false
66-
)
63+
ShareUtils.openUrlInApp(context, requireContext().getString(url))
6764
}
6865
}
6966

app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fun showLicense(context: Context?, component: SoftwareComponent): Disposable {
6666
dialog.dismiss()
6767
}
6868
setNeutralButton(R.string.open_website_license) { _, _ ->
69-
ShareUtils.openUrlInBrowser(context!!, component.link)
69+
ShareUtils.openUrlInApp(context!!, component.link)
7070
}
7171
}
7272
}

app/src/main/java/org/schabi/newpipe/error/ErrorActivity.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private void openPrivacyPolicyDialog(final Context context, final String action)
160160
.setMessage(R.string.start_accept_privacy_policy)
161161
.setCancelable(false)
162162
.setNeutralButton(R.string.read_privacy_policy, (dialog, which) ->
163-
ShareUtils.openUrlInBrowser(context,
163+
ShareUtils.openUrlInApp(context,
164164
context.getString(R.string.privacy_policy_url)))
165165
.setPositiveButton(R.string.accept, (dialog, which) -> {
166166
if (action.equals("EMAIL")) { // send on email
@@ -171,9 +171,9 @@ private void openPrivacyPolicyDialog(final Context context, final String action)
171171
+ getString(R.string.app_name) + " "
172172
+ BuildConfig.VERSION_NAME)
173173
.putExtra(Intent.EXTRA_TEXT, buildJson());
174-
ShareUtils.openIntentInApp(context, i, true);
174+
ShareUtils.openIntentInApp(context, i);
175175
} else if (action.equals("GITHUB")) { // open the NewPipe issue page on GitHub
176-
ShareUtils.openUrlInBrowser(this, ERROR_GITHUB_ISSUE_URL, false);
176+
ShareUtils.openUrlInApp(this, ERROR_GITHUB_ISSUE_URL);
177177
}
178178
})
179179
.setNegativeButton(R.string.decline, (dialog, which) -> {

app/src/main/java/org/schabi/newpipe/error/ErrorPanelHelper.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class ErrorPanelHelper(
156156
) {
157157
errorOpenInBrowserButton.isVisible = true
158158
errorOpenInBrowserButton.setOnClickListener {
159-
ShareUtils.openUrlInBrowser(context, errorInfo.request, true)
159+
ShareUtils.openUrlInBrowser(context, errorInfo.request)
160160
}
161161
}
162162

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

+2-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import static org.schabi.newpipe.util.ExtractorHelper.showMetaInfoInTextView;
1212
import static org.schabi.newpipe.util.ListHelper.getUrlAndNonTorrentStreams;
1313
import static org.schabi.newpipe.util.NavigationHelper.openPlayQueue;
14-
import static org.schabi.newpipe.util.NavigationHelper.playWithKore;
1514

1615
import android.animation.ValueAnimator;
1716
import android.annotation.SuppressLint;
@@ -485,16 +484,8 @@ private void setOnClickListeners() {
485484
info.getThumbnailUrl())));
486485
binding.detailControlsOpenInBrowser.setOnClickListener(makeOnClickListener(info ->
487486
ShareUtils.openUrlInBrowser(requireContext(), info.getUrl())));
488-
binding.detailControlsPlayWithKodi.setOnClickListener(makeOnClickListener(info -> {
489-
try {
490-
playWithKore(requireContext(), Uri.parse(info.getUrl()));
491-
} catch (final Exception e) {
492-
if (DEBUG) {
493-
Log.i(TAG, "Failed to start kore", e);
494-
}
495-
KoreUtils.showInstallKoreDialog(requireContext());
496-
}
497-
}));
487+
binding.detailControlsPlayWithKodi.setOnClickListener(makeOnClickListener(info ->
488+
KoreUtils.playWithKore(requireContext(), Uri.parse(info.getUrl()))));
498489
if (DEBUG) {
499490
binding.detailControlsCrashThePlayer.setOnClickListener(v ->
500491
VideoDetailPlayerCrasher.onCrashThePlayer(requireContext(), player));

app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ public boolean onOptionsItemSelected(final MenuItem item) {
204204
break;
205205
case R.id.menu_item_rss:
206206
if (currentInfo != null) {
207-
ShareUtils.openUrlInBrowser(
208-
requireContext(), currentInfo.getFeedUrl(), false);
207+
ShareUtils.openUrlInApp(requireContext(), currentInfo.getFeedUrl());
209208
}
210209
break;
211210
case R.id.menu_item_openInBrowser:

app/src/main/java/org/schabi/newpipe/info_list/dialog/StreamDialogDefaultEntry.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,8 @@ public enum StreamDialogDefaultEntry {
9999
)
100100
),
101101

102-
PLAY_WITH_KODI(R.string.play_with_kodi_title, (fragment, item) -> {
103-
final Uri videoUrl = Uri.parse(item.getUrl());
104-
try {
105-
NavigationHelper.playWithKore(fragment.requireContext(), videoUrl);
106-
} catch (final Exception e) {
107-
KoreUtils.showInstallKoreDialog(fragment.requireActivity());
108-
}
109-
}),
102+
PLAY_WITH_KODI(R.string.play_with_kodi_title, (fragment, item) ->
103+
KoreUtils.playWithKore(fragment.requireContext(), Uri.parse(item.getUrl()))),
110104

111105
SHARE(R.string.share, (fragment, item) ->
112106
ShareUtils.shareText(fragment.requireContext(), item.getName(), item.getUrl(),

app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java

+1-8
Original file line numberDiff line numberDiff line change
@@ -1420,14 +1420,7 @@ private void onMoreOptionsClicked() {
14201420
private void onPlayWithKodiClicked() {
14211421
if (player.getCurrentMetadata() != null) {
14221422
player.pause();
1423-
try {
1424-
NavigationHelper.playWithKore(context, Uri.parse(player.getVideoUrl()));
1425-
} catch (final Exception e) {
1426-
if (DEBUG) {
1427-
Log.i(TAG, "Failed to start kore", e);
1428-
}
1429-
KoreUtils.showInstallKoreDialog(player.getContext());
1430-
}
1423+
KoreUtils.playWithKore(context, Uri.parse(player.getVideoUrl()));
14311424
}
14321425
}
14331426

app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java

+5-37
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.schabi.newpipe.util;
22

3-
import static org.schabi.newpipe.util.external_communication.ShareUtils.installApp;
3+
import static org.schabi.newpipe.util.ListHelper.getUrlAndNonTorrentStreams;
44

55
import android.annotation.SuppressLint;
66
import android.app.Activity;
@@ -50,9 +50,9 @@
5050
import org.schabi.newpipe.local.playlist.LocalPlaylistFragment;
5151
import org.schabi.newpipe.local.subscription.SubscriptionFragment;
5252
import org.schabi.newpipe.local.subscription.SubscriptionsImportFragment;
53-
import org.schabi.newpipe.player.PlayerService;
5453
import org.schabi.newpipe.player.PlayQueueActivity;
5554
import org.schabi.newpipe.player.Player;
55+
import org.schabi.newpipe.player.PlayerService;
5656
import org.schabi.newpipe.player.PlayerType;
5757
import org.schabi.newpipe.player.helper.PlayerHelper;
5858
import org.schabi.newpipe.player.helper.PlayerHolder;
@@ -63,8 +63,6 @@
6363

6464
import java.util.List;
6565

66-
import static org.schabi.newpipe.util.ListHelper.getUrlAndNonTorrentStreams;
67-
6866
public final class NavigationHelper {
6967
public static final String MAIN_FRAGMENT_TAG = "main_fragment_tag";
7068
public static final String SEARCH_FRAGMENT_TAG = "search_fragment_tag";
@@ -323,15 +321,13 @@ public static void playOnExternalPlayer(@NonNull final Context context,
323321

324322
public static void resolveActivityOrAskToInstall(@NonNull final Context context,
325323
@NonNull final Intent intent) {
326-
if (intent.resolveActivity(context.getPackageManager()) != null) {
327-
ShareUtils.openIntentInApp(context, intent, false);
328-
} else {
324+
if (!ShareUtils.tryOpenIntentInApp(context, intent)) {
329325
if (context instanceof Activity) {
330326
new AlertDialog.Builder(context)
331327
.setMessage(R.string.no_player_found)
332328
.setPositiveButton(R.string.install,
333-
(dialog, which) -> ShareUtils.openUrlInBrowser(context,
334-
context.getString(R.string.fdroid_vlc_url), false))
329+
(dialog, which) -> ShareUtils.installApp(context,
330+
context.getString(R.string.vlc_package)))
335331
.setNegativeButton(R.string.cancel, (dialog, which)
336332
-> Log.i("NavigationHelper", "You unlocked a secret unicorn."))
337333
.show();
@@ -684,34 +680,6 @@ public static Intent getChannelIntent(final Context context,
684680
return getOpenIntent(context, url, serviceId, StreamingService.LinkType.CHANNEL);
685681
}
686682

687-
/**
688-
* Start an activity to install Kore.
689-
*
690-
* @param context the context
691-
*/
692-
public static void installKore(final Context context) {
693-
installApp(context, context.getString(R.string.kore_package));
694-
}
695-
696-
/**
697-
* Start Kore app to show a video on Kodi.
698-
* <p>
699-
* For a list of supported urls see the
700-
* <a href="https://github.com/xbmc/Kore/blob/master/app/src/main/AndroidManifest.xml">
701-
* Kore source code
702-
* </a>.
703-
*
704-
* @param context the context to use
705-
* @param videoURL the url to the video
706-
*/
707-
public static void playWithKore(final Context context, final Uri videoURL) {
708-
final Intent intent = new Intent(Intent.ACTION_VIEW);
709-
intent.setPackage(context.getString(R.string.kore_package));
710-
intent.setData(videoURL);
711-
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
712-
context.startActivity(intent);
713-
}
714-
715683
/**
716684
* Finish this <code>Activity</code> as well as all <code>Activities</code> running below it
717685
* and then start <code>MainActivity</code>.

app/src/main/java/org/schabi/newpipe/util/external_communication/KoreUtils.java

+39-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package org.schabi.newpipe.util.external_communication;
22

3+
import static org.schabi.newpipe.util.external_communication.ShareUtils.installApp;
4+
import static org.schabi.newpipe.util.external_communication.ShareUtils.tryOpenIntentInApp;
5+
36
import android.content.Context;
7+
import android.content.Intent;
8+
import android.net.Uri;
49

510
import androidx.annotation.NonNull;
611
import androidx.appcompat.app.AlertDialog;
712
import androidx.preference.PreferenceManager;
813

914
import org.schabi.newpipe.R;
1015
import org.schabi.newpipe.extractor.ServiceList;
11-
import org.schabi.newpipe.util.NavigationHelper;
1216

1317
/**
1418
* Util class that provides methods which are related to the Kodi Media Center and its Kore app.
@@ -29,13 +33,39 @@ public static boolean shouldShowPlayWithKodi(@NonNull final Context context,
2933
.getBoolean(context.getString(R.string.show_play_with_kodi_key), false);
3034
}
3135

32-
public static void showInstallKoreDialog(@NonNull final Context context) {
33-
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
34-
builder.setMessage(R.string.kore_not_found)
35-
.setPositiveButton(R.string.install, (dialog, which) ->
36-
NavigationHelper.installKore(context))
37-
.setNegativeButton(R.string.cancel, (dialog, which) -> {
38-
});
39-
builder.create().show();
36+
/**
37+
* Start an activity to install Kore.
38+
*
39+
* @param context the context
40+
*/
41+
public static void installKore(final Context context) {
42+
installApp(context, context.getString(R.string.kore_package));
43+
}
44+
45+
/**
46+
* Start Kore app to show a video on Kodi, and if the app is not installed ask the user to
47+
* install it.
48+
* <p>
49+
* For a list of supported urls see the
50+
* <a href="https://github.com/xbmc/Kore/blob/master/app/src/main/AndroidManifest.xml">
51+
* Kore source code
52+
* </a>.
53+
*
54+
* @param context the context to use
55+
* @param videoURL the url to the video
56+
*/
57+
public static void playWithKore(final Context context, final Uri videoURL) {
58+
final Intent intent = new Intent(Intent.ACTION_VIEW)
59+
.setPackage(context.getString(R.string.kore_package))
60+
.setData(videoURL)
61+
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
62+
63+
if (!tryOpenIntentInApp(context, intent)) {
64+
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
65+
builder.setMessage(R.string.kore_not_found)
66+
.setPositiveButton(R.string.install, (dialog, which) -> installKore(context))
67+
.setNegativeButton(R.string.cancel, (dialog, which) -> { });
68+
builder.create().show();
69+
}
4070
}
4171
}

0 commit comments

Comments
 (0)