我写了一个小应用程序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"
的真正含义。
您是否在华为设备上进行测试? – Klatschen
@Klatschen是的,我是。 –
也有同样的问题,华为Honor 7,Android 6.0。由于这是一条INFO日志消息,因此无需担心。我的猜测是这是华为内部的日志消息。 (可以在这里确认,因为它很烦人) –