2016-04-18 6 views
1

3GBのRAMを搭載したLG G4またはNote 3でアプリを実行すると、デバイスに2GBのRAMが搭載されていることがわかります。誰かがどこに問題があるのか​​説明できるか?デバイスの合計RAMメモリを取得するには?

ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); 
    ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); 
    activityManager.getMemoryInfo(mi); 
    long freeMemory = mi.availMem/1048576L; 
    long totalMemory = mi.totalMem/1048576L; 
    long usedMemory = totalMemory - freeMemory; 
    SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences(Util.MyPREFERENCES, 0); 
    String status = sharedPreferences.getString(Util.KEY_STATUS, null); 
    if (status.equals("clean")) { 
     tvFree.setText(freeMemory + " MB"); 
     tvTotal.setText(totalMemory + " MB"); 
     tvUsed.setText(usedMemory + " MB"); 
     stateImage.setImageResource(R.drawable.greenstate); 
     rippleBackground.stopRippleAnimation(); 
    } 
+0

はあなたに似た問題を抱えていました。 – duffymo

+0

まあ、それは許可する必要があります、私は再びアンドロイドのドキュメントをチェックさせてください。 –

+0

詳細は重要です。これは64ビットのJVMですか? 32ビットJVMから1.6GB以上を取得することはできません。http://www.oracle.com/technetwork/java/hotspotfaq-138619.html – duffymo

答えて

1

そのための明確なAPIではないようですが、私は簡単なハックを使用:

セットアップ(最初の15〜20のような)2Sの電力の一部を持つルックアップテーブルを見つけると、 APIから取得された「OSメモリ」に最も近い値。たぶんそれはあなたがOSによって必要なRAMをカウントすることはできません Get android device's all RAM memory programmatically and not only what is only allocated to user processes

関連する問題