Better tryOpenUri implementation and toast string.

Got the if/else hint from
http://developer.android.com/about/versions/android-4.3.html#Behaviors

(much better than try/except anyway)
This commit is contained in:
Daniel Martí 2013-08-22 18:16:57 +02:00
parent 560b7392cf
commit afe102e90a
2 changed files with 9 additions and 8 deletions

View File

@ -183,7 +183,7 @@
<string name="permissions_for_long">Permissions for version %s</string>
<string name="showPermissions">Show permissions</string>
<string name="showPermissions_long">Display a list of permissions an app needs</string>
<string name="no_handler_app">You don\'t have any app installed that can handle %s</string>
<string name="no_handler_app">You don\'t have any available app that can handle %s</string>
<string name="compactlayout">Compact Layout</string>
<string name="compactlayout_long">Only show app names and summaries in list</string>

View File

@ -634,14 +634,15 @@ public class AppDetails extends ListActivity {
return true;
}
public void tryOpenUri(String s) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(s)));
} catch (android.content.ActivityNotFoundException e) {
Toast toast = Toast.makeText(this,
getString(R.string.no_handler_app, s), Toast.LENGTH_LONG);
toast.show();
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(s));
if (intent.resolveActivity(getPackageManager()) != null)
startActivity(intent);
else
Toast.makeText(this,
getString(R.string.no_handler_app, intent.getDataString()),
Toast.LENGTH_LONG).show();
}
@Override