Java Code Examples for android.provider.Settings#ACTION_MANAGE_UNKNOWN_APP_SOURCES

The following examples show how to use android.provider.Settings#ACTION_MANAGE_UNKNOWN_APP_SOURCES . 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: OpenFilePlugin.java    From open_file with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.O)
private void startInstallPermissionSettingActivity() {
    if (activity == null) {
        return;
    }
    Uri packageURI = Uri.parse("package:" + activity.getPackageName());
    Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, packageURI);
    activity.startActivityForResult(intent, RESULT_CODE);
}
 
Example 2
Source File: UpdateDownloadService.java    From v9porn with MIT License 5 votes vote down vote up
/**
 * 跳转到设置-允许安装未知来源-页面
 */
@RequiresApi(api = Build.VERSION_CODES.O)
private void startInstallPermissionSettingActivity() {
    //注意这个是8.0新API
    Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}
 
Example 3
Source File: IntentUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 获取 APP 安装权限设置的意图
 * @param packageName 应用包名
 * @param isNewTask   是否开启新的任务栈
 * @return APP 安装权限设置的意图
 */
public static Intent getLaunchAppInstallPermissionSettingsIntent(final String packageName, final boolean isNewTask) {
    try {
        Uri uri = Uri.parse("package:" + packageName);
        Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, uri);
        return getIntent(intent, isNewTask);
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "getLaunchAppInstallPermissionSettingsIntent");
    }
    return null;
}
 
Example 4
Source File: MainActivity.java    From AppSmartUpdate with Apache License 2.0 5 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) {
        case INSTALL_PACKAGES_REQUESTCODE:
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            } else {
                Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
                startActivityForResult(intent, GET_UNKNOWN_APP_SOURCES);
            }
            break;

    }
}
 
Example 5
Source File: AppUtils.java    From Common with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.O)
private static void startInstallPermissionSettingActivity(Context context) {
    try {
        Uri packageURI = Uri.parse("package:" + context.getPackageName());
        Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, packageURI);
        context.startActivity(intent);
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
 
Example 6
Source File: InstallUtils.java    From MNUpdateAPK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 去打开安装权限的页面
 * @param activity
 * @param installPermissionCallBack
 */
public static void openInstallPermissionSetting(Activity activity, final InstallPermissionCallBack installPermissionCallBack) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        Uri packageURI = Uri.parse("package:" + activity.getPackageName());
        Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, packageURI);
        new ActResultRequest(activity).startForResult(intent, new ActForResultCallback() {
            @Override
            public void onActivityResult(int resultCode, Intent data) {
                Log.i(TAG, "onActivityResult:" + resultCode);
                if (resultCode == RESULT_OK) {
                    //用户授权了
                    if (installPermissionCallBack != null) {
                        installPermissionCallBack.onGranted();
                    }
                } else {
                    //用户没有授权
                    if (installPermissionCallBack != null) {
                        installPermissionCallBack.onDenied();
                    }
                }
            }
        });
    } else {
        //用户授权了
        if (installPermissionCallBack != null) {
            installPermissionCallBack.onGranted();
        }
    }

}
 
Example 7
Source File: PermissionOperator.java    From QuickDevFramework with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.O)
private void requestInstallPackagePermission(Activity activity, RequestPermissionCallback callback) {
    if (PermissionManager.hasInstallPackagePermission()) {
        if (callback != null) {
            callback.onGranted();
        }
        return;
    }
    Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
    intent.setData(Uri.parse("package:" + activity.getPackageName()));
    activity.startActivityForResult(intent, requestCode);
    currCallback = callback;
}