Click here to Skip to main content
15,502,349 members
Home / Discussions / Android
   

Android

 
GeneralRe: Android Day of Week Calculator Pin
Pavlex49-Feb-17 22:39
Pavlex49-Feb-17 22:39 
GeneralRe: Android Day of Week Calculator Pin
Richard MacCutchan9-Feb-17 23:20
mveRichard MacCutchan9-Feb-17 23:20 
GeneralRe: Android Day of Week Calculator Pin
David Crow10-Feb-17 3:08
David Crow10-Feb-17 3:08 
GeneralRe: Android Day of Week Calculator Pin
Richard MacCutchan10-Feb-17 3:46
mveRichard MacCutchan10-Feb-17 3:46 
GeneralMobile and o/s application development Pin
JimmiJames337-Feb-17 6:42
professionalJimmiJames337-Feb-17 6:42 
QuestionRe: Mobile and o/s application development Pin
David Crow7-Feb-17 7:15
David Crow7-Feb-17 7:15 
QuestionAndroid Popup Window Pin
Pavlex42-Feb-17 9:09
Pavlex42-Feb-17 9:09 
QuestionPermissions Not Persistent During Across App Startups Pin
Django_Untaken1-Feb-17 21:51
Django_Untaken1-Feb-17 21: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 23:33
mveAfzaal Ahmad Zeeshan1-Feb-17 23:33 
GeneralRe: Permissions Not Persistent During Across App Startups Pin
Django_Untaken2-Feb-17 2:06
Django_Untaken2-Feb-17 2:06 
GeneralRe: Permissions Not Persistent During Across App Startups Pin
Afzaal Ahmad Zeeshan2-Feb-17 3:21
mveAfzaal Ahmad Zeeshan2-Feb-17 3:21 
GeneralRe: Permissions Not Persistent During Across App Startups Pin
Django_Untaken2-Feb-17 3:58
Django_Untaken2-Feb-17 3:58 
GeneralRe: Permissions Not Persistent During Across App Startups Pin
Richard Deeming2-Feb-17 4:46
mveRichard Deeming2-Feb-17 4:46 
QuestionAlarm Manager Pin
Pavlex429-Jan-17 1:40
Pavlex429-Jan-17 1:40 
AnswerRe: Alarm Manager Pin
Richard MacCutchan29-Jan-17 3:01
mveRichard MacCutchan29-Jan-17 3:01 
GeneralRe: Alarm Manager Pin
Pavlex429-Jan-17 3:13
Pavlex429-Jan-17 3:13 
GeneralRe: Alarm Manager Pin
Richard MacCutchan29-Jan-17 3:18
mveRichard MacCutchan29-Jan-17 3:18 
GeneralRe: Alarm Manager Pin
Afzaal Ahmad Zeeshan29-Jan-17 3:22
mveAfzaal Ahmad Zeeshan29-Jan-17 3:22 
GeneralRe: Alarm Manager Pin
Richard MacCutchan29-Jan-17 3:47
mveRichard MacCutchan29-Jan-17 3:47 
GeneralRe: Alarm Manager Pin
Afzaal Ahmad Zeeshan29-Jan-17 4:07
mveAfzaal Ahmad Zeeshan29-Jan-17 4:07 
AnswerRe: Alarm Manager Pin
Afzaal Ahmad Zeeshan29-Jan-17 3:20
mveAfzaal Ahmad Zeeshan29-Jan-17 3:20 
GeneralRe: Alarm Manager Pin
Pavlex429-Jan-17 4:40
Pavlex429-Jan-17 4:40 
AnswerRe: Alarm Manager Pin
Afzaal Ahmad Zeeshan29-Jan-17 4:56
mveAfzaal Ahmad Zeeshan29-Jan-17 4:56 
GeneralRe: Alarm Manager Pin
Pavlex429-Jan-17 5:00
Pavlex429-Jan-17 5:00 
GeneralRe: Alarm Manager Pin
Pavlex429-Jan-17 5:54
Pavlex429-Jan-17 5: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.