2011年4月23日土曜日

Android ビルドバージョンで処理を分岐する

Build.VERSION クラスで端末のビルドバージョンを取得することができます。

Build.VERSION.SDK_INT には、フレームワークの SDK バージョンが数値ではいっています。この数値は Build.VERSION_CODES で定数として定義されているので、比較することで任意のビルドバージョンで処理をわけることができます。


if(Build.VERSION.SDK_INT == Build.VERSION_CODES.GINGERBREAD_MR1) {

// 2.3.3 向けの処理


} else {

 // 2.3.3 以外向けの処理

}



if(Integer.parseInt(Build.VERSION.SDK) == Build.VERSION_CODES.CUPCAKE) {
// for 1.5
}
else {
switch(Build.VERSION.SDK_INT) {
case Build.VERSION_CODES.DONUT:
// for 1.6
break;
case Build.VERSION_CODES.ECLAIR_MR1:
// for 2.1
break;
case Build.VERSION_CODES.FROYO:
// for 2.2
break;
case Build.VERSION_CODES.GINGERBREAD:
// for 2.3
break;
case Build.VERSION_CODES.GINGERBREAD_MR1:
// for 2.3.3
break;
case Build.VERSION_CODES.HONEYCOMB:
// for 3.0
break;
default:
break;
}
}



・ 主な Build.VERSION_CODES の定数

 CUPCAKE
   May 2009: Android 1.5

 DONUT
   September 2009: Android 1.6

 ECLAIR
   November 2009: Android 2.0

 ECLAIR_0_1
   December 2009: Android 2.0.1

 ECLAIR_MR1
   January 2010: Android 2.1

 FROYO
   June 2010: Android 2.2

 GINGERBREAD
   November 2010: Android 2.3

 GINGERBREAD_MR1
   Almost newest version of Android, version 2.3.3

 HONEYCOMB
   Newest version of Android, version 3.0


# Build.VERSION.SDK に数字以外の文字列が入ると
# NumberFormatException になります。
# 安全なコードにしたいなら、try-catch するか、
# if(Build.VERSION.SDK.equals(String.valueOf(Build.VERSION_CODES.CUPCAKE)))
# なのかなぁ。
# ちなみに、Android Developers Blog: How to have your (Cup)cake and eat it too
# では、parseInt() 使ってました。

  

39 件のコメント:

  1. On your place I would make a video about this build version and publish it on youtube. If you want to lead youtube channel all the time use this site https://soclikes.com/ to get subscribers for your channel

    返信削除
  2. ビデオを作成してtiktokに投稿したい場合は、私はあなたにアドバイスしますTiktokの「いいね」の購入。

    返信削除
  3. This is very interesting, You are a very skilled blogger.
    토토사이트
    경마사이트
    경마

    返信削除
  4. I am overwhelmed by your post with such a nice topic. Feel free to visit my website, thank you! 토토

    返信削除
  5. It is really a great and helpful piece of info. I am glad that you shared this helpful information with us. Please keep us updated. Feel free to visit my website, thank you! 카지노사이트

    返信削除
  6. The beauty of the words is that the same words can be used in a variety of ways to provide a different and unique meaning. You possess the nice and quite impressive style of writings that has touched my heart and soul. I shall come again to soothe my knowledge and skills thirst. Feel free to visit my website, thank you! 파워볼사이트

    返信削除
  7. I am sure this piece of writing has touched all the internet users, its really really fastidious piece of writing on building up new weblog. Feel free to visit my website, thank you! 바카라사이트

    返信削除
  8. Thank you for sharing this information. I read your blog and I can't stop my self to read your full blog. Again Thanks and Best of luck to your next Blog in future.스포츠토토

    返信削除
  9. mobil sohbet https://mobil.sohbet.org

    返信削除
  10. Thanks for sharing such great information. It was really helpful to me. 릴게임

    返信削除
  11. This is one very interesting post. I like the way you write and I will bookmark your blog to my favorites. 바카라사이트

    返信削除
  12. What an awesome post, I just read it from start to end your blog post. Really an informative blog. 바카라사이트

    返信削除
  13. Thank you for sharing this useful article , and this design blog simple and user friendly regards. 바둑이게임

    返信削除
  14. Amazing article. Your blog helped me to improve myself in many ways thanks for sharing this kind of wonderful informative blogs in live. I have bookmarked more article from this website. Such a nice blog you are providing. Feel free to visit my website; 바카라사이트닷컴

    返信削除
  15. spins. Almost every game is free spins. Let's get to know betflix

    返信削除
  16. This is very well written information. I am sure anyone using it will benefit from it. Keep it up! You can get Indian visa online easily.

    返信削除
  17. At least nine people are also known to have died since Saturday while swimming in lakes and rivers.
    카지노 드라마

    返信削除
  18. But this was one of the first times the heat has caused such an issue in England, remarkably at its most northerly international ground.

    온라인 카지노

    返信削除


  19. will be praised anywhere. I am a columnist This post is really the best on this valuable topic 검증카지노

    返信削除