Get Emulator list from Chrome

拜拜、爱过 提交于 2019-12-05 22:32:19

Did a Notepad++ Find in Files and found it.

The data is stored in JSON format in file

C:\Users\Your UserName\AppData\Local\Google\Chrome\User Data\Default\Preferences

Under Key

devtools>preferences>standardEmulatedDeviceList

I have used Jackson to parse the JSON

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Test {

    public static void main(String[] args) {
        try {
            ObjectMapper mapper = new ObjectMapper();
            Map map = mapper.readValue(
                    new File("C:\\Users\\<UserName>\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Preferences"),
                    Map.class);
            Map devTools = (Map) map.get("devtools");
            Map preferences = (Map) devTools.get("preferences");
            String standardEmulatedDeviceList = (String) preferences.get("standardEmulatedDeviceList");
            List emulatorMap = mapper.readValue(standardEmulatedDeviceList, List.class);
            System.out.println(emulatorMap.size());
            for (Object object : emulatorMap) {
                Map device = (Map) object;
                System.out.println(device.get("title"));
            }
        } catch (IOException ex) {
            Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!