我想在TextView中显示系统存储信息。 该信息将是:-总存储容量,已用存储容量。 请帮助我做到这一点。 而且我还想在用户打开应用程序时在textview中显示它。
package com.devrachit.shareloop;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public static long getUsedMemorySize() {
long freeSize = 0L;
long totalSize = 0L;
long usedSize = -1L;
try {
Runtime info = Runtime.getRuntime();
freeSize = info.freeMemory();
totalSize = info.totalMemory();
usedSize = totalSize - freeSize;
} catch (Exception e) {
e.printStackTrace();
}
return usedSize;
}
protected void onCreate(Bundle savedInstanceState) {
// globally
TextView myAwesomeTextView = (TextView)findViewById(R.id.textfreestorage);
//in your OnCreate() method
myAwesomeTextView.setText("My Awesome Text");
}
}