我寫了一個小應用程序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日誌消息,因此無需擔心。我的猜測是這是華爲內部的日誌消息。 (可以在這裏確認,因爲它很煩人) –