Click here to Skip to main content
15,881,812 members
Home / Discussions / Android
   

Android

 
GeneralRe: Android Day of Week Calculator Pin
Pavlex49-Feb-17 21:39
Pavlex49-Feb-17 21:39 
GeneralRe: Android Day of Week Calculator Pin
Richard MacCutchan9-Feb-17 22:20
mveRichard MacCutchan9-Feb-17 22:20 
GeneralRe: Android Day of Week Calculator Pin
David Crow10-Feb-17 2:08
David Crow10-Feb-17 2:08 
GeneralRe: Android Day of Week Calculator Pin
Richard MacCutchan10-Feb-17 2:46
mveRichard MacCutchan10-Feb-17 2:46 
GeneralMobile and o/s application development Pin
JimmiJames337-Feb-17 5:42
professionalJimmiJames337-Feb-17 5:42 
QuestionRe: Mobile and o/s application development Pin
David Crow7-Feb-17 6:15
David Crow7-Feb-17 6:15 
QuestionAndroid Popup Window Pin
Pavlex42-Feb-17 8:09
Pavlex42-Feb-17 8:09 
QuestionPermissions Not Persistent During Across App Startups Pin
Django_Untaken1-Feb-17 20:51
Django_Untaken1-Feb-17 20:51 
Hello there. First of all, permission working fine when I use onRequestPermissionsResult() in MainActivity.

Problem occurs when I try to seperate permission from MainActivity using the following model
public interface RequestPermissionsResultInterface
{
  void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults);
}

public interface PermissionManagerInterface
{
  void onPermissionGranted(String message, int requestCode);
  void onPermissionDenied(String message, int requestCode);
}

public class PermissionManager implements RequestPermissionsResultInterface
{
    private Activity mActivity;
    private static Context mContext;
    private static PermissionManager mPermissionManager;
    private static volatile PermissionManagerInterface mManagerInterface;

    
    public static PermissionManager getInstance(Context context)
    {
        if (mPermissionManager == null)
        {
            synchronized (PermissionManager.class)
            {
                if (mPermissionManager == null)
                {
                    mPermissionManager = new PermissionManager(context);
                }
            }
        }
        return mPermissionManager;
    }

    public PermissionManager(Context context) {
        mContext = context;
    }

    public RequestPermissionsResultInterface askPermission(
            Activity mActivity,
            String permissionName,
            final PermissionManagerInterface managerInterface,
            final int requestCode)
    {
       if (ContextCompat.checkSelfPermission(mActivity, permissionName) != PackageManager.PERMISSION_GRANTED)
       {
          // show message box
       }
       else
          ActivityCompat.requestPermissions(
                      mActivity,
                      new String[]{permissionName},
                      requestCode);
    }

  @Override
  public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
  {
    if(grantResults[0] == PackageManager.PERMISSION_GRANTED)
      mManagerInterface.onPermissionGranted("Permission Granted", requestCode);
    else
      mManagerInterface.onPermissionDenied("Permission Denied", requestCode);
  }
}

Then I use PermissionManager in the MainActivity::OnCreate() like this
mPermissionManagerInterface = new PermissionManagerInterface() {
    @Override
    public void onPermissionGranted(String message, int requestCode)
    {
        Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onPermissionDenied(String message, int requestCode)
    {
        Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
    }
};

mPermissionManager = PermissionManager.getInstance(this);
mPermissionManager.askPermission(
        this,
        Manifest.permission.READ_EXTERNAL_STORAGE,
        mPermissionManagerInterface,
        EXTERNAL_STORAGE_PERMISSION_CODE);


As said in the title, it allows the permission....but it does not persist. When I close and rerun the application again, I have to allow this permission again. What could be wrong? Thanks for any pointer.
AnswerRe: Permissions Not Persistent During Across App Startups Pin
Afzaal Ahmad Zeeshan1-Feb-17 22:33
professionalAfzaal Ahmad Zeeshan1-Feb-17 22:33 
GeneralRe: Permissions Not Persistent During Across App Startups Pin
Django_Untaken2-Feb-17 1:06
Django_Untaken2-Feb-17 1:06 
GeneralRe: Permissions Not Persistent During Across App Startups Pin
Afzaal Ahmad Zeeshan2-Feb-17 2:21
professionalAfzaal Ahmad Zeeshan2-Feb-17 2:21 
GeneralRe: Permissions Not Persistent During Across App Startups Pin
Django_Untaken2-Feb-17 2:58
Django_Untaken2-Feb-17 2:58 
GeneralRe: Permissions Not Persistent During Across App Startups Pin
Richard Deeming2-Feb-17 3:46
mveRichard Deeming2-Feb-17 3:46 
QuestionAlarm Manager Pin
Pavlex429-Jan-17 0:40
Pavlex429-Jan-17 0:40 
AnswerRe: Alarm Manager Pin
Richard MacCutchan29-Jan-17 2:01
mveRichard MacCutchan29-Jan-17 2:01 
GeneralRe: Alarm Manager Pin
Pavlex429-Jan-17 2:13
Pavlex429-Jan-17 2:13 
GeneralRe: Alarm Manager Pin
Richard MacCutchan29-Jan-17 2:18
mveRichard MacCutchan29-Jan-17 2:18 
GeneralRe: Alarm Manager Pin
Afzaal Ahmad Zeeshan29-Jan-17 2:22
professionalAfzaal Ahmad Zeeshan29-Jan-17 2:22 
GeneralRe: Alarm Manager Pin
Richard MacCutchan29-Jan-17 2:47
mveRichard MacCutchan29-Jan-17 2:47 
GeneralRe: Alarm Manager Pin
Afzaal Ahmad Zeeshan29-Jan-17 3:07
professionalAfzaal Ahmad Zeeshan29-Jan-17 3:07 
AnswerRe: Alarm Manager Pin
Afzaal Ahmad Zeeshan29-Jan-17 2:20
professionalAfzaal Ahmad Zeeshan29-Jan-17 2:20 
GeneralRe: Alarm Manager Pin
Pavlex429-Jan-17 3:40
Pavlex429-Jan-17 3:40 
AnswerRe: Alarm Manager Pin
Afzaal Ahmad Zeeshan29-Jan-17 3:56
professionalAfzaal Ahmad Zeeshan29-Jan-17 3:56 
GeneralRe: Alarm Manager Pin
Pavlex429-Jan-17 4:00
Pavlex429-Jan-17 4:00 
GeneralRe: Alarm Manager Pin
Pavlex429-Jan-17 4:54
Pavlex429-Jan-17 4:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.