环境 安卓7.0或以上 网易公开课app
/**
* 获取用户性别
* @return str gender
*/
function getUserGender() {
if (!requestScreenCapture()) {
toast("请求截图失败");
exit();
}
waitForActivity("com.netease.vopen.feature.timeline.ui.UserTimelineActivity");
if (id('timeline_profile_gender').exists()) {
var rect = id('timeline_profile_gender').findOnce().bounds();
var img = captureScreen();
var point = findColor(img, -622207, {
region: [rect.left, rect.top, rect.width(), rect.height()],
threshold: 4
});
if (point) {
return "女";
} else {
var point = findColor(img, -7943189, {
region: [rect.left, rect.top, rect.width(), rect.height()],
threshold: 4
});
if (point) {
return "男";
}
};
} else {
return "未知";
}
}
/**
* 获取用户昵称
* @return str userName
*/
function getUserName() {
var userName = '';
//等待个人人资料页面出现
waitForActivity("com.netease.vopen.feature.timeline.ui.UserTimelineActivity");
if (id('mid_title').exists()) {
userName = id('mid_title').findOnce().text();
} else {
log('ERROR:未获取到用户昵称');
}
return userName;
}