added account permission detection to prevent crash
This commit is contained in:
parent
bd1ec749dd
commit
95f80b222e
|
@ -189,6 +189,15 @@ public class AccountUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean hasAccountPermission(@NonNull AccountManager am) {
|
||||||
|
try {
|
||||||
|
getAccounts(am);
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean hasInvalidAccount(@NonNull AccountManager am) {
|
public static boolean hasInvalidAccount(@NonNull AccountManager am) {
|
||||||
for (Account account : getAccounts(am)) {
|
for (Account account : getAccounts(am)) {
|
||||||
if (!isAccountValid(am, account)) return true;
|
if (!isAccountValid(am, account)) return true;
|
||||||
|
|
|
@ -22,7 +22,9 @@ package org.mariotaku.twidere.activity
|
||||||
import android.accounts.AccountManager
|
import android.accounts.AccountManager
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.widget.Toast
|
||||||
import org.mariotaku.twidere.BuildConfig
|
import org.mariotaku.twidere.BuildConfig
|
||||||
|
import org.mariotaku.twidere.R
|
||||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_INTENT
|
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_INTENT
|
||||||
import org.mariotaku.twidere.model.util.AccountUtils
|
import org.mariotaku.twidere.model.util.AccountUtils
|
||||||
import org.mariotaku.twidere.util.StrictModeUtils
|
import org.mariotaku.twidere.util.StrictModeUtils
|
||||||
|
@ -39,6 +41,8 @@ open class MainActivity : BaseActivity() {
|
||||||
val am = AccountManager.get(this)
|
val am = AccountManager.get(this)
|
||||||
if (!Utils.checkDeviceCompatible()) {
|
if (!Utils.checkDeviceCompatible()) {
|
||||||
startActivity(Intent(this, IncompatibleAlertActivity::class.java))
|
startActivity(Intent(this, IncompatibleAlertActivity::class.java))
|
||||||
|
} else if (!AccountUtils.hasAccountPermission(am)) {
|
||||||
|
Toast.makeText(this, R.string.message_toast_no_account_permission, Toast.LENGTH_SHORT).show()
|
||||||
} else if (AccountUtils.hasInvalidAccount(am)) {
|
} else if (AccountUtils.hasInvalidAccount(am)) {
|
||||||
val intent = Intent(this, InvalidAccountAlertActivity::class.java)
|
val intent = Intent(this, InvalidAccountAlertActivity::class.java)
|
||||||
intent.putExtra(EXTRA_INTENT, Intent(this, HomeActivity::class.java))
|
intent.putExtra(EXTRA_INTENT, Intent(this, HomeActivity::class.java))
|
||||||
|
|
|
@ -696,6 +696,7 @@
|
||||||
<!-- Toast message for network errors -->
|
<!-- Toast message for network errors -->
|
||||||
<string name="message_toast_network_error">Network error</string>
|
<string name="message_toast_network_error">Network error</string>
|
||||||
<string name="message_toast_no_account">No account</string>
|
<string name="message_toast_no_account">No account</string>
|
||||||
|
<string name="message_toast_no_account_permission">Account permission is required</string>
|
||||||
<string name="message_toast_no_account_selected">No account selected</string>
|
<string name="message_toast_no_account_selected">No account selected</string>
|
||||||
<string name="message_toast_no_user_selected">No user selected</string>
|
<string name="message_toast_no_user_selected">No user selected</string>
|
||||||
<string name="message_toast_press_again_to_close">Press again to close</string>
|
<string name="message_toast_press_again_to_close">Press again to close</string>
|
||||||
|
|
Loading…
Reference in New Issue