protected void onClickAppShortcut(final View v) {
if (intent == null) {
throw new IllegalArgumentException("Input must have a valid intent");
}
if (mayLowStorage(intent)) {
return;
}
。。。。
private static final long MIN_MAY_LOW_STORAGE_THRESHOLD = 100L * 1024 * 1024;
private boolean mayLowStorage(Intent appIntent) {
if (appIntent.getComponent() == null) {
return false;
}
String pkg = appIntent.getComponent().getPackageName();
if ("com.android.dialer".equals(pkg) || "com.android.contacts".equals(pkg) ||
"com.google.android.apps.messaging".equals(pkg) || "com.google.android.apps.nbu.files".equals(pkg)) {
return false;
}
String storageDirectory = Environment.getDataDirectory().toString();
StatFs stat = new StatFs(storageDirectory);
long availableBlocks = stat.getAvailableBlocksLong();
long blockSize = stat.getBlockSizeLong();
long remaining = availableBlocks * blockSize;
boolean lowStorage = remaining < MIN_MAY_LOW_STORAGE_THRESHOLD;
if (lowStorage) {
Toast.makeText(this, R.string.low_memory_hint, Toast.LENGTH_LONG).show();
try {
Intent intent = new Intent("android.settings.INTERNAL_STORAGE_SETTINGS");
intent.setPackage("com.android.settings");
intent.putExtra("low_memory", true);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
return lowStorage;
}