工具 Receiver
- 获取imei
- 定义receiver
public class ImeiReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String imei = ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId(); setResultData(imei); }
}
- adb 命令(注意在Manifest中添加权限) `android.permission.READ_PHONE_STATE`
> adb shell am broadcast -a action_name
- 获取宽高
- 定义receiver
public class WHReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
DisplayMetrics displaymetrics = new DisplayMetrics();
int width, height;
WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE;
if (wm != null) {
wm.getDefaultDisplay().getMetrics(displaymetrics);
height = displaymetrics.heightPixels;
width = displaymetrics.widthPixels;
} else{
height = -1;
width = -1;
}
String result = "width=" + width + " "+ "height="+height;
setResultData(result);
}
}
- adb shell 命令
- 获取宽 "width=... "
> adb shell am broadcast -a com.qunar.adbfwd.GET_WH | grep data | sed 's/\\(.\*\\)width=\\(.\*\\) \\(.\*\\)/\\2/g' 注意中间的空格
- 获取高 "height=...""
>adb shell am broadcast -a com.qunar.adbfwd.GET_WH | grep data | sed 's/\\(.\*\\)height=\\(.\*\\)"\\(.\*\\)/\\2/g'