本文整理汇总了Java中android.app.ActivityManager.getMemoryInfo方法的典型用法代码示例。如果您正苦于以下问题:Java ActivityManager.getMemoryInfo方法的具体用法?Java ActivityManager.getMemoryInfo怎么用?Java ActivityManager.getMemoryInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.ActivityManager
的用法示例。
在下文中一共展示了ActivityManager.getMemoryInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRamCurrent
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* Returns the current device RAM amount.
*/
static String getRamCurrent(Context context) {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
return Long.toString(getTotalRAM() - (mi.availMem / 1048576L));
}
示例2: isLowMemory
import android.app.ActivityManager; //导入方法依赖的package包/类
private static boolean isLowMemory(Context context) {
if (null == context) {
return false;
}
ActivityManager am = (ActivityManager)
context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo outInfo = new ActivityManager.MemoryInfo();
am.getMemoryInfo(outInfo);
return outInfo.lowMemory;
}
示例3: getDeviceUsableMemory
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* 获取设备的可用内存大小
*
* @param cxt 应用上下文对象context
* @return 当前内存大小
*/
public static int getDeviceUsableMemory(Context cxt) {
ActivityManager am = (ActivityManager) cxt
.getSystemService(Context.ACTIVITY_SERVICE);
MemoryInfo mi = new MemoryInfo();
am.getMemoryInfo(mi);
// 返回当前系统的可用内存
return (int) (mi.availMem / (1024 * 1024));
}
示例4: getDeviceUsableMemory
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* Gets the available memory size of the device
*
* @param context context
* @return Current memory size
*/
public static int getDeviceUsableMemory(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
// Returns the available memory for the current system
// int size = (int) (mi.availMem / (1024 * 1024));
int size1 = (int) (mi.availMem >> 20);
return size1;
}
示例5: getAvailableMemory
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* Check available memory
* @return
*/
private ActivityManager.MemoryInfo getAvailableMemory() {
ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
return memoryInfo;
}
示例6: G
import android.app.ActivityManager; //导入方法依赖的package包/类
private static long G(Context context) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(ModelName
.ACTIVITY);
MemoryInfo memoryInfo = new MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
return memoryInfo.availMem;
}
示例7: getTotalMemorySize
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* 获取所有的内存大小(in k)
*
* @param context
* @return
*/
@TargetApi(16)
public static Long getTotalMemorySize(Context context) {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
return mi != null ? mi.totalMem : null;
} else {
return null;
}
}
示例8: onCreate
import android.app.ActivityManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_memory_info);
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
TextView availableMemory = (TextView) findViewById(R.id.availableMemory);
TextView percentAvailable = (TextView) findViewById(R.id.percentAvailable);
TextView lowMemory = (TextView) findViewById(R.id.lowMemory);
TextView threshold = (TextView) findViewById(R.id.threshold);
TextView totalMemory = (TextView) findViewById(R.id.totalMemory);
TextView etc = (TextView) findViewById(R.id.etc);
StringBuilder sb = new StringBuilder();
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
double tmp = memoryInfo.availMem / 0x100000L;
sb.append(tmp);
sb.append(" MB");
availableMemory.setText(sb.toString());
tmp = memoryInfo.availMem / (double) memoryInfo.totalMem * 100.0;
sb.setLength(0);
sb.append(tmp);
sb.append(" %");
percentAvailable.setText(sb.toString());
if (memoryInfo.lowMemory) {
lowMemory.setText("Yes");
}
else {
lowMemory.setText("No");
}
tmp = memoryInfo.threshold / 0x100000L;
sb.setLength(0);
sb.append(tmp);
sb.append(" MB");
threshold.setText(sb.toString());
tmp = memoryInfo.totalMem / 0x100000L;
sb.setLength(0);
sb.append(tmp);
sb.append(" MB");
totalMemory.setText(sb.toString());
ActivityManager.RunningAppProcessInfo runningAppProcessInfo = new ActivityManager.RunningAppProcessInfo();
activityManager.getMyMemoryState(runningAppProcessInfo);
sb.setLength(0);
sb.append("PID: ");
sb.append(runningAppProcessInfo.pid);
sb.append("\n");
sb.append("Importance: ");
sb.append(runningAppProcessInfo.importance);
sb.append("\n");
sb.append("Last Trim Level: ");
sb.append(runningAppProcessInfo.lastTrimLevel);
sb.append("\n");
sb.append("Importance Reason Code: ");
sb.append(runningAppProcessInfo.importanceReasonCode);
sb.append("\n");
sb.append("LRU: ");
sb.append(runningAppProcessInfo.lru);
sb.append("\n");
etc.setText(sb.toString());
}
示例9: isLowMemory
import android.app.ActivityManager; //导入方法依赖的package包/类
private boolean isLowMemory() {
ActivityManager activityManager = (ActivityManager)context.getSystemService(ACTIVITY_SERVICE);
if (activityManager != null) {
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
return memoryInfo.lowMemory;
} else {
return true;
}
}
示例10: getMemoryInfo
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* Get memory info of device.
*/
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static ActivityManager.MemoryInfo getMemoryInfo(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
return mi;
}
示例11: getAvailMemory
import android.app.ActivityManager; //导入方法依赖的package包/类
private static long getAvailMemory() {
ActivityManager am = (ActivityManager) NimUIKit.getContext()
.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
return mi.availMem;
}
示例12: L
import android.app.ActivityManager; //导入方法依赖的package包/类
public static String L(Context context) {
try {
ActivityManager activityManager = (ActivityManager) context.getSystemService
(ModelName.ACTIVITY);
MemoryInfo memoryInfo = new MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
return String.valueOf(memoryInfo.availMem / 1000000) + "/" + String.valueOf(ay() /
1000000);
} catch (Throwable th) {
th.printStackTrace();
return null;
}
}
示例13: getAvailMemory
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* Get available memory info.
*/
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static String getAvailMemory(Context context) {// 获取android当前可用内存大小
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
// mi.availMem; 当前系统的可用内存
return Formatter.formatFileSize(context, mi.availMem);// 将获取的内存大小规格化
}
示例14: getAllMemory
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* Get all memory
*
* @param context
* @return
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static String getAllMemory(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
return Formatter.formatFileSize(context, mi.totalMem);
}
示例15: getAvailableMemory
import android.app.ActivityManager; //导入方法依赖的package包/类
static public int getAvailableMemory(Context context)
{
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
Log.d(LoadOSService.class.getName(),"current available memory KB is:"+mi.availMem/1024);
return (int)mi.availMem;
}