cocosCreator-小功能
程序员文章站
2022-03-03 22:20:37
cocosCreator-小功能拷贝功能电量获取拷贝功能ios:+(void)copyString:(NSString*)str{ UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; pasteboard.string = str;}android: import android.os.Looper; // 拷贝 public static boolean isLooper = f...
拷贝功能
ios:
+(void)copyString:(NSString*)str
{
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = str;
}
android:
import android.os.Looper;
// 拷贝
public static boolean isLooper = false;
//在 onCreate 中赋值 ccActivity = this;
public static AppActivity ccActivity;
// 拷贝字符串
public static int copyString(String content) {
if (!isLooper) {
Looper.prepare();
isLooper = !isLooper;
}
ClipboardManager cbm = (ClipboardManager) ccActivity.getSystemService(Service.CLIPBOARD_SERVICE);
ClipData cd = ClipData.newPlainText("pipi", content);
cbm.setPrimaryClip(cd);
return 0;
}
js:
//拷贝字符串
copyString(str) {
if (cc.sys.os === cc.sys.OS_ANDROID && cc.sys.isBrowser !== true) {
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "copyString", "(Ljava/lang/String;)I", str);
} else if (cc.sys.os === cc.sys.OS_IOS || cc.sys.os === cc.sys.OS_OSX && cc.sys.isBrowser !== true) {
jsb.reflection.callStaticMethod("AppController", "copyString:", str);
}
},
电量获取
ios:
+ (float) getBatteryLevel {
//打开电池的监听
[UIDevice currentDevice].batteryMonitoringEnabled = YES;
//获取剩余电量 范围在0.000000 至 1.000000之间
CGFloat batterylevel = [UIDevice currentDevice].batteryLevel;
CGFloat floatlevel = batterylevel * 100;
return floatlevel;
}
android:
js:
getBatteryLevel(str) {
if (cc.sys.os === cc.sys.OS_ANDROID && cc.sys.isBrowser !== true) {
} else if (cc.sys.os === cc.sys.OS_IOS || cc.sys.os === cc.sys.OS_OSX && cc.sys.isBrowser !== true) {
let bl = jsb.reflection.callStaticMethod("AppController", "getBatteryLevel");
bl = bl.toFixed(2) * 100;
return bl;
}else {
return "0";
}
},
本文地址:https://blog.csdn.net/chuying1509/article/details/107130199