应用卸载反馈- /CharonChui/UninstallFeedback (SDK5.0后就失效了)
Home键监听- /BolexLiu/AndroidHomeKeyListen
利用广播创建和删除桌面添加快捷方式- /BolexLiu/AddShortcut
>手机系统版本号,手机型号,手机厂商
android.os.Build.MODEL.toUpperCase().contains("PCT-AL10")
/**
* 获取当前手机系统版本号
*
* @return 系统版本号
*/
public static String getSystemVersion() {
return android.os.Build.VERSION.RELEASE;
}
/**
* 获取手机型号
*
* @return 手机型号
*/
public static String getSystemModel() {
return android.os.Build.MODEL;
}
/**
* 获取手机厂商
*
* @return 手机厂商
*/
public static String getDeviceBrand() {
return android.os.Build.BRAND;
}
String sysVersion = android.os.Build.VERSION.RELEASE;
String phoneModel = android.os.Build.MODEL;
String phoneFactory = android.os.Build.BRAND;
LogUtil.e("desaco", "系统版本号:"+sysVersion+",,手机型号 phoneModel:"+phoneModel+",,手机厂商:"+phoneFactory);
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
获取手机厂商 brand=Xiaomi,, 手机型号,phoneModel: MIX 3
获取手机厂商 brand=Xiaomi,, 手机型号,phoneModel: MIX
/**
* 获取手机型号
*/
String phoneModel = android.os.Build.MODEL;
public void fetchEqual(String phoneModel) {
String backupModel = "vivo x20";
Log.e("desaco","backupModel = " + backupModel.toLowerCase());
Log.e("desaco","phoneModel = "+ phoneModel.toLowerCase());
if (phoneModel.toLowerCase() .equals(backupModel.toLowerCase())) {
Log.e("desaco"," true .. " );
} else {
Log.e("desaco"," false .. " );
}
}
--CPU核数、时钟频率以及内存大小,CPU数目
如何获取 Android 设备的CPU核数、时钟频率以及内存大小- /blog/2223173
Device Year Class is an Android library that implements a simple algorithm that maps a device's RAM, CPU cores, and clock speed to the year where those combination of specs were considered high end- /facebook/device-year-class
android获取cpu数目- /gather_2a/MtjaAg0sNTU5MC1ibG9n.html
java或者android中获取cpu数量的方法: Runtime.getRuntime().availableProcessors();
private int getNumCores() {
// Private Class to display only CPU devices in the directory listing
class CpuFilter implements FileFilter
{
@Override
public boolean accept(File pathname)
{
// Check if filename is "cpu", followed by a single digit number
if (Pattern.matches("cpu[0-9]", pathname.getName()))
{
return true;
}
return false;
}
}
try {
// Get directory containing CPU info
File dir = new File("/sys/devices/system/cpu/");
// Filter to only list the devices we care about
File[] files = dir.listFiles(new CpuFilter());
// Return the number of cores (virtual CPU devices)
return files.length;
} catch (Exception e) {
// Default to return 1 core
return 1;
}
}
public static int getNumberOfCPUCores() {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
// Gingerbread doesn't support giving a single application access to both cores, but a
// handful of devices (Atrix 4G and Droid X2 for example) were released with a dual-core
// chipset and Gingerbread; that can let an app in the background run without impacting
// the foreground application. But for our purposes, it makes them single core.
return 1; //上面的意思就是2.3以前不支持多核,有些特殊的设备有双核...不考虑,就当单核!!
}
int cores;
try {
cores = new File("/sys/devices/system/cpu/").listFiles(CPU_FILTER).length;
} catch (SecurityException e) {
cores = DEVICEINFO_UNKNOWN; //这个常量得自己约定
} catch (NullPointerException e) {
cores = DEVICEINFO_UNKNOWN;
}
return cores;
}
private static final FileFilter CPU_FILTER = new FileFilter() {
@Override
public boolean accept(File pathname) {
String path = pathname.getName();
//regex is slow, so checking char by char.
if (path.startsWith("cpu")) {
for (int i = 3; i < path.length(); i++) {
if (path.charAt(i) < '0' || path.charAt(i) > '9') {
return false;
}
}
return true;
}
return false;
}
};
>虚拟按键,监听网络
android虚拟按键适配- /a910626/article/details/52972110
通过Broadcast动态注册监听网络变化- /code/snippet_1250198_48668
> 应用要创建和删除自己的快捷方式图标, 只需发送如下两个Intent即可:
com.android.launcher.action.INSTALL_SHORTCUT
com.android.launcher.action.UNINSTALL_SHORTCUT
同时需要在AndroidManifest.xml中添加如下两个权限:
android:name="com.android.launcher.permission.INSTALL_SHORTCUT
android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT
>获取屏幕宽高
Android开发中获取屏幕宽高的几种方法- /biaobiao1217/article/details/46876995
Android获取手机屏幕的宽高- /speverriver/article/details/51124879
>设备的唯一标识 MAC,IMEI
Android设备的唯一标识- /q4878802/article/details/52043936
> 同一个机构发开的不同App之间的数据共享, android:sharedUserId
不同的应用程序可以运行在相同的进程中。对于此方法,首先必须使用相同的私钥签署这些应用程序,然后必须使用 manifest 文件给它们分配相同的 Linux 用户 ID,这可以通过用相同的值/名定义 manifest 属性 android:sharedUserId 来做到。通过sharedUserId,拥有同一个User id的多个APK安装包可以配置成运行在同一个进程中.所以默认就是可以互相访问任意数据. 也可以配置成运行成不同的进程, 同时可以访问其他APK的数据目录下的数据库和文件.就像访问本程序的数据一样。这样就为同一个机构发开的不同App之间的数据共享,提供了便利。
> 安装和卸载
Android代码实现APP普通安装卸载和静默安装卸载- /risingwonderland/article/details/45537313
Android静默安装和静默卸载代码- /lr393993507/p/5543145.html
Android中实现静态的默认安装和卸载应用- /jiangwei0910410003/article/details/36427963
在安装和卸载完后,android系统会发一个广播:
android.intent.action.PACKAGE_ADDED(安装);
android.intent.action.PACKAGE_REMOVED(卸载);
/* 安装apk */
public static void installApk(Context context, String fileName) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(Uri.parse("file://" + fileName),"application/vnd.android.package-archive");
context.startActivity(intent);
}
/* 卸载apk */
public static void uninstallApk(Context context, String packageName) {
Uri uri = Uri.parse("package:" + packageName);
Intent intent = new Intent(Intent.ACTION_DELETE, uri);
context.startActivity(intent);
}
> Android壁纸,动态壁纸 静态壁纸
深入理解Android壁纸- /innost/article/details/47660645
在Android中设置壁纸的方法,在Android中设置壁纸的方法有三种,分别是:
1、使用WallpaperManager的setResource(int ResourceID)方法
2、使用WallpaperManager的setBitmap(Bitmap bitmap)方法
3、重写ContextWrapper 类中提供的setWallpaper()
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
浅谈视频壁纸- /miLLlulei/article/details/77868105
Android系统截屏- /solarsaber/article/details/78038240
Android仿网易云音乐中锁屏后在开锁界面插屏功能- /u010696525/article/details/51445515
Android锁屏的实现原理及技术要点- /ahence/article/details/25400911
an universal lock screen app demo with "shield" the home key on android 4.0+- /ASPOOK/Android-LockScreen
> 飞行模式,4.2以上的版本app没有权限修改Setting.Global的
android 4.2 系统以后的飞行模式- /hrklzwzj/article/details/51940507
飞行模式- /tl3shi/AirPlaneModeSwitcher
if(Settings.System.getString(cr,Settings.System.AIRPLANE_MODE_ON).equals("0")){
//获取当前飞行模式状态,返回的是String值0,或1.0为关闭飞行,1为开启飞行
//如果关闭飞行,则打开飞行
Settings.System.putString(cr,Settings.System.AIRPLANE_MODE_ON, "1");
// Settings.System.putString(cr,Settings.System.AIRPLANE_MODE_ON, "0");
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
sendBroadcast(intent);
}
> 手电筒,手机低电量模式
android 实现手电筒功能- /ak4100/article/details/43953055
Android开启手电筒功能(完美适配Android4x,5x,6x)- /mynameishuangshuai/article/details/53214763
Android Low Battery 低电量处理流程- /wangbaochu/article/details/44406681
-- 闪光灯
Android闪光灯实现- /u014752325/article/details/52945944
-- 低耗电模式下的一些限制:
暂停访问网络。
系统将忽略 wake locks。
标准 AlarmManager 闹铃(包括 setExact() 和 setWindow())推迟到下一维护时段。
如果您需要设置在低电耗模式下触发的闹铃,请使用 setAndAllowWhileIdle() 或 - setExactAndAllowWhileIdle()。
一般情况下,使用 setAlarmClock() 设置的闹铃将继续触发 — 但系统会在这些闹铃触发之前不久退出低电耗模式。
系统不执行 Wi-Fi 扫描。
系统不允许运行同步适配器。
系统不允许运行 JobScheduler。
android那些事系列之android闪光灯或手电筒不得不说的那些机型问题- /Terry_722/article/details/51187830
> 调节屏幕亮度(当前应用和系统亮度)
Android 调节屏幕亮度(当前应用和系统亮度)- /xinyutianyu/article/details/45605803
android-设置系统及应用级屏幕亮度- /centralperk/article/details/40345221
Android6.0调节屏幕亮度显示- /qitehuanjue/article/details/53219873
android5.1 自动亮度调节简析- /p/13658019bcea
Android设置屏幕亮度的两种方式- /jiangxuelei_/article/details/51243575
Android调整屏幕亮度和改变屏幕亮度调整模式的代码- /hzlxtq123/article/details/53742057
boolean autoBrightness = false;
ContentResolver contentResolver = activity.getContentResolver();
try {
autoBrightness = Settings.System.getInt(contentResolver,
Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
}
> 缓存处理及手机硬盘容量
Android 文件保存getFilesDir()丶getCacheDir()、getExternalFilesDir() 等操作方法探索- /android_technology/article/details/53516357
计算Android App占用的各种空间大小- /item/8786bc2e95a042320bef.html /hyl963254113/article/details/43405363
Android获取cpu使用率,剩余内存和硬盘容量- /l2show/article/details/40950657
Android中App可分配内存的大小- /u011506413/article/details/50965435
> 开机,关机
1.定时开机
pendingIntent = PendingIntent.getBroadcast(context,0,poweron_intent,PendingIntent.FLAG_CANCEL_CURRENT);
am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,calendar.getTimeInMillis(), poweron_pendingIntent);
2.定时关机
-- 发送关机intent
pendingIntent = PendingIntent.getBroadcast(context,0,poweroff_intent,PendingIntent.FLAG_CANCEL_CURRENT);
am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),pendingIntent);
-- 收关机intent
if(from_intent.getAction().equals("com.android.settings.action.REQUEST_POWER_OFF")) {
Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivityAsUser(intent, UserHandle.CURRENT);
}