Java Code Examples for org.telegram.ui.Components.AlertsCreator#createContactsPermissionDialog()

The following examples show how to use org.telegram.ui.Components.AlertsCreator#createContactsPermissionDialog() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContactsActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void askForPermissons(boolean alert) {
    Activity activity = getParentActivity();
    if (activity == null || !UserConfig.getInstance(currentAccount).syncContacts || activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
        return;
    }
    if (alert && askAboutContacts) {
        AlertDialog.Builder builder = AlertsCreator.createContactsPermissionDialog(activity, new MessagesStorage.IntCallback() {
            @Override
            public void run(int param) {
                askAboutContacts = param != 0;
                MessagesController.getGlobalNotificationsSettings().edit().putBoolean("askAboutContacts", askAboutContacts).commit();
                askForPermissons(false);
            }
        });
        showDialog(builder.create());
        return;
    }
    ArrayList<String> permissons = new ArrayList<>();
    permissons.add(Manifest.permission.READ_CONTACTS);
    permissons.add(Manifest.permission.WRITE_CONTACTS);
    permissons.add(Manifest.permission.GET_ACCOUNTS);
    String[] items = permissons.toArray(new String[permissons.size()]);
    activity.requestPermissions(items, 1);
}
 
Example 2
Source File: ContactsActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void askForPermissons(boolean alert) {
    Activity activity = getParentActivity();
    if (activity == null || !UserConfig.getInstance(currentAccount).syncContacts || activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
        return;
    }
    if (alert && askAboutContacts) {
        AlertDialog.Builder builder = AlertsCreator.createContactsPermissionDialog(activity, new MessagesStorage.IntCallback() {
            @Override
            public void run(int param) {
                askAboutContacts = param != 0;
                MessagesController.getGlobalNotificationsSettings().edit().putBoolean("askAboutContacts", askAboutContacts).commit();
                askForPermissons(false);
            }
        });
        showDialog(builder.create());
        return;
    }
    ArrayList<String> permissons = new ArrayList<>();
    permissons.add(Manifest.permission.READ_CONTACTS);
    permissons.add(Manifest.permission.WRITE_CONTACTS);
    permissons.add(Manifest.permission.GET_ACCOUNTS);
    String[] items = permissons.toArray(new String[permissons.size()]);
    activity.requestPermissions(items, 1);
}
 
Example 3
Source File: ContactsActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    if (listViewAdapter != null) {
        listViewAdapter.notifyDataSetChanged();
    }
    if (checkPermission && Build.VERSION.SDK_INT >= 23) {
        Activity activity = getParentActivity();
        if (activity != null) {
            checkPermission = false;
            if (activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
                if (activity.shouldShowRequestPermissionRationale(Manifest.permission.READ_CONTACTS)) {
                    AlertDialog.Builder builder = AlertsCreator.createContactsPermissionDialog(activity, new MessagesStorage.IntCallback() {
                        @Override
                        public void run(int param) {
                            askAboutContacts = param != 0;
                            MessagesController.getGlobalNotificationsSettings().edit().putBoolean("askAboutContacts", askAboutContacts).commit();
                            askForPermissons(false);
                        }
                    });
                    showDialog(permissionDialog = builder.create());
                } else {
                    askForPermissons(true);
                }
            }
        }
    }
}
 
Example 4
Source File: ContactsActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    if (listViewAdapter != null) {
        listViewAdapter.notifyDataSetChanged();
    }
    if (checkPermission && Build.VERSION.SDK_INT >= 23) {
        Activity activity = getParentActivity();
        if (activity != null) {
            checkPermission = false;
            if (activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
                if (activity.shouldShowRequestPermissionRationale(Manifest.permission.READ_CONTACTS)) {
                    AlertDialog.Builder builder = AlertsCreator.createContactsPermissionDialog(activity, new MessagesStorage.IntCallback() {
                        @Override
                        public void run(int param) {
                            askAboutContacts = param != 0;
                            MessagesController.getGlobalNotificationsSettings().edit().putBoolean("askAboutContacts", askAboutContacts).commit();
                            askForPermissons(false);
                        }
                    });
                    showDialog(permissionDialog = builder.create());
                } else {
                    askForPermissons(true);
                }
            }
        }
    }
}
 
Example 5
Source File: ContactsActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    if (listViewAdapter != null) {
        listViewAdapter.notifyDataSetChanged();
    }
    if (checkPermission && Build.VERSION.SDK_INT >= 23) {
        Activity activity = getParentActivity();
        if (activity != null) {
            checkPermission = false;
            if (activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
                if (activity.shouldShowRequestPermissionRationale(Manifest.permission.READ_CONTACTS)) {
                    AlertDialog.Builder builder = AlertsCreator.createContactsPermissionDialog(activity, param -> {
                        askAboutContacts = param != 0;
                        if (param == 0) {
                            return;
                        }
                        askForPermissons(false);
                    });
                    showDialog(permissionDialog = builder.create());
                } else {
                    askForPermissons(true);
                }
            }
        }
    }
}
 
Example 6
Source File: ContactsActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void askForPermissons(boolean alert) {
    Activity activity = getParentActivity();
    if (activity == null || !UserConfig.getInstance(currentAccount).syncContacts || activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
        return;
    }
    if (alert && askAboutContacts) {
        AlertDialog.Builder builder = AlertsCreator.createContactsPermissionDialog(activity, param -> {
            askAboutContacts = param != 0;
            if (param == 0) {
                return;
            }
            askForPermissons(false);
        });
        showDialog(builder.create());
        return;
    }
    ArrayList<String> permissons = new ArrayList<>();
    permissons.add(Manifest.permission.READ_CONTACTS);
    permissons.add(Manifest.permission.WRITE_CONTACTS);
    permissons.add(Manifest.permission.GET_ACCOUNTS);
    String[] items = permissons.toArray(new String[0]);
    try {
        activity.requestPermissions(items, 1);
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
Example 7
Source File: ContactsActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void askForPermissons(boolean alert) {
    Activity activity = getParentActivity();
    if (activity == null || !UserConfig.getInstance(currentAccount).syncContacts || activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
        return;
    }
    if (alert && askAboutContacts) {
        AlertDialog.Builder builder = AlertsCreator.createContactsPermissionDialog(activity, param -> {
            askAboutContacts = param != 0;
            if (param == 0) {
                return;
            }
            askForPermissons(false);
        });
        showDialog(builder.create());
        return;
    }
    ArrayList<String> permissons = new ArrayList<>();
    permissons.add(Manifest.permission.READ_CONTACTS);
    permissons.add(Manifest.permission.WRITE_CONTACTS);
    permissons.add(Manifest.permission.GET_ACCOUNTS);
    String[] items = permissons.toArray(new String[0]);
    try {
        activity.requestPermissions(items, 1);
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
Example 8
Source File: DialogsActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void askForPermissons(boolean alert)
{
    Activity activity = getParentActivity();
    if (activity == null)
    {
        return;
    }
    ArrayList<String> permissons = new ArrayList<>();
    if (UserConfig.getInstance(currentAccount).syncContacts && askAboutContacts && activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED)
    {
        if (alert)
        {
            AlertDialog.Builder builder = AlertsCreator.createContactsPermissionDialog(activity, param ->
            {
                askAboutContacts = param != 0;
                MessagesController.getGlobalNotificationsSettings().edit().putBoolean("askAboutContacts", askAboutContacts).apply();
                askForPermissons(false);
            });
            showDialog(permissionDialog = builder.create());
            return;
        }
        permissons.add(Manifest.permission.READ_CONTACTS);
        permissons.add(Manifest.permission.WRITE_CONTACTS);
        permissons.add(Manifest.permission.GET_ACCOUNTS);
    }
    if (activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
    {
        permissons.add(Manifest.permission.READ_EXTERNAL_STORAGE);
        permissons.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }
    if (permissons.isEmpty())
    {
        return;
    }
    String[] items = permissons.toArray(new String[permissons.size()]);
    try
    {
        activity.requestPermissions(items, 1);
    }
    catch (Exception ignore)
    {
    }
}
 
Example 9
Source File: DialogsActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void askForPermissons(boolean alert)
{
    Activity activity = getParentActivity();
    if (activity == null)
    {
        return;
    }
    ArrayList<String> permissons = new ArrayList<>();
    if (UserConfig.getInstance(currentAccount).syncContacts && askAboutContacts && activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED)
    {
        if (alert)
        {
            AlertDialog.Builder builder = AlertsCreator.createContactsPermissionDialog(activity, param ->
            {
                askAboutContacts = param != 0;
                MessagesController.getGlobalNotificationsSettings().edit().putBoolean("askAboutContacts", askAboutContacts).apply();
                askForPermissons(false);
            });
            showDialog(permissionDialog = builder.create());
            return;
        }
        permissons.add(Manifest.permission.READ_CONTACTS);
        permissons.add(Manifest.permission.WRITE_CONTACTS);
        permissons.add(Manifest.permission.GET_ACCOUNTS);
    }
    if (activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
    {
        permissons.add(Manifest.permission.READ_EXTERNAL_STORAGE);
        permissons.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }
    if (permissons.isEmpty())
    {
        return;
    }
    String[] items = permissons.toArray(new String[permissons.size()]);
    try
    {
        activity.requestPermissions(items, 1);
    }
    catch (Exception ignore)
    {
    }
}
 
Example 10
Source File: ContactsActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    if (listViewAdapter != null) {
        listViewAdapter.notifyDataSetChanged();
    }
    if (checkPermission && Build.VERSION.SDK_INT >= 23) {
        Activity activity = getParentActivity();
        if (activity != null) {
            checkPermission = false;
            if (activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
                if (activity.shouldShowRequestPermissionRationale(Manifest.permission.READ_CONTACTS)) {
                    AlertDialog.Builder builder = AlertsCreator.createContactsPermissionDialog(activity, param -> {
                        askAboutContacts = param != 0;
                        if (param == 0) {
                            return;
                        }
                        askForPermissons(false);
                    });
                    showDialog(permissionDialog = builder.create());
                } else {
                    askForPermissons(true);
                }
            }
        }
    }
}