标签: android-api-levels

如何检查Android 12 API级别?

我正在尝试使用以下代码检查 android 12 API 级别。

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
{
     // Do something for Android 12 and above versions 
}
else
{
    // Do something for phones running an SDK before Android 12
}
Run Code Online (Sandbox Code Playgroud)

但在 android 12 beta 设备中运行应用程序时始终执行其他部分。这是检查 android 12 beta 版本的另一种方法吗?

android-studio android-api-levels android-12

4
推荐指数
1
解决办法
8061
查看次数

对于API级别为21的项目放弃appcompat是个好主意吗?

我正在启动一个API级别最低为21的项目,试图找出实现ActionBar的正确方法.官方文档从使用appcompat库开始,列出的主要优点是它保持兼容性回到7级.我甚至不想要预先安装Lollipop.我应该使用appcompat吗?放弃appcompat库有什么优点或缺点吗?

android android-appcompat android-actionbar android-5.0-lollipop android-api-levels

3
推荐指数
1
解决办法
257
查看次数

在Android中输入类android.support.design.widget.FloatingActionButton时出错

当我尝试构建应用程序时,它将显示android.view.InflateException在FloatingActionButton中?我真的不知道导致错误的原因.

Login.xml

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:background="@drawable/bg_image" >
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/lLayout_logincontainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_margin="40dp"
        android:orientation="vertical">
        <ImageView
            android:layout_width="130dp"
            android:layout_height="125dp"
            android:src="@drawable/project"/>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp">


            <EditText
                android:id="@+id/aTxt_UserName"
                style="@style/edittextstyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="User Name"
                android:imeOptions="actionNext"
                android:textColorHint="@color/white"
                >

            </EditText>


        </android.support.design.widget.TextInputLayout>

        <!--  Password Label -->
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginTop="8dp">

            <EditText
                android:id="@+id/eTxt_PassWord"
                style="@style/edittextstyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Password"
                android:inputType="textPassword"
                android:textColorHint="@color/white"
                android:textColor="@color/white" />

        </android.support.design.widget.TextInputLayout>

        <android.support.v7.widget.AppCompatButton
            android:id="@+id/btn_login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:layout_marginTop="3dp"
            android:background="@drawable/button_shape"
            android:padding="12dp"
            android:text="Login"
            android:textAllCaps="false"
            android:textColor="#ffffff" />
    </LinearLayout>


</RelativeLayout> …
Run Code Online (Sandbox Code Playgroud)

android android-layout floating-action-button android-api-levels

3
推荐指数
1
解决办法
1万
查看次数

使用非弃用时,应为弃用和非弃用变体调用两次 shouldInterceptRequest

我有覆盖 shouldInterceptRequest 方法的 webView:

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
    WebResourceResponse response = proxy.getWebResourceResponse(request.getUrl(), request.getMethod(), request.getRequestHeaders());
    if (response == null) {
        return super.shouldInterceptRequest(view, request);
    } else {
        return response;
    }
}

@SuppressWarnings("deprecation")
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
    WebResourceResponse response = proxy.getWebResourceResponse(Uri.parse(url), "GET", null);
    if (response == null) {
        return super.shouldInterceptRequest(view, url);
    } else {
        return response;
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是在 Lollipop+ 上这两种方法都被调用。所以我认为我应该指定弃用的版本应该只用于旧的 Android 版本。与 RequiresApi 正好相反......如果可以通过制作复制粘贴类并使用 if-else 根据 Android 版本选择类来解决这个问题......但这真的很难看。

更新 …

android android-webview android-min-sdk android-api-levels

3
推荐指数
1
解决办法
2980
查看次数

在 Java 中从 rgb 字符串创建颜色

这是我将字符串转换为颜色的代码:

public Color prepareColour(String str) {
    str.replace("#", "");
    float r = Float.valueOf(str.substring(0,1));
    float g = Float.valueOf(str.substring(2,3));
    float b = Float.valueOf(str.substring(4,5));
    Color color = Color.valueOf(r,g,b);
    return color;

}
Run Code Online (Sandbox Code Playgroud)

我收到以下调试错误:

错误:(16, 23) 错误:Color 类中的构造函数 Color 不能应用于给定类型;要求:未找到参数:float,float,float 原因:实际和形式参数列表的长度不同

但是,从 Android Studio 编译之前的建议是:

调用需要 API 级别 26(当前最小值为 17)......

我看到 2011 年的答案支持这种创建颜色的方式,所以它肯定适用于 API 17 并且不需要 26。

我试过清理和重建项目,以及str.substring用实际值替换,没有任何变化。

为什么代码不能编译?

java android android-api-levels

3
推荐指数
1
解决办法
6144
查看次数

我该如何降低最低SDK版本?

我正在开发一个Anrdoid应用程序.它差不多完成了.我刚刚注意到它minSdkVersion被设置为21.也许我在创建项目时忘了它.我想降低它,因为应用程序的用户可能会使用较旧的设备.

我不认为将#minSdkVersion改为10,坐下来并希望将来能够编译并运行良好.

我的想法是,我可以检查项目中使用的所有方法,它们的最低API级别,所以我可以知道我必须用替代品替换.但是,该项目有点大.逐个搜索所有方法的文档会花费很多时间.

是否可以自动列出项目中使用的Android API特定方法及其API级别?或以某种方式检测使用的方法所需的最高API级别?Android Studio知道这些数字,它也可以获取文档.或者,可以安全地更改minSdkVersiontargetSdkVersion更低的API级别以了解旧设备中不支持哪些方法,并且在我修复IDE将向我显示的所有错误/警告后,我的应用程序运行良好吗?

android android-studio android-api-levels

3
推荐指数
1
解决办法
1621
查看次数

“Android P”和“API Level 27”系统镜像有什么区别?

当前在此 Android Studio 对话框中的前两个系统映像条目之间有什么区别: Android Studio 系统镜像

您可以看到OreoAPI 27P都没有列在“API 级别分布图表”中。

Android 平台/API 版本分发

android android-studio android-api-levels android-9.0-pie

3
推荐指数
1
解决办法
3425
查看次数

如果 Google 只接受 Api 级别 26 或更高版本的应用程序,为什么我仍然可以发布 Api 级别低于 26 的应用程序?

最近我读了一本关于android的书,里面是这么说的Starting with august 2019, Google play will only accept apps built using Api 26 or newer。但最近我们发布了最低 Api 级别 23 的 Android 应用程序,并且已成功发布。任何人都可以说出场景是什么,或者书中的文档是错误的吗?

android google-play android-api-levels

3
推荐指数
1
解决办法
2380
查看次数

Android APIv29 FileNotFoundException EACCES(权限被拒绝)

为targetSdkVersion v29构建时,我无法访问存储。

这是我的gradle配置:

    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    ...
        minSdkVersion 15
        targetSdkVersion 29
Run Code Online (Sandbox Code Playgroud)

请注意,WRITE_EXTERNAL_STORAGE为进行构建时,将授予权限并且相同的设置可以正常工作targetSdkVersion 28

这是我的实现:

        val outputFolder = File(baseFolder + File.separator + "Output Folder")
        if (!outputFolder.exists()) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                Files.createDirectory(outputFolder.toPath()) //This allways returns false with targetSdkVersion 29
            } else {
                if (!outputFolder.mkdirs()) {
                    Log.e("SaveRaw", "Unable to create folder for audio recording")
                }
            }
        }

        outputFile = File("$baseFolder/Output Folder/$filename")
        try {
            fileOutputStream = FileOutputStream(outputFile)
        } catch (e: FileNotFoundException) {
            e.printStackTrace() // allways throwing exception …
Run Code Online (Sandbox Code Playgroud)

android filenotfoundexception kotlin android-external-storage android-api-levels

3
推荐指数
1
解决办法
212
查看次数

Android API-21 中 DateTimeFormatter 的替代方案

我的应用程序在运行时崩溃了。我第一次构建和编译它时它有效,但现在不行了。我认为这是由于“DateTimeFormatter”无法在我当前的 api 级别 21 中使用。有解决方法吗?

这是错误:

java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/format/DateTimeFormatter;
Run Code Online (Sandbox Code Playgroud)

以下是受影响的代码:

@RequiresApi(api = Build.VERSION_CODES.O)
public boolean checkTimeAgainstCurrentTime(String time) throws ParseException {
    boolean isTime = false;
    DateTimeFormatter parser = DateTimeFormatter.ofPattern("h:mma", Locale.ENGLISH);
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
    LocalTime theTime = LocalTime.parse(time, parser);
    Date time1 = new Date(System.currentTimeMillis());
    Date time2 = new SimpleDateFormat("HH:mm:ss").parse(theTime + ":00");
    time1.setHours(time2.getHours());
    time1.setMinutes(time2.getMinutes());
    SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date today = Calendar.getInstance().getTime();
    today.setHours(today.getHours()+8);
    if (today.after(time1)) {
        isTime = true;
    }
    // If true, means expired.
    return isTime;
}
Run Code Online (Sandbox Code Playgroud)

java android android-studio android-api-levels

3
推荐指数
1
解决办法
1834
查看次数