1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-12-22 21:16:57 +00:00

Surround setPrimaryClip with try catch. Fixes austinhuang0131/barinsta#1133

This commit is contained in:
Ammar Githam 2021-04-25 16:25:58 +09:00
parent 3e06cb2079
commit cdbaf95589

View File

@ -88,13 +88,17 @@ public final class Utils {
}
public static void copyText(@NonNull final Context context, final CharSequence string) {
if (clipboardManager == null)
if (clipboardManager == null) {
clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
}
int toastMessage = R.string.clipboard_error;
if (clipboardManager != null) {
clipboardManager.setPrimaryClip(ClipData.newPlainText(context.getString(R.string.app_name), string));
toastMessage = R.string.clipboard_copied;
try {
clipboardManager.setPrimaryClip(ClipData.newPlainText(context.getString(R.string.app_name), string));
toastMessage = R.string.clipboard_copied;
} catch (Exception e) {
Log.e(TAG, "copyText: ", e);
}
}
Toast.makeText(context, toastMessage, Toast.LENGTH_SHORT).show();
}