Getting an Access error with PrintWriter

edited January 2017 in Android Mode

I have a PrintWriter object named fileOut which I initialize with createWriter("testfile.txt"). I then print to it, flush and close it.

It will not compile, repeatedly giving me two of these errors:

check = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Manifest.permission.READ_EXTERNAL_STORAGE cannot be resolved

I have both READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE enabled properly.

Anyone experience this before?

Answers

  • This link could help: http://stackoverflow.com/questions/33134276/cannot-request-read-external-storage-permission

    What OS/Processing version/Android mode version please?

    Kf

  • Answer ✓

    @CantSayIHave===

    if platform >22 && android mode < 4 try:

    check = ContextCompat.checkSelfPermission(this.getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE)

    (if check== false then ContextCompat.requestPermissions(getActivity().....)

  • @akenaton

    How do you keep track of API > 22? Is it possible to access what API a phone can handle on real time? One strategy I would consider is to adjust the min API in the manifest. This will limit the access of the app from other devices with older APIs. Is that a good idea? If I can access the API version on the phone, could I implement a way so the code works for API<22 and API>22?

    Kf

  • edited January 2017 Answer ✓

    @kfrajer=== BUILD is your friend::

        if(Build.VERSION.SDK_INT > 22){
    
            }else{
            }
    

    Build.VERSION.SDK_INT returns API level used by the phone BUILD.VERSION.RELEASE returns the OS system: 4.4.4 for kitKat etc

    --As for the Manifest, yes, you can and must adjust the MinSDK in it; if you don't default value used is 1....So it is a good idea -

    -- As for coding for API-- && API++ yes, you can do that: globally appCompatV4 or V7 or... is made for that; yet in many cases you have only to have a look to the API and what changes are happened: so using (Build.) (once!!!!) you can write as i have done: if...use this method){else..... use this one...

Sign In or Register to comment.