【问题标题】:unable to force open GPS无法强制打开 GPS
【发布时间】:2019-04-19 05:52:00
【问题描述】:

我想帮助我的应用用户在他们关闭 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 异常。我不知道如何解决它,谁能帮助我?

【问题讨论】:

标签: android gps


【解决方案1】:

尝试在 try catch 块中添加整个代码并检查通用 Exception 类并查看错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-09
    • 2013-12-07
    • 2010-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多