Voice Actions Activity code not found - android

I'm working with adding Voice Actions to my app. Documentation tells me to use the method isVoiceInteraction() in an activity however every time I run a build (command line or IDE) I get errors saying the method can't be found. My question is, why?
I decompiled the source of an Activity and saw the method is there when I target API 21.
Here's my default build config:
compileSdkVersion 21
buildToolsVersion '22.0.1'
defaultConfig {
minSdkVersion 16
targetSdkVersion 21
// version name and code set here
}
The method can be found if I change the compile, min, and target SDK version to android-MNC however that isn't what I need.
Why is my build not recognizing the any of the voice methods defined in an Activity (as of Android 5.0+)?
My confusion is that I'm working with a custom voice action. It was approved however I was told (from the Google Voice Actions Team) that I need to have my new APK submitted to the play store by August 7th, 2015. That seems odd because I don't think I can submit an APK targeting the preview SDK.

Voice Interactions is one of the features added in Android M - you'll need to ensure you follow the Preview SDK instructions and compile and target "android-MNC"

Related

How does Android Studio know about backwards compatibility issues?

I am trying to understand how Android Studio determines if a code is available in a certain API. When using MediaStore.setRequireOriginal, Android Studio warns me that "this call requires API level 29". Does Android Studio check that this code is available in previous Android version sources?
photoContentUri = MediaStore.setRequireOriginal(photoContentUri)
I am trying to understand how it knows this.
The linter just knows all the APIs in all the versions. You don't need to download all the previous Android version sources (I was wondering how Android Studio's Linter knew about older versions when I only had API level 29 and 30 sources downloaded on my machine).
As you can see, lint now has a database of the full Android API such that it knows precisely which version each API call was introduced in.
Lint API Check page
The Short Answer:
It's set by the developer, And Android Studio just compares your minSdkVersion set in build.gradle file with the required api level.
The Longer Answer:
When you get this warning on a method, just CTRL+click on it to go to the source class, and there you will find it annotated #RequiresApi or/and #TargetApi, for example :
class MediaStore{
#RequiresApi(api = 29)
#TargetApi(29)
void setRequiredOriginal(...){}
}
Your build.gradle file:
defaultConfig {
minSdkVersion 23
...
}
Android Studio compares minSdkVersion to #RequiresApi or/and #TargetApi at the time you call the method MediaStore.setRequiredOriginal(...); and warn you if minSdkVersion is less that the recommended api.
Please note that there are differences between #RequiresApi and #TargetApi, sometimes you find them used along with each other but sometimes just one of them.
For more about difference between the two see: https://stackoverflow.com/a/50578783/10005752
There is something in build.gradle of application module like:
defaultConfig {
minSdkVersion 23
targetSdkVersion 30
}
So you can change the "minSdkVersion" to 29, and the warning message disappear ...
And if not:
With android OS version >= 29: your code works normally
With android OS version <29: might be an exception occurs

Set the supported lowest supported Android version in a Nativescript app.

I've deployed a Nativescript app to Google Play for my beta testers to use. My app is only intended to support Android version 4.4 and above. So I thought setting this in the AndroidManifest would get the job done.
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="__APILEVEL__"/>
Yet once deployed the Play store is still saying that those running Android versions lower than 4.4 can still download the app. What else do I need to do to prevent this?
Follow the thread below where a solution is shown on how to modify your minimum SDK version with app.gradle
https://github.com/NativeScript/android-runtime/issues/575#issuecomment-251584253
Basically as Plamen5kov has shown, you have to do the following:
what you can do is go to app/App_Resources/Android/app.gradle and
change the default configuration to meet your requirements.
android {
defaultConfig {
minSdkVersion 19 ....
Gradle overrides the AndroidManifest.xml that's why you need to change
the configuration in gradle, rather than in the manifest file.

Find higher api 23 calls than minSdk 21

Hello there are some answer on this topic, but none which worked for me so far.
My build.gradle looks like this
compileSdkVersion 23
buildToolsVersion "23.0.3"
minSdkVersion 21
targetSdkVersion 23
Somewhere in my Fragments I called the method getContext() and that crashed the app on a Lollipop 5.0 device. It works fine on Marshmallow 6.0.
The Fragment is imported from the non support library package.
import android.app.Fragment;
and since I have compileSDK on 23 I can call the method getContext() withing the Fragment to get the Context.
This will lead to a crash on Lollipop 5.0 and 5.1 since that method was added with API 23 and not API 21,22.
My Question is, how can I find such high level calls in Android Studio when the min SDK is below that?
how can I find such high level calls in Android Studio when the min
SDK is below that?
AFAIK Android studio normally warn the developer whenever they are using any methods which is not completely backward compatible till minSDKVersion defined by the application. So, At that point of time, you can check out current version of device and call relevant other method accordingly.
However, for some reason its not showing any lint warning while calling getContext() method. So, It seems we have to deal with it now.
Go to
-> Analyze -> Inspect Code -> run code inspection
Then in the result view there is
"Project Name"
- Android > Lint > Correctness
- calling new methods in older versions
Under (calling new methods in older versions) all unavailable calls should be listed
Now that we're in 2022, I found a more appropriate solution.
Run the gradlew lint command in Terminal and waiting for it to finish will generate a report file.
Wrote HTML report to file:///C:/Users/Administrator/path/to/project/module/build/reports/lint-results-$flavorName$buildType.html
open this file in browser, find InlinedApi and NewApi and you will find all of it.

Android: able to install app for unsupported Android version

We're dropping support for Android 2.3 (API level 9) devices because most of our users have a newer Android version on their phones. I've updated the minimum SDK version to api level 14.
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
}
}
However I'm still able to install the app on Android 2.3 devices manually (not by store). Is this expected behavior or am I doing something wrong? I couldn't find the answer somewhere else.
Another strange issue is that Lint doesn't detect the correct api level.
listView.setFastScrollAlwaysVisible(true);
This results in the warning: Call requires api level 11 (current min is 9).
However my current minimum is now 14. So this indicates to me that i did something wrong. I tried cleaning and rebuilding the project, restarting Android Studio. It all didn't work.
Can anyone help me out?
Edit
Based on Sufians comment I started fiddling around with my gradle files and I came to the following solution. However some questions still remain.
My project structure looks like this:
android.gradle (top-level build file which contains SDK versions)
main module (contains base code for other modules)
build.gradle (apply from: '../android.gradle')
sub module A (module specific changes)
build.gradle (has dependency on main module)
sub module B (module specific changes)
build.gradle (has dependency on main module)
I have a top-level build file android.gradle which contains the SDK versions. My modules then include the build file by apply from: '../android.gradle'. If I put the minSdkVersion directly in de main module the warnings disappear. Is that the way it should be? or do I need to set an minSdkVersion for every submodule? Or is there another way so that the SDK versions can stay within the android.gradle file?
Ok... I finally realized that there is nothing wrong in my project structure. The only thing I needed to do was press the little 'Sync Project with Gradle Files' button. After that all errors disappear.
Also I concluded that it's possible to install unsupported apps manually.
However the Google Play Store should prevent users from installing or updating the app.
i have personally never developed anything for android but when installing apps the device has never complained when installing an .apk that wasn't supported by the OS version.
even when the store said it wasn't supported i'm always able to install it as a .apk so i think it can't really be blocked.
Yes, you can install the app manually on your device as long the minimum API level specified in your manifest is less than your device's API level.
When you upload your app to the store, the store will not show your app to users with devices having Android version less than the min API level specified (API level 9 in your case).
As for the Lint warnings, make sure that the minimum/maximum SDK versions in your manifest file match those specified in the build.gradle file.
and you can also make sure that new APIs are not executed on older API levels by checking the OS version in the code.
http://developer.android.com/reference/android/os/Build.VERSION.html
If I put the minSdkVersion directly in de main module the warnings
disappear. Is that the way it should be?
Your main module's minimum and target SDKs (i.e inside the build.gradle of the module) will be that of your application.
The project's build.gradle should not contain any of this information.
or do I need to set an
minSdkVersion for every submodule? Or is there another way so that the
SDK versions can stay within the android.gradle file?
Each module defines its own minimum SDK. If you're using a third party module/library, you better not change it, unless you know what you're doing.

Android: "configuration cannot be published" while Uploading APK to Play Store

Need help with an Android Play Store issue I've seen while trying to update our app.
The problem appears when the apk upload is done, and the following message shows up:
This configuration cannot be published for the following reason(s):
It is forbidden that a device upgrading from API levels in range 14-18 to API levels in range 19+ should downgrade from version 10 to version 9, which would occur when
Screen layouts containing any of [small, normal, large, xlarge] and
Features containing all of [android.hardware.LOCATION, android.hardware.location.GPS, android.hardware.screen.PORTRAIT, android.hardware.TOUCHSCREEN, android.hardware.WIFI].
Some devices are eligible to run multiple APKs. In such a scenario, the device will receive the APK with the higher version code.
What is somewhat strange is that the Play Store lists our supported API levels as 14-18, whereas our SDK settings are as follows:
/* build.gradle */
...
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "<my app id>"
minSdkVersion 14
targetSdkVersion 21
}
...
/* AndroidManifest.xml */
...
android:versionCode="10"
android:versionName="1.1.1" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
...
Another (perhaps minor) issue is that the following permission is listed under the APK DETAILS tab of the Play Store despite that we don't set this in our manifest file:
android.permission.CHANGE_WIFI_STATE
When we switch the build/target SDK version to 19 (as we previously did), Android Studio correctly complains that we are not using the latest Android version. Even then, we still see the upload problem.
Might there be something else in our configuration that is wrong?
Thanks in advance for your assistance!
OK, I finally managed to solve the issue.
Used aapt to see how Play Store would parse the apk
Found out that an external, closed-source library that I'm using sets a maxSdkVersion=18 in its manifest library
Obtained a version of the offending library that doesn't have the max SDK setting.
Recompiled the app and successfully uploaded to the play store.
An alternative to step 3 would have been to override the maxSdkVersion in my main AndroidManifest.xml file, or Disable Manifest Merger in Android Gradle Build in gradle, but Android Studio wasn't very cooperative on that front.
Admittedly, the error message on Play Store is rather cryptic and could be worded better.

Categories

Resources