无法将android更新为targetSdkVersion 33,没有android.权限,ACCESS_COARSE_LOCATION或android.权限,ACCESS_FINE_LOCATION

xghobddn  于 2023-03-16  发布在  Android
关注(0)|答案(1)|浏览(1168)

请帮助,我尝试更新Android targetSdkVersion到版本33.
我的身材。

compileSdkVersion 19
buildToolsVersion '26.0.2'
defaultConfig {
  minSdkVersion 14
  targetSdkVersion 19
}

安卓清单:

android:minSdkVersion="14"
android:targetSdkVersion="19"
uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" 
uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"

在我将targetSdkVersion(compileSdkVersion和buildToolsVersion)更新为33(在build.gradle和AndroidManifest.xml中)后,我遇到了这个异常:

`java.lang.RuntimeException: Unable to start activity ComponentInfo{activity.MainActivity}: 
java.lang.SecurityException: uid 10159 does not have android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3645)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.SecurityException: uid 10159 does not have android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.`

注意:

  • 在android 13上使用targetSdkVersion 19启动应用时的流程:权限屏幕出现在警告弹出窗口后,我正在使用旧版本Android,在登录屏幕后
  • 在Android 13上将targetSdkVersion更改为33后的流:登录屏幕是第一个屏幕,没有显示权限屏幕,我输入了登录凭据,然后抛出异常,我不确定为什么不先请求权限

谢谢
从以下行引发异常:位置gpsLocation = m位置管理器.getLastKnownLocation(位置管理器.GPS_PROVIDER);

public abstract class MyActivity extends AnaliticsActivity implements OnRefreshListener {
    ..........
    private GPSManager gpsManager;
    private Context mContext;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        mContext = this;

        initActivity();
        initHelpers();
        initActionBar();
    }
    
    private void initActivity() {

        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    private void initHelpers() {
        gpsManager = new GPSManager(getApplicationContext());
...
    }
    ........
}

public class GPSManager implements LocationListener {
    ...
    public GPSManager(Context context,) {
        // reference to the system Location Manager
        mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        Location gpsLocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        .....
    }
    ....
}
2vuwiymt

2vuwiymt1#

从Android 6开始,你需要request permissions at runtime .我找不到兼容机制的细节,但我怀疑当你的targetSdkVersion低于23时(这是Android 6)它在兼容模式下运行,并在开始时请求所有权限,就像在旧版本上一样。现在你更新了它超过23,你基本上说“我希望我的应用能在API 33”(see this Q&A)上正常运行,其中包含rntime权限。

相关问题