Android 6.0“gps”位置提供程序需要ACCESS_FINE_LOCATION权限

Android 6.0“gps”位置提供程序需要ACCESS_FINE_LOCATION权限,第1张

概述我在清单中定义了使用gps的所有预设.喜欢 “uses-permission android:name =”android.permission.ACCESS_FINE_LOCATION“/> “uses-permission android:name =”android.permission.ACCESS_COARSE_LOCATION“/> 每当我尝试在Android 6.0上打开此活动时,它 我在清单中定义了使用gps的所有预设.喜欢

“uses-permission android:name =”androID.permission.ACCESS_FINE_LOCATION“/>

“uses-permission androID:name =”androID.permission.ACCESS_COARSE_LOCATION“/>

每当我尝试在Android 6.0上打开此活动时,它都会停止此logcat消息.但适用于某些手机.有人可以帮助我弄明白,并提供解决方案.几天来我一直试图解决这个问题,以及如何解决这个问题.

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.data.smurf/org.data.smurf.Konkurranse}: java.lang.SecurityException: "gps" location provIDer requires ACCESS_FINE_LOCATION permission.   at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:3253)   at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)   at androID.app.ActivityThread.access00(ActivityThread.java:221)   at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)   at androID.os.Handler.dispatchMessage(Handler.java:102)   at androID.os.Looper.loop(Looper.java:158)   at androID.app.ActivityThread.main(ActivityThread.java:7224)   at java.lang.reflect.Method.invoke(Method.java)   at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)   at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:1120)Caused by java.lang.SecurityException: "gps" location provIDer requires ACCESS_FINE_LOCATION permission.   at androID.os.Parcel.readException(Parcel.java:1620)   at androID.os.Parcel.readException(Parcel.java:1573)   at androID.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:688)   at androID.location.LocationManager.requestLocationUpdates(LocationManager.java:908)   at androID.location.LocationManager.requestLocationUpdates(LocationManager.java:469)   at org.data.smurf.Konkurranse.onCreate(Konkurranse.java:197)   at androID.app.Activity.performCreate(Activity.java:6876)   at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)   at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:3206)   at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)   at androID.app.ActivityThread.access00(ActivityThread.java:221)   at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)   at androID.os.Handler.dispatchMessage(Handler.java:102)   at androID.os.Looper.loop(Looper.java:158)   at androID.app.ActivityThread.main(ActivityThread.java:7224)   at java.lang.reflect.Method.invoke(Method.java)   at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)   at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

这是我的Konkurranse /竞赛活动.我删除了与菜单和 *** 作栏无关的代码.

Public class Konkurranse Extends Activity {    /**     * Called when the activity is first created.     */    @OverrIDe    public voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        FacebookSdk.sdkInitialize(getApplicationContext());        Fresco.initialize(getApplicationContext());        setContentVIEw(R.layout.activity_konkurranse);        LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);        final com.facebook.Profile profile = com.facebook.Profile.getCurrentProfile();        final ProfilePictureVIEw profilePictureVIEw = (ProfilePictureVIEw) findVIEwByID(R.ID.profilepic);        final TextVIEw name = (TextVIEw) findVIEwByID(R.ID.name);        simpleDraweeVIEw = (SimpleDraweeVIEw) findVIEwByID(R.ID.profilePicture);        RoundingParams roundingParams = RoundingParams.fromCornersRadius(50f);        roundingParams.setRoundAsCircle(true);        simpleDraweeVIEw.getHIErarchy().setRoundingParams(roundingParams);        /// Logged IN \\        if (profile != null) {            profilePictureVIEw.getProfileID();            profilePictureVIEw.setProfileID(profile.getID());            name.setText(profile.getname());            simpleDraweeVIEw.setimageURI(profile.getProfilePictureUri(100,100));        }        final SharedPreferences sharedPrefs = getSharedPreferences("details",MODE_PRIVATE);        //After referencing your VIEws,add this.        final String nameStr = sharedPrefs.getString("name",null);        final String IDStr = sharedPrefs.getString("ID",null);        Accesstoken token = Accesstoken.getCurrentAccesstoken();        if (token != null) {            if (nameStr != null) name.setText(nameStr);            if (IDStr != null) profilePictureVIEw.setProfileID(IDStr);            simpleDraweeVIEw.setimageURI(profile.getProfilePictureUri(100,100));        }        //.. Do the same for other profile data        mobilnummer = (EditText) findVIEwByID(R.ID.mobilnummer);        buttongps = (button) findVIEwByID(R.ID.gps);        buttongps.setonClickListener(onbuttongpsClick);        buttonblue = (button) findVIEwByID(R.ID.bluetooth);        buttonblue.setonClickListener(onbuttonblueClick);        final LocationManager manager;        manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);        final ImageVIEw gpsimg = (ImageVIEw) findVIEwByID(R.ID.gpsstatus);        if (manager.isProvIDerEnabled(LocationManager.GPS_PROVIDER)) {            gpsimg.setimageResource(R.drawable.ok);        } else {            gpsimg.setimageResource(R.drawable.notok);  //not ok        }        // Register bluettoth Listener        bluetoothListener = new BluetoothListener() {            @OverrIDe            public voID onBluetoothOff() {                btimg.setimageResource(R.drawable.notok);  //not ok            }            @OverrIDe            public voID onBluetoothOn() {                btimg.setimageResource(R.drawable.ok);            }        };        IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);        registerReceiver(bluetoothListener,filter);        gpsListener = new GPSListener(this) {            @OverrIDe            public voID onGPSOff() {                gpsimg.setimageResource(R.drawable.notok);  //not ok            }            @OverrIDe            public voID onGPSOn() {                gpsimg.setimageResource(R.drawable.ok);            }        };        // Henter fra SharedPrefs        SharedPreferences prefs = getSharedPreferences(PREFS_name,MODE_PRIVATE);        String savedMobileNumber = prefs.getString("mobilnummer","");        mobilnummer.setText(savedMobileNumber);        final ImageVIEw tlfstatus = (ImageVIEw) findVIEwByID(R.ID.tlfstatus);        if (mobilnummer.getText().toString().length() >= 8) {            tlfstatus.setimageResource(R.drawable.ok);        } else {            tlfstatus.setimageResource(R.drawable.notok); //not ok        }        // OnCreate ends here.    }    public VIEw.OnClickListener onbuttongpsClick = new VIEw.OnClickListener() {        @OverrIDe        public voID onClick(VIEw v) {            Intent gpsOptionsIntent = new Intent(androID.provIDer.Settings.ACTION_LOCATION_SOURCE_SETTINGS);            startActivity(gpsOptionsIntent);        }    };    public VIEw.OnClickListener onbuttonblueClick = new VIEw.OnClickListener() {        @OverrIDe        public voID onClick(VIEw v) {            BluetoothAdapter mBluetoothAdapter;            mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();            if (!mBluetoothAdapter.isEnabled()) mBluetoothAdapter.enable();            ImageVIEw img = (ImageVIEw) findVIEwByID(R.ID.bluestatus);            img.setimageResource(R.drawable.ok);        }    };}
解决方法 Serg的回答是真的.使用Marshmallow(AndroID 6.0,API Level 23),permissiom系统已更改,现在您需要通过在运行时请求权限来处理Marshmallow设备.有一些库可以简化这个过程.

Easy Permissions就是其中之一.

总结

以上是内存溢出为你收集整理的Android 6.0“gps”位置提供程序需要ACCESS_FINE_LOCATION权限全部内容,希望文章能够帮你解决Android 6.0“gps”位置提供程序需要ACCESS_FINE_LOCATION权限所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1128085.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存