mSecurityInputMethodService 在 logcat 中为空

mSecurityInputMethodService is null in logcat

我写了一个小 android 应用程序,它应该显示智能手机的当前位置(最后已知位置)。虽然我复制了示例代码,并尝试了其他几种解决方案,但似乎每次都出现相同的错误。我的应用程序包含一个按钮。按下按钮应该 log 经度和纬度,但只记录 "mSecurityInputMethodService is null".

这是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);
    }
}

我还在 Manifest 文件中使用了 <uses-permission>。如果能解释 "mSecurityInputMethodService is null" 的真正含义,我将不胜感激。

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

拨号:

*#*#2846579#*#*

并显示隐藏菜单。转到 "Background Setting" -> "Log setting" 并启用日志级别。

华为手机禁用logcat,对上述答案的小改进

拨号:

*#*#2846579#*#*

并显示隐藏菜单。转到 "Background Setting" -> "Log setting" 并启用日志级别。

具体启用:AP LogCharge LogSleep Log.

来源:https://www.xda-developers.com/huawei-phones-disable-logcat-heres-how-to-restore-access/

我在访问键盘时遇到了同样的错误,但键盘没有显示。并且打开日志没有帮助。原来我用的是google键盘,换成huawei swype就解决了

而不是:

log.d(...);

使用

log.i(...);

正如其他答案所建议的,您需要特殊权限才能阅读调试消息。