博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android 手机设置中的关于手机界面
阅读量:3759 次
发布时间:2019-05-22

本文共 8051 字,大约阅读时间需要 26 分钟。

不管哪一款Android 设备都会在设置中显示关于手机一栏,基本上大同小异,手机名称啊,型号啊,版本号啊手机内存机身存储等等,以下是简单的记录下:

1.Activity:

package activity;import android.app.ActivityManager;import android.content.Context;import android.content.Intent;import android.os.Environment;import android.os.StatFs;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.text.format.Formatter;import android.view.View;import android.widget.ImageView;import android.widget.ListView;import android.widget.TextView;import com.vstar3d.myapplication.R;import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.lang.reflect.Method;import java.util.ArrayList;import java.util.List;import adapter.Setting_AboutPhoneAdapter;public class Setting_AboutPhoneActivity extends AppCompatActivity {    private TextView mImageView;    private ListView listView;    private Setting_AboutPhoneAdapter adapter;    private List
list; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main4); initView(); initDate(); getDate(); } private void initDate() { list = new ArrayList
(); adapter = new Setting_AboutPhoneAdapter(list, this); } private void initView() { mImageView = (TextView) findViewById(R.id.image); mImageView.setText("基于Adnroid"+android.os.Build.VERSION.RELEASE+"开发"); listView = (ListView) findViewById(R.id.listView); } public void getDate() { String name = "手机名称\n" + android.os.Build.PRODUCT; String model = "型号\n" + android.os.Build.MODEL; String version = "Android版本\n" + android.os.Build.VERSION.RELEASE; String cpu = "处理器\n" + android.os.Build.CPU_ABI2; String phonememory = "手机内存\n" + "手机总内存: " + this.getTotalMemory() + ", " + "可用内存: " + this.getAvailMemory(); String sdmemory = "机身存储\n" + "SD卡总内存: " + this.getSDAllSize() + "GB" + ", " + "可用内存: " + this.getSDFreeSize() + "GB"; String display = "版本号\n" + android.os.Build.DISPLAY; String result1 = "基带版本\n" + getBaseband_Ver(); String kernel = "内核版本\n" + getKernelVersion(); String inner = "内部版本\n" + getInner_Ver(); list.add(name); list.add(model); list.add(version); list.add(cpu); list.add(phonememory); list.add(sdmemory); list.add(result1); list.add(kernel); list.add(inner); list.add(display); listView.setAdapter(adapter); } /*手机可用内存*/ private String getAvailMemory() { ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); am.getMemoryInfo(mi); return Formatter.formatFileSize(getBaseContext(), mi.availMem); } /*手机总内存*/ private String getTotalMemory() { String str1 = "/proc/meminfo"; String str2; String[] arrayOfString; long initial_memory = 0; try { FileReader localFileReader = new FileReader(str1); BufferedReader localBufferedReader = new BufferedReader(localFileReader, 8192); str2 = localBufferedReader.readLine(); arrayOfString = str2.split("\\s+"); initial_memory = Long.parseLong(arrayOfString[1]) * 1024; localBufferedReader.close(); } catch (IOException e) { } return Formatter.formatFileSize(getBaseContext(), initial_memory); } /*SD卡总内存*/ public float getSDAllSize() { File path = Environment.getExternalStorageDirectory(); StatFs sf = new StatFs(path.getPath()); long blockSize = sf.getBlockSize(); long allBlocks = sf.getBlockCount(); return (allBlocks * blockSize) / 1024 / 1024 / 1024; //单位MB } /*SD卡可用内存*/ public float getSDFreeSize() { File path = Environment.getExternalStorageDirectory(); StatFs sf = new StatFs(path.getPath()); long blockSize = sf.getBlockSize(); long freeBlocks = sf.getAvailableBlocks(); return (freeBlocks * blockSize) / 1024 / 1024 / 1024; //单位MB } /*基带版本*/ public static String getBaseband_Ver() { String Version = ""; try { Class cl = Class.forName("android.os.SystemProperties"); Object invoker = cl.newInstance(); Method m = cl.getMethod("get", new Class[]{
String.class, String.class}); Object result = m.invoke(invoker, new Object[]{
"gsm.version.baseband", "no message"}); Version = (String) result; } catch (Exception e) { e.printStackTrace(); } return Version; } /*内部版本*/ public static String getInner_Ver() { String ver = ""; if (android.os.Build.DISPLAY.contains(android.os.Build.VERSION.INCREMENTAL)) { ver = android.os.Build.DISPLAY; } else { ver = android.os.Build.VERSION.INCREMENTAL; } return ver; } /*内核版本*/ public static String getKernelVersion() { String kernelVersion = ""; InputStream inputStream = null; try { inputStream = new FileInputStream("/proc/version"); } catch (FileNotFoundException e) { e.printStackTrace(); return kernelVersion; } BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream), 8 * 1024); String info = ""; String line = ""; try { while ((line = bufferedReader.readLine()) != null) { info += line; } } catch (IOException e) { e.printStackTrace(); } finally { try { bufferedReader.close(); inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } try { if (info != "") { final String keyword = "version "; int index = info.indexOf(keyword); line = info.substring(index + keyword.length()); index = line.indexOf(" "); kernelVersion = line.substring(0, index); } } catch (IndexOutOfBoundsException e) { e.printStackTrace(); } return kernelVersion; }}

2.Adapter:

package adapter;import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.TextView;import com.vstar3d.myapplication.R;import java.util.List;public class Setting_AboutPhoneAdapter extends BaseAdapter {    private List
itemDetailed; private Context context; public Setting_AboutPhoneAdapter(List
itemDetailed, Context context) { this.itemDetailed = itemDetailed; this.context = context; } @Override public int getCount() { return itemDetailed.size(); } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder viewHolder; if (convertView == null){ convertView = LayoutInflater.from(context).inflate(R.layout.item,null); viewHolder = new ViewHolder(); viewHolder.text_detailed = (TextView) convertView.findViewById(R.id.text_detailed); convertView.setTag(viewHolder); }else { viewHolder = (ViewHolder) convertView.getTag(); } String stringTitle = itemDetailed.get(position); viewHolder.text_detailed.setText(stringTitle); return convertView; } class ViewHolder{ TextView text_detailed; }

3.布局文件:main

item:

至于还有一些法律信息等等信息加进去就行。

转载地址:http://gbfpn.baihongyu.com/

你可能感兴趣的文章
Thymeleaf模板引擎
查看>>
使用Thymeleaf配置国际化页面
查看>>
Spring Boot中Spring MVC的整合支持
查看>>
Spring Boot制作个人博客-首页
查看>>
Spring Boot制作个人博客-详情页
查看>>
Spring Boot制作个人博客-分类页
查看>>
Spring Boot制作个人博客-标签页
查看>>
Spring Boot制作个人博客-归档页
查看>>
Spring Boot制作个人博客-关于我页
查看>>
Spring Boot制作个人博客-博客管理列表页
查看>>
周总结11
查看>>
Spring Boot制作个人博客-博客关于我页面
查看>>
2021-06-12# 学习以及成为想要成为的人day17
查看>>
# 学习以及成为想要成为的人day18
查看>>
学习以及成为想要成为的人day19
查看>>
#学习以及成为想要成为的人day20
查看>>
servlet500
查看>>
ns3实验
查看>>
ORM框架入门----使用Hibernate实现用户添加
查看>>
Hibernate-Query 保存和查询
查看>>