工具 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中添加權(quán)限) `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'