2016-07-26 74 views
5

我写了一个小应用程序android应显示智能手机的当前位置(最后一个已知位置)。虽然我复制了示例代码,并尝试了其他几种解决方案,但似乎每次都有相同的错误。我的应用程序由一个按钮组成。按下按钮应该是日志的经度和纬度,但只有日志"mSecurityInputMethodService is null"mSecurityInputMethodService在logcat中为空

这里的MainActivity.java

public class MainActivity extends Activity { 
int response; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Button button = (Button)findViewById(R.id.button); 
    button.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      onbutclick(); 
     } 
    }); 

} 
public void onbutclick(){ 
    LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
    if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){ 
     Location loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
     if(loc != null){ 
      Log.d("Latitude",Double.toString(loc.getLatitude())); 
      Log.d("Longitude",Double.toString(loc.getLongitude())); 
     } 

    }else{ 
     ActivityCompat.requestPermissions(this,new String[] {Manifest.permission.ACCESS_FINE_LOCATION},response); 
     Intent inte = getIntent(); 
     finish(); 
     startActivity(inte); 
    } 
} 

我也该清单文件中使用<uses-permission>。我真的很感谢"mSecurityInputMethodService is null"的真正含义。

+5

您是否在华为设备上进行测试? – Klatschen

+0

@Klatschen是的,我是。 –

+1

也有同样的问题,华为Honor 7,Android 6.0。由于这是一条INFO日志消息,因此无需担心。我的猜测是这是华为内部的日志消息。 (可以在这里确认,因为它很烦人) –

回答

21

对于我的华为设备的以下帮助:

表盘:

*#*#2846579#*#* 

和显示的隐藏菜单。进入“后台设置” - >“日志设置”并启用日志级别。

+0

老兄,你真的救了我很多痛苦。 –

+0

谢谢你!我有同样的问题,现在修复 –