Context.getExternalFilesDirs(null) is not defined - android

I am trying context.getExternalFilesDirs(null) to get paths for mounted storages. I intend to use this method keeping in view the new restrictions imposed by android in Kitkat. When I write statement to make a call to the method it gets underlined in RED with message as shown in image below:
I have checked all installations required to support API level 19 and everything seems fine.
My application is targeted for API 19 with minimum sdk version set to 16.
I have checked it a lot and looks like no one has faced this issue. I don't know what can possibly go wrong here but if you have any idea that where I am doing wrong please identify. Thank you

This is how I resolved the above issue.Right side click on Project -> Properties -> Android -> set Project Build Target to > Android 4.4.2 -> Apply

Check the documentation ,
getExternalFilesDirs()
has been added with API 19, and your min SDK is 16, you have to check that when you run on devices less than API 19 and there by organize your functionalities.You can Use TargetAPI annotation and then red underline will be removed.

Related

Find all issues saying `require API level` in Intellij / Android Studio

I want find all issues saying call requires some API level in whole project.
Call requires API level 21 (current min is 19):
android.content.res.Resources#getDrawable
I could see its issue id is Issue id: NewApi. But I can not find a inspection name for same. Basically I want run inspection by name to get all these issues.
You can find the name in Settings -> Inspections (there is no filter by id, though)
In your case it's Calling new methods on older versions.
its very Simple
In Android Studio Right click over any class file.
Select Analyze and select Inspect Code
Under the Popup window select the hierarchy like Whole Project, Module App
or specific file.
Click OK
it will generate the report, by this report you can find all locations of implementation.

import project for low api, stylev21 not found

I research material design project for 4.x API, It seem too many problems in style values, always style.... (in v-21) not found. I think v-21 is only build with api 21. But I want to build for 4.x API, do anyone know problem?
Here is some project in Github i found:
https://github.com/wasabeef/awesome-android-ui
https://github.com/rey5137/material
I use eclipse too. Change ANdroid API 21,22,23 but it still not work
The Log say : no resource found that matches the given name "TextAppearance.Appcompat.Body1"
Here is my picture:
OTHER QUESTION:
The Author say this material project can run on API 2.x -> 4.x , but why it need to build with API 21 -> 23? So can lower device can run it?
Set compileSdkVersion 23 or 21 or above in your build.gradle file.
The Log say : no resource found that matches the given name
"TextAppearance.Appcompat.Body1"
This is because you might not have imported AppCompat Library to your Eclipse Project.
The Author say this material project can run on API 2.x -> 4.x , but
why it need to build with API 21 -> 23? So can lower device can run
it?
Yes, Its always a good practice to build your App with the latest API version as this will include all the updated resources which might be not available in previous versions of Android. However, this will not affect your APK size in anyways.

no resource identifier found for android:elevation

As per guidelines here for Android L development, I used android:elevation property in my application, but it shows the following error:
No resource identifier found for attribute elevation in package
android
I am using eclipse and I have downloaded the latest version just 2 days ago.
I have also set my target sdk as API level 21 and minimum as API level 14. I have also installed the latest updates on sdk-build tools shown in sdk manager.
Anyone know the solution? plz help me.
1) Select Project > Right Click > Properties > Check Android L > apply > Ok
2) android:minSdkVersion="L"
Hope this will work for you.
One thing worth noting is that Android Lollipop corresponds to API level 21. There is no such thing (yet) as API level 22.
You should be able to solve your problem by setting android:minSdkVersion and android:targetSdkVersion to "21".
Select Project, then Properties, then Android and tick Android 5.0. Ignore all the answers telling you to set android:minSdkVersion. Android is designed to ignore stuff inside elements it does not understand just so that in this case you can apply elevation when running on lollipop devices and it is ignored on earlier devices.
You can hide the remaining lint warning in the xml file by adding tools:ignore="NewApi" in the element. This needs xmlns:tools="http://schemas.android.com/tools" specified in the root element.
AppCompat v21 allows a fair bit of Material Design to be used on pre-lollipop devices, but I've yet to work out how to add it to a project in Eclipse.
android:elevation or View.setElevation() is introduced since Android API 21. So, if you set android:minSdkVersion="14", it's not OK. android:minSdkVersion="14" is integrant.

adding android:widgetCategory="keyguard|home_screen" while still supporting older sdk

I am trying to modify my widget so that it supports being placed on 4.2 lockscreens. However I still want to support older SDK's.
I added
android:widgetCategory="keyguard|home_screen"
to my appwidget-provider in res/xml, but eclipse complains that there is "no resource identifier found for attribute widetCategory in package android'
If I raise the minSdkVerion to 17 everything works fine, but I want to still support older SDKs.
I have tried using resource qualifiers creating a separte res/xml-v17/mywidget.xml and only adding the tag there, but the error still appears.
Thanks for any help.
Edit:
I figured it out. using a res/xml-v17/ folder is the answer. I just had to change the build target for my project to 17 / 4.2.
I think that setting targetSdk to 17 is enough. XML elements that do not make sense on older SDKs are simply ignored.
No need to put mywidget.xml into res/xml-v17 folder
Put a copy of your mywidget.xml in res/xml-v17/ folder.
This targets Android 4.2 and all new "properties on the appwidget-provider element will be avaible. Also right click your project in eclipse and change build target to: API level 17/ Android 4.2
I saw your Edit. But i think this makes it more clear that this question have an answer.
UPDATE: I can confirm Tomáš Hubálek answer. the xml-v17 is not needed. Changing Build target is enough. Right click your project in eclipse and change build target to: API level 17/ Android 4.2

targetSdkVersion not similar in android manifest as selected while project creation

I am creating a project in android using eclipse.
Now my problem is when i create a android application project, I set Build Sdk version to 4.1 (API 16). But when i saw in manifest file the android:targetSdkVersion="15" . Can anyone explain me why this is happening ? see the below screenshots.
Thanks in advance
Updated Answer:
Here it goes,
Solution is,
goto:
Your
Directory\android-sdk-windows\tools\templates\projects\NewAndroidApplication\root
Open :
AndroidManifest.xml.ftl File
Change :
default :
<uses-sdk android:minSdkVersion="${minApi}"
android:targetSdkVersion="${targetApi}" />
Modified :
<uses-sdk android:minSdkVersion="${minApi}"
android:targetSdkVersion="${buildApi}" />
So the Problem goes here:
In the ftl file the attribute name ${targetApi} has been set, but we are selecting the buildApi value in the project creation window.
${targetApi} or ${buildApi} default value is the higher version , that means in your SDK tool it is API 15. So it is always 15 in the Manifest.
If you tried to create a new project with target API less than 10 or more than 15 anything , in the manifest it will be denoted as 15 only always.
Try this:
Create a project with API target 8 and see , manifest target will be 15 only. (Before modify the ftl file).
But project.properties has been updated properly.
So if you change ${targetApi} to ${buildApi} in the Manifest.xml.ftl, the problem solved.
It is a possible error in SDK tools revision 20, Even i updated the SDK tools itsn't resolved in the recent revision also.
Hope this one might be helpful for somebody, those who facing the same.
Older Answer:
It is showing for me too. But in my case, I selected API 14 and it is showing android:targetSdkVersion="15" in the manifest.
I guess some reason should be there... 4.0 or 4.2 , it is assigning 4.1 in the manifest... Or may be a bug with Eclipse IDE. Why cant you update the newer version of Eclipse IDE and try it out. This might be a IDE Problem only.
Can you see that Right click- Properties - Android , Checked one is same what you selected in the beginning.
And also project.properties has the same version what you selected in the beginning.
well the Project target you set is got set in the default.properties file if you change that and save it the the attached sdk will change you can try it.
the entry in menifiest is used after compilation on the device . don't know why it is taking wrong value.but in my eclipse it takes only minsdkversion and its value is same what i entered on start.however my point is it does not matter

Categories

Resources