无法强制打开GPS

unable to force open GPS

我想帮助我的应用用户在他们关闭 GPS 时强制打开 GPS,我按照以下代码进行操作:

public static void openGPS(final Context context) {
    Intent gpsIntent = new Intent();
    gpsIntent.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
    gpsIntent.addCategory("android.intent.category.ALTERNATIVE");
    gpsIntent.setData(Uri.parse("custom:3"));
    try {
        PendingIntent.getBroadcast(context, 0, gpsIntent, 0).send();
    } catch (PendingIntent.CanceledException e) {
        Toast.makeText(context, "force open GPS failed:" + e.getMessage(), Toast.LENGTH_SHORT).show();
    }
}

但我无法打开 GPS,也没有得到异常 Toast like above.I 不知道如何解决它,有人可以帮助我吗?

尝试在 try catch 块中添加整个代码并检查通用异常 class 并查看错误是什么。