【问题标题】:Calls require API level调用需要 API 级别
【发布时间】:2014-04-22 08:23:27
【问题描述】:

我遇到了这个错误:

调用需要 API 级别 9(当前最低为 7)

但是,在遵循此处发布的一些解决方案之后,通过添加 uses-skd 部分仍然没有帮助:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app" >

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.app.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <uses-sdk
                    android:minSdkVersion="7"
                    android:targetSdkVersion="17" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

【问题讨论】:

  • 把这个android:minSdkVersion="7"改成android:minSdkVersion="9".你使用的api要求是9
  • uses-sdk 应该在清单标签下声明。不在activity 标签内...
  • 对于哪种方法,您会收到该错误?您想支持哪些安卓版本?

标签: android android-studio


【解决方案1】:

这应该是程序,uses-sdk 必须是 manifest 元素的直接子元素

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.xxxxx"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="19" />

【讨论】:

  • 嗨,苏坎。我按照您的指示将数字 7 更改为 9。错误仍然存​​在。
  • @McJim 检查更新的答案:)
  • 如果它有效:) 请接受我的回答快乐编码:)
【解决方案2】:

您可以在方法调用之前使用@SuppressLint("NewApi")。但是不要忘记添加android os版本检查以避免应用在旧设备上崩溃

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        // make your call;
}

【讨论】:

    【解决方案3】:

    这意味着,用户需要特定的最低 Android 版本(9 是 Android 2.3+)。换句话说:低于 2.1 的用户将无法使用该功能,因为会出现异常。所以改变:

    <uses-sdk android:minSdkVersion="9" ...
    

    清理 Lint 或者如果您仍然希望您的应用从第 7 级(Android 2.1+)开始可用,并且只想将该功能提供给“较新”设备,请使用 if 构造:

    if(Build.VERSION.SDK_INT >= 9) {
         // here goes the feature.
    }
    

    请记住,您的 IDE 可能无法识别这一点并仍然抛出一个 Lint 标记,因此只需为该方法或类或整个项目隐藏 Lint。

    【讨论】:

      猜你喜欢
      • 2022-01-23
      • 2021-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-11
      • 2016-12-18
      • 1970-01-01
      • 2013-02-26
      相关资源
      最近更新 更多