2.3 Supporting Different Platform Versions 支持不同的平台版本

本文介绍了如何让应用程序在不同版本的Android系统上运行良好。包括指定最低和目标API级别、在运行时检查系统版本、使用Android支持库以及利用平台样式和主题等技巧。

While the latest versions of Android often provide great APIs for your app, you should continue to support older versions of Android until more devices get updated. This lesson shows you how to take advantage of the latest APIs while continuing to support older versions as well.

虽然最新版本的Android通常为您的应用程序提供了很棒的API,但应该继续支持较旧版本的Android,直到更新设备更新。 本课程向您展示如何利用最新的API,同时继续支持旧版本。

The dashboard for Platform Versions is updated regularly to show the distribution of active devices running each version of Android, based on the number of devices that visit the Google Play Store. Generally, it’s a good practice to support about 90% of the active devices, while targeting your app to the latest version.

平台版本的仪表板会定期更新,以显示运行每个版本的Android的活动设备的分布情况,具体取决于访问Google Play商店的设备数量。 一般来说,在将应用程序定位到最新版本的同时,支持大约90%的活动设备是一个很好的做法。

Tip: In order to provide the best features and functionality across several Android versions, you should use the Android Support Library in your app, which allows you to use several recent platform APIs on older versions.

提示:为了在多个Android版本中提供最佳功能和功能,您应该在应用程序中使用Android支持库,从而允许您在旧版本上使用几种最新的平台API。

Specify Minimum and Target API Levels

指定最低和目标API级别

The AndroidManifest.xml file describes details about your app and identifies which versions of Android it supports. Specifically, the minSdkVersion and targetSdkVersion attributes for the <uses-sdk> element identify the lowest API level with which your app is compatible and the highest API level against which you’ve designed and tested your app.

AndroidManifest.xml文件描述了您的应用程序的详细信息,并标识了其支持的Android版本。 具体来说,<uses-sdk>元素的minSdkVersiontargetSdkVersion属性标识了您的应用程序兼容的最低API级别,以及您设计和测试应用程序的最高API级别。

For example:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" ... >
    <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15" />
    ...
</manifest>

As new versions of Android are released, some style and behaviors may change. To allow your app to take advantage of these changes and ensure that your app fits the style of each user's device, you should set the targetSdkVersion value to match the latest Android version available.

随着新版Android的发布,一些风格和行为可能会改变。 为了让您的应用程序能够利用这些更改,并确保您的应用程序适合每个用户设备的风格,您应该将targetSdkVersion值设置为与最新版本的Android版本相匹配。

Check System Version at Runtime

在运行时检查系统版本

Android provides a unique code for each platform version in the Build constants class. Use these codes within your app to build conditions that ensure the code that depends on higher API levels is executed only when those APIs are available on the system.

Android在Build常量类中为每个平台版本提供了一个唯一的代码。 在您的应用程序中使用这些代码来构建条件,以确保仅在系统上提供这些API时才执行依赖于更高API级别的代码。

private void setUpActionBar() {
    // Make sure we're running on Honeycomb or higher to use ActionBar APIs
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        ActionBar actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
}

Note: When parsing XML resources, Android ignores XML attributes that aren’t supported by the current device. So you can safely use XML attributes that are only supported by newer versions without worrying about older versions breaking when they encounter that code. For example, if you set the targetSdkVersion="11", your app includes the ActionBar by default on Android 3.0 and higher. To then add menu items to the action bar, you need to set android:showAsAction="ifRoom" in your menu resource XML. It's safe to do this in a cross-version XML file, because the older versions of Android simply ignore the showAsAction attribute (that is, you do not need a separate version in res/menu-v11/).

注意:解析XML资源时,Android会忽略当前设备不支持的XML属性。 因此,您可以安全地使用仅由较新版本支持的XML属性,而不必担心在遇到该代码时旧版本中断。 例如,如果您设置targetSdkVersion="11",则应用程序在Android 3.0及更高版本上默认包含ActionBar。 然后将菜单项添加到操作栏,您需要在菜单资源XML中设置android:showAsAction="ifRoom"。 可以在跨版本的XML文件中做到这一点,因为旧版本的Android只是忽略showAsAction属性(也就是说,在res/menu-v11/中不需要单独的版本)。

Use Platform Styles and Themes

使用平台样式和主题

Android provides user experience themes that give apps the look and feel of the underlying operating system. These themes can be applied to your app within the manifest file. By using these built in styles and themes, your app will naturally follow the latest look and feel of Android with each new release.

Android提供用户体验主题,为应用程序提供底层操作系统的外观和感觉。 这些主题可以应用到清单文件中的应用程序。 通过使用这些内置的样式和主题,您的应用程序将自然地遵循Android的最新外观和每个新版本的感觉。

To make your activity look like a dialog box:

要使您的活动看起来像一个对话框:

<activity android:theme="@android:style/Theme.Dialog">

To make your activity have a transparent background:

要使您的活动具有透明背景:

<activity android:theme="@android:style/Theme.Translucent">

To apply your own custom theme defined in /res/values/styles.xml:

要应用您定制在/res/values/styles.xml中的自定义主题:

<activity android:theme="@style/CustomTheme">

To apply a theme to your entire app (all activities), add the android:theme attribute to the <application> element:

要将主题应用于整个应用程序(所有活动),请将android:theme属性添加到<application>元素中:

<application android:theme="@style/CustomTheme">

For more about creating and using themes, read the Styles and Themes guide.

有关创建和使用主题的更多信息,请阅读Styles and Themes指南。

转载于:https://www.cnblogs.com/youseiraws/p/7016053.html

### 光流法C++源代码解析与应用 #### 光流法原理 光流法是一种在计算机视觉领域中用于追踪视频序列中运动物体的方法。它基于亮度不变性假设,即场景中的点在时间上保持相同的灰度值,从而通过分析连续帧之间的像素变化来估计运动方向和速度。在数学上,光流场可以表示为像素位置和时间的一阶导数,即Ex、Ey(空间梯度)和Et(时间梯度),它们共同构成光流方程的基础。 #### C++实现细节 在给定的C++源代码片段中,`calculate`函数负责计算光流场。该函数接收一个图像缓冲区`buf`作为输入,并初始化了几个关键变量:`Ex`、`Ey`和`Et`分别代表沿x轴、y轴和时间轴的像素强度变化;`gray1`和`gray2`用于存储当前帧和前一帧的平均灰度值;`u`则表示计算出的光流矢量大小。 #### 图像处理流程 1. **初始化和预处理**:`memset`函数被用来清零`opticalflow`数组,它将保存计算出的光流数据。同时,`output`数组被填充为白色,这通常用于可视化结果。 2. **灰度计算**:对每一像素点进行处理,计算其灰度值。这里采用的是RGB通道平均值的计算方法,将每个像素的R、G、B值相加后除以3,得到一个近似灰度值。此步骤确保了计算过程的鲁棒性和效率。 3. **光流向量计算**:通过比较当前帧和前一帧的灰度值,计算出每个像素点的Ex、Ey和Et值。这里值得注意的是,光流向量的大小`u`是通过`Et`除以`sqrt(Ex^2 + Ey^2)`得到的,再乘以10进行量化处理,以减少计算复杂度。 4. **结果存储与阈值处理**:计算出的光流值被存储在`opticalflow`数组中。如果`u`的绝对值超过10,则认为该点存在显著运动,因此在`output`数组中将对应位置标记为黑色,形成运动区域的可视化效果。 5. **状态更新**:通过`memcpy`函数将当前帧复制到`prevframe`中,为下一次迭代做准备。 #### 扩展应用:Lukas-Kanade算法 除了上述基础的光流计算外,代码还提到了Lukas-Kanade算法的应用。这是一种更高级的光流计算方法,能够提供更精确的运动估计。在`ImgOpticalFlow`函数中,通过调用`cvCalcOpticalFlowLK`函数实现了这一算法,该函数接受前一帧和当前帧的灰度图,以及窗口大小等参数,返回像素级别的光流场信息。 在实际应用中,光流法常用于目标跟踪、运动检测、视频压缩等领域。通过深入理解和优化光流算法,可以进一步提升视频分析的准确性和实时性能。 光流法及其C++实现是计算机视觉领域的一个重要组成部分,通过对连续帧间像素变化的精细分析,能够有效捕捉和理解动态场景中的运动信息
微信小程序作为腾讯推出的一种轻型应用形式,因其便捷性与高效性,已广泛应用于日常生活中。以下为该平台的主要特性及配套资源说明: 特性方面: 操作便捷,即开即用:用户通过微信内搜索或扫描二维码即可直接使用,无需额外下载安装,减少了对手机存储空间的占用,也简化了使用流程。 多端兼容,统一开发:该平台支持在多种操作系统与设备上运行,开发者无需针对不同平台进行重复适配,可在一个统一的环境中完成开发工作。 功能丰富,接口完善:平台提供了多样化的API接口,便于开发者实现如支付功能、用户身份验证及消息通知等多样化需求。 社交整合,传播高效:小程序深度嵌入微信生态,能有效利用社交关系链,促进用户之间的互动与传播。 开发成本低,周期短:相比传统应用程序,小程序的开发投入更少,开发周期更短,有助于企业快速实现产品上线。 资源内容: “微信小程序-项目源码-原生开发框架-含效果截图示例”这一资料包,提供了完整的项目源码,并基于原生开发方式构建,确保了代码的稳定性与可维护性。内容涵盖项目结构、页面设计、功能模块等关键部分,配有详细说明与注释,便于使用者迅速理解并掌握开发方法。此外,还附有多个实际运行效果的截图,帮助用户直观了解功能实现情况,评估其在实际应用中的表现与价值。该资源适用于前端开发人员、技术爱好者及希望拓展业务的机构,具有较高的参考与使用价值。欢迎查阅,助力小程序开发实践。资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
### Java Appium Mobile Application Automation Testing #### Overview of Appium for Mobile Applications Appium represents an open-source, cross-platform test automation tool designed specifically for automating native, mobile web, and hybrid applications on iOS and Android platforms[^3]. This tool functions similarly to Selenium Server but extends its functionality by supporting both Android and iOS environments. For Android devices, Appium supports all versions starting from 2.3 onward, making it versatile across different device types and operating system levels. The setup process involves configuring targeted desired capabilities that define how tests should be executed through Appium[^2]. #### Setting Up Desired Capabilities in Java To initiate automated testing using Appium with Java, one must first configure the `DesiredCapabilities` object properly: ```java import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; import org.openqa.selenium.remote.DesiredCapabilities; import java.net.URL; public class TestSetup { public static void main(String[] args) throws Exception { URL url = new URL("http://localhost:4723/wd/hub"); DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("platformName", "Android"); caps.setCapability("deviceName", "emulator-5554"); // Replace with your emulator or real device name caps.setCapability("appPackage", "com.example.package"); caps.setCapability("appActivity", ".MainActivity"); AndroidDriver<MobileElement> driver = new AndroidDriver<>(url, caps); try { // Your test code here... } finally { driver.quit(); } } } ``` This configuration specifies essential parameters such as platform name (`platformName`) and specific details about the target application package (`appPackage`) along with activity (`appActivity`). These settings ensure proper initialization of the session between client-side scripts written in Java and the Appium server. #### Generating Detailed Reports After executing tests via Appium, comprehensive HTML reports can be generated automatically including logs from the Appium server and ADB commands used during execution[^5]. In case any failure occurs within these tests, relevant screenshots are captured alongside log information providing valuable insights into what went wrong. --related questions-- 1. How do you set up environment variables required for running Appium tests? 2. What tools integrate well with Appium for continuous integration pipelines? 3. Can you explain more about handling permissions when setting up desired capabilities? 4. Is there a way to parallelize multiple instances of Appium sessions efficiently? 5. Which programming languages besides Java support similar setups for Appium?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值