我在我的活动有一个问题,它可以控制到Android手机GPS设置有用户打开/关闭GPS,但我无法retrun回到我的活动。当我preSS后退按钮,它直接将家里的移动,而不是从那里我将信号发送到设置回来我的活动。谁能告诉我这种情况的解决方案。
如果(!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)){
startActivityForResult(新意图(Settings.ACTION_LOCATION_SOURCE_SETTINGS),1);
@覆盖
保护无效onActivityResult(INT申请code,INT结果code,意图数据){
Log.e(,OnActivity结果......);
super.onActivityResult(要求code,因此code,数据);
如果(结果code == GPS_LOC){
开关(要求code){
案例GPS_LOC:
//super.onCreate(inst);
super.onResume();
//super.finish();
打破;
}
}
}
解决方案
我的作品。你确定你有ACCESS_FINE_LOCATION权限集中在你的清单?你肯定startActivityForResult()被调用?
此外,什么是GPS_LOC?
下面是我的code的作品:
公共类主要的扩展活动{
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
findViewById(R.id.button1).setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
startActivityForResult(新意图(Settings.ACTION_LOCATION_SOURCE_SETTINGS),1);
}
});
}
@覆盖
保护无效onActivityResult(INT申请code,INT结果code,意图数据){
super.onActivityResult(要求code,因此code,数据);
如果(结果code == 1){
开关(要求code){
情况1:
打破;
}
}
}
}
I am having a problem in my Activity, which can take the control to the android mobile GPS settings to have user to switch on/off the GPS, But I am unable to retrun back to my activity. when I press back button, It is directly going to Home of the mobile, not coming back my Activity from where I send signal to settings. can anyone tell me the solution for this.
if(!lm.isProviderEnabled(LocationManager.GPS_PROVIDER )) {
startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 1);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.e("","OnActivity Result...");
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == GPS_LOC) {
switch (requestCode) {
case GPS_LOC:
//super.onCreate(inst);
super.onResume();
//super.finish();
break;
}
}
}
解决方案
Works for me. Are you sure you have ACCESS_FINE_LOCATION permission set in your manifest? Are you sure startActivityForResult() is being called?
Also, what is GPS_LOC?
Here's my code that works:
public class main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.button1).setOnClickListener( new OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 1);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == 1) {
switch (requestCode) {
case 1:
break;
}
}
}
}
相关推荐
最新文章