Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – java.lang.SecurityException“gps”位置提供程序需要ACCESS_FINE_LOCATION权限大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
所以这是我的MyLOCATIOnListener类
package com.example.gpslocater;

import android.content.Context;
import android.LOCATIOn.LOCATIOn;
import android.LOCATIOn.LOCATIOnListener;
import android.os.bundle;
import android.widget.TextView;
import android.widget.Toast;

public class MyLOCATIOnListener implements LOCATIOnListener {

        public TextView mLOCATIOntextView;
    Context mContent;
    public MyLOCATIOnListener(Context context) {
        mContent = context;
    }
    @Override
    public void onLOCATIOnChanged(LOCATIOn LOCATIOn) {

        LOCATIOn.getLatitude();
        LOCATIOn.getLongitude();

        String Text = "My current LOCATIOn is :" + 
        "Latitude = " + LOCATIOn.getLatitude() +
        " Longitude = " + LOCATIOn.getLongitude();
        //figure out a way to make it display through a text view
        mLOCATIOntextView.setText(Text);
    }

    @Override
    public void onProviderDisabled(String provider) {
        Toast.makeText(mContent,"Gps Disabled",Toast.LENGTH_SHORT).show();

    }

    @Override
    public void onProviderEnabled(String provider) {
        Toast.makeText(mContent,"Gps Enabled",Toast.LENGTH_SHORT);


    }

    @Override
    public void onStatusChanged(String provider,int status,Bundle extras) {
        // TODO Auto-generated method stub

    }

}

这是我的GPS活动课程

public class GPSActivity extends Activity {
    private Button mGPSButton;
    private TextView mLatitudeTextView;
    private TextView mLongitudeTextView;
    private LOCATIOnManager mLOCATIOnManager;
    private LOCATIOnListener mLOCATIOnListener;

    @Override
    protected void onCreate(Bundle savedInstanceStatE) {
        super.onCreate(savedInstanceStatE);
        setContentView(R.layout.activity_gps);

        mLOCATIOnManager = (LOCATIOnManager)getSystemservice(Context.LOCATION_serviCE);
        mLOCATIOnListener = new MyLOCATIOnListener(null);
        mGPSButton = (Button)findViewById(R.id.press_button);
        mGPSButton.setOnClickListener(new View.onClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                mLOCATIOnManager.requestLOCATIOnupdates(LOCATIOnManager.GPS_PROVIDER,mLOCATIOnListener);
            }
        });
    }


    @Override
    public Boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.g,menu);
        return true;
    }

}

现在,当我运行它可以工作,但按下按钮后程序停止响应有很多错误消息

有一条错误消息说java.lang.SecurityException“gps”位置提供程序需要ACCESS_FINE_LOCATION权限,我是否必须添加,如果是这样,我在哪里添加它?我认为这是我的程序崩溃的原因.

@H_674_13@解决方法
从提供的logcat有意义.
在清单中添加内容
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

大佬总结

以上是大佬教程为你收集整理的android – java.lang.SecurityException“gps”位置提供程序需要ACCESS_FINE_LOCATION权限全部内容,希望文章能够帮你解决android – java.lang.SecurityException“gps”位置提供程序需要ACCESS_FINE_LOCATION权限所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。