mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-23 07:27:22 +01:00
get RECEIVE_SMS permission with SEND_SMS
Apparently one of the newer Android SDK levels adds the requirement to have RECEIVE_SMS permission in order for a broadcast receiver to get called. Meaning receipt didn't work even if SEND_SMS had been granted. Since they're both in the same group (for now) the OS will grant the second silently if the first has been granted, but it still has to be requested. So request both at the same time. This still leaves the problem that a user who's never tried to create an SMS game won't have been asked for either permission and so won't receive SMS invitations, but fixing that is for a later release.
This commit is contained in:
parent
3c861166de
commit
9c501b19a8
2 changed files with 18 additions and 8 deletions
|
@ -1218,6 +1218,8 @@ public class BoardDelegate extends DelegateBase
|
|||
case SMS:
|
||||
Perms23.tryGetPerms( this, Perm.SEND_SMS, R.string.sms_invite_rationale,
|
||||
Action.INVITE_SMS, m_mySIS.nMissing, info );
|
||||
Perms23.tryGetPerms( this, Perm.RECEIVE_SMS, R.string.sms_invite_rationale,
|
||||
Action.INVITE_SMS, m_mySIS.nMissing, info );
|
||||
break;
|
||||
case RELAY:
|
||||
RelayInviteDelegate.launchForResult( m_activity, m_mySIS.nMissing,
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
|
@ -43,14 +44,15 @@ public class Perms23 {
|
|||
private static final String TAG = Perms23.class.getSimpleName();
|
||||
|
||||
public static enum Perm {
|
||||
READ_PHONE_STATE("android.permission.READ_PHONE_STATE"),
|
||||
STORAGE("android.permission.WRITE_EXTERNAL_STORAGE"),
|
||||
SEND_SMS("android.permission.SEND_SMS"),
|
||||
READ_CONTACTS("android.permission.READ_CONTACTS")
|
||||
;
|
||||
READ_PHONE_STATE(Manifest.permission.READ_PHONE_STATE),
|
||||
STORAGE(Manifest.permission.WRITE_EXTERNAL_STORAGE),
|
||||
SEND_SMS(Manifest.permission.SEND_SMS),
|
||||
RECEIVE_SMS(Manifest.permission.RECEIVE_SMS),
|
||||
READ_CONTACTS(Manifest.permission.READ_CONTACTS);
|
||||
|
||||
private String m_str;
|
||||
private Perm(String str) { m_str = str; }
|
||||
|
||||
public String getString() { return m_str; }
|
||||
public static Perm getFor( String str ) {
|
||||
Perm result = null;
|
||||
|
@ -261,6 +263,7 @@ public class Perms23 {
|
|||
{
|
||||
// Log.d( TAG, "gotPermissionResult(%s)", perms.toString() );
|
||||
Map<Perm, Boolean> result = new HashMap<Perm, Boolean>();
|
||||
boolean shouldResend = false;
|
||||
for ( int ii = 0; ii < perms.length; ++ii ) {
|
||||
Perm perm = Perm.getFor( perms[ii] );
|
||||
boolean granted = PackageManager.PERMISSION_GRANTED == granteds[ii];
|
||||
|
@ -269,9 +272,8 @@ public class Perms23 {
|
|||
// Hack. If SMS has been granted, resend all moves. This should be
|
||||
// replaced with an api allowing listeners to register
|
||||
// Perm-by-Perm, but I'm in a hurry.
|
||||
if ( granted && perm == Perm.SEND_SMS ) {
|
||||
GameUtils.resendAllIf( context, CommsConnType.COMMS_CONN_SMS,
|
||||
true, true );
|
||||
if ( granted && (perm == Perm.SEND_SMS || perm == Perm.RECEIVE_SMS) ) {
|
||||
shouldResend = true;
|
||||
}
|
||||
|
||||
// Log.d( TAG, "calling %s.onPermissionResult(%s, %b)",
|
||||
|
@ -279,6 +281,11 @@ public class Perms23 {
|
|||
// granted );
|
||||
}
|
||||
|
||||
if ( shouldResend ) {
|
||||
GameUtils.resendAllIf( context, CommsConnType.COMMS_CONN_SMS,
|
||||
true, true );
|
||||
}
|
||||
|
||||
PermCbck cbck = s_map.remove( code );
|
||||
if ( null != cbck ) {
|
||||
cbck.onPermissionResult( result );
|
||||
|
@ -290,6 +297,7 @@ public class Perms23 {
|
|||
String permString = perm.getString();
|
||||
boolean result = PackageManager.PERMISSION_GRANTED
|
||||
== ContextCompat.checkSelfPermission( XWApp.getContext(), permString );
|
||||
// Log.d( TAG, "havePermission(%s) => %b", permString, result );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue