Android:支持不同的版本(Supporting Different Platform Versions)

 

Supporting Different Platform Versions(支持不同的版本)

       由于Android的新版本经常会提供大量的API,所以你应该同时支持旧版本直到更多的设备更新到新的版本。这篇文章就是讲如何在支持旧版本的基础上来使用新的APIS开发你自己的APK.

Google是通过Google play Store来统计设备Android 版本的使用比例和分布情况的。一般来讲,需要你的APP 支持大概90%的设备。

建议:为了在不同的Android版本中提供最好的功能和特性,在APP中应该使用Android Support Library.通过这个库,你可以在旧版本中使用新版本的APIS.

指定最小和目标API 级别

  AndroidManifest.xml文件详细描述了你的APP能够识别和支持的Android版本。该文件中,<uses-sdk>元素的minSdkVersiontargetSdkVersion属性指定了你的APP能够能兼容的最低API 级别和你设计以及测试APP的最高API级别。

 例如:

<manifest

 xmlns:android="http://schemas.android.com/apk/res/android" ... >

<uses-sdk android:minSdkVersion="4"

 android:targetSdkVersion="15" />

   ...

</manifest>

新的Android 版本发布以后,一些设计风格和行为可能会改变。为了允许你的APP利用这些改变并确保它能够适合每个用户设备的风格,你应该尽可能的设置targetSdkVersion为最新的Android版本。

在运行时核查系统的版本

       在Build常量类中,Android为每个平台的版本提供了一个识别码。在APP中使用这个识别码是为了确保系统能获得高版本APIS的时候,依赖于高版本APIS的代码才会执行。

例如:

Private void setUpActionBar()

{

//确保目前运行的版本至少是Honeycomb才使用ActionBar APIS

If(Build.VERSION.SDK_INT >=  Build.VERSION_CODES.HONEYCOMB)

      {

             ActionBar  actionBar  = getActionBar  ();

             actionBar.setDisplayHomeAsUpEnabled (true);

}

}

注意:在解析XML资源时, Android 会忽略当前设备部支持的XML属性。所以在设计XML文件的时候你不必担心因为旧版本不支持而打断这个解析过程,你可以放心的使用只有新版本才支持的XML属性。例如如果你设置targetSdkVersion="11",并且你的APP包含了Android 3.0或者更高才能支持的ActionBar.为了添加菜单项到ActionBar,你必须在菜单XML文件中设置android:showAsAction="ifRoom"。这种跨版本设计XML的做法是安全的,因为Android 旧版本会忽视showAsAction属性(所以你不需要单独建立一个res/menu-v11文件夹来定义这个menu菜单)。

使用平台风格和主题(Use Platform Styles and Themes)

Android 提供了一个用户体验主题,通过这个主题,APP 能够 look and feel 到潜在的的操作系统。这些主题可以通过manifest 文件应用到你的APP.通过这些内嵌的风格和主题,你的APP能够自然地follow the latest look and feel of Android with each new release.

让你的活动像一个对话框一样显示:

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

让你的活动背景透明:

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

应用自己定义的主题,客制化的主题定义在:/res/values/styles.xml

<activityandroid:theme="@style/CustomTheme">

将一个主题应用到整个的APP中:

<applicationandroid:theme="@style/CustomTheme">

### Qt Android Bluetooth Low Energy (BLE) Development Tutorial and Resources For developing applications that utilize Bluetooth Low Energy (BLE) on the Android platform using Qt, it is essential to understand how BLE support integrates within this framework. The integration of BLE into an Android application through Qt involves leveraging specific classes provided by Qt's Bluetooth module which supports both central and peripheral roles required for BLE communication[^1]. To start with a project setup, one must ensure that the development environment includes necessary components such as Qt Creator along with appropriate versions of Qt libraries supporting Android deployment. Additionally, ensuring that the target device has proper permissions set up in its manifest file allows access to Bluetooth functionalities. A typical approach begins by initializing `QLowEnergyController` object configured either as Central or Peripheral mode depending upon whether your app will act like a client connecting to other devices or serve as a server providing services respectively. For instance: ```cpp // Initialize controller acting as a central role. QLowEnergyController *controller = QLowEnergyController::createCentral(remoteDevice); connect(controller,&QLowEnergyController::connected,this,[this](){ qDebug() << "Connected!"; }); ``` Furthermore, developers can explore examples included within official documentation where detailed guidance alongside sample codes illustrate various aspects from scanning nearby peripherals until establishing connections and exchanging data packets over characteristics defined under GATT profiles[^2]. These tutorials provide comprehensive insights enabling efficient implementation while adhering best practices recommended when working specifically around mobile platforms including battery optimization techniques crucial during prolonged sessions involving continuous transmissions between paired units. --related questions-- 1. What are some common issues encountered while setting up BLE projects in Qt? 2. How does one handle connection states effectively in a Qt-based BLE application? 3. Can you explain more about optimizing power consumption for long-running BLE operations on Android? 4. Are there any differences in implementing BLE features across different operating systems supported by Qt?
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值