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 . These examples are extracted from open source projects. 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 Project: v9porn   File: UpdateDownloadService.java    License: 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 2
Source Project: DevUtils   File: IntentUtils.java    License: 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 3
Source Project: AppSmartUpdate   File: MainActivity.java    License: 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 4
Source Project: Common   File: AppUtils.java    License: 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 5
@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 6
/**
 * 去打开安装权限的页面
 * @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
@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;
}