mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-25 02:18:23 +01:00
Handle ActivityNotFoundException when opening Custom Tabs.
This commit is contained in:
parent
fe18c9d520
commit
c50da35b4f
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
BIN
.idea/caches/gradle_models.ser
generated
BIN
.idea/caches/gradle_models.ser
generated
Binary file not shown.
@ -1,5 +1,6 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
@ -152,28 +153,13 @@ public class LinkResolverActivity extends AppCompatActivity {
|
|||||||
if(uri.getScheme() == null) {
|
if(uri.getScheme() == null) {
|
||||||
uri = Uri.parse("http://" + uri.toString());
|
uri = Uri.parse("http://" + uri.toString());
|
||||||
}
|
}
|
||||||
customTabsIntent.launchUrl(this, uri);
|
try {
|
||||||
|
customTabsIntent.launchUrl(this, uri);
|
||||||
|
} catch (ActivityNotFoundException e) {
|
||||||
|
openInBrowser(uri, pm);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
openInBrowser(uri, pm);
|
||||||
intent.setData(uri);
|
|
||||||
|
|
||||||
List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
|
|
||||||
ArrayList<String> packageNames = new ArrayList<>();
|
|
||||||
|
|
||||||
String currentPackageName = getApplicationContext().getPackageName();
|
|
||||||
|
|
||||||
for(ResolveInfo info : activities) {
|
|
||||||
if(!info.activityInfo.packageName.equals(currentPackageName)) {
|
|
||||||
packageNames.add(info.activityInfo.packageName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!packageNames.isEmpty()) {
|
|
||||||
intent.setPackage(packageNames.get(0));
|
|
||||||
startActivity(intent);
|
|
||||||
} else {
|
|
||||||
Toast.makeText(this, R.string.no_browser_found, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,6 +182,29 @@ public class LinkResolverActivity extends AppCompatActivity {
|
|||||||
return packagesSupportingCustomTabs;
|
return packagesSupportingCustomTabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void openInBrowser(Uri uri, PackageManager pm) {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
|
intent.setData(uri);
|
||||||
|
|
||||||
|
List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
|
||||||
|
ArrayList<String> packageNames = new ArrayList<>();
|
||||||
|
|
||||||
|
String currentPackageName = getApplicationContext().getPackageName();
|
||||||
|
|
||||||
|
for(ResolveInfo info : activities) {
|
||||||
|
if(!info.activityInfo.packageName.equals(currentPackageName)) {
|
||||||
|
packageNames.add(info.activityInfo.packageName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!packageNames.isEmpty()) {
|
||||||
|
intent.setPackage(packageNames.get(0));
|
||||||
|
startActivity(intent);
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, R.string.no_browser_found, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Uri getRedditUriByPath(String path) {
|
public static Uri getRedditUriByPath(String path) {
|
||||||
return Uri.parse("https://www.reddit.com" + path);
|
return Uri.parse("https://www.reddit.com" + path);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user