Quantcast
Viewing latest article 15
Browse Latest Browse All 500

Using Java code to detect device

This article will talk about how to using Java code to detect device.

Please kindly use ro.product.cpu.abilist and check every entry in it.

 

 recommand "getprop ro.product.cpu.abilist", which will return x86 or x86_64 for intel architecture devices.

 

Sample code

 

    try {

        Process process = Runtime.getRuntime().exec("getprop ro.product.cpu.abilist");

        InputStreamReader ir = new InputStreamReader(process.getInputStream());

        BufferedReader input = new BufferedReader(ir);

       final String abilist = input.readLine();

        if (!abilist.isEmpty()) {

           final String[] abi = abilist.split(",");

           if(abi[0].contains("x86_64")) {

                Log.i("mytag", "abi x86_64:  " + abi[0]);

            } else if (abi[0].contains("x86")) {

                Log.i("mytag", "abi x86:  " + abi[0]);

            } else if (abi[0].contains("armeabi-v7a")) {

               Log.i("mytag", "abi armeabi-v7a:  " + abi[0]);

            } else if (abi[0].contains("armeabi")) {

                Log.i("mytag", "abi armeabi:  " + abi[0]);

            } else if (abi[0].contains("arm64-v8a")) {

                Log.i("mytag", "abi arm64-v8a:  " + abi[0]);

            } else {

               Log.i("mytag", "abi unknown:  " + abi[0]);

           }

       } else {

           Log.i("mytag", "abilist is empty");

       }

    } catch (IOException e) {

        e.printStackTrace();

    ​}

 

then now you can know which device is it, and do some customization or optimization trick.

  • android
  • 图标图像: 

    Image may be NSFW.
    Clik here to view.
  • 开源
  • Eclipse*
  • Java*
  • 安卓*
  • 电话
  • 平板电脑
  • 开发人员
  • 安卓* 操作系统
  • 安卓*
  • 包括在 RSS 中: 

    1
  • 入门级
  • Eclipse

  • Viewing latest article 15
    Browse Latest Browse All 500

    Trending Articles



    <script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>