【发布时间】: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 异常。我不知道如何解决它,谁能帮助我?
【问题讨论】:
-
我认为您应该在这里找到解决方案:stackoverflow.com/questions/43518520/…
-
@Vikas 但我在中国,我的应用用户无法访问 GMS