3 回答

TA贡献1788条经验 获得超4个赞
始终使用此方法来启动除应用程序之外的意图 -
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
if(intent.resolveActivity(context.getPackageManager()) != null){
startActivity(intent);
}else{
//handle activity not found
}
这样你就不会得到 ActivityNotFoundException。
您还可以使用 try catch 作为 -
try {
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
} catch (e: ActivityNotFoundException) {
//handle activity not found
}

TA贡献1779条经验 获得超6个赞
Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //This line solve my issue
startActivity(i);

TA贡献1785条经验 获得超4个赞
我想您想导航到 GPS 设置屏幕。尝试这个。
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
手机/设备可能完全缺少区域设置屏幕,从而导致崩溃。
添加回答
举报