前端之家收集整理的这篇文章主要介绍了
cocos2dx复制内容到剪贴板,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
android
c++中@H_404_4@
javar 类型签名
类型签名 |
Java类型 |
Z |
boolean |
B |
byte |
C |
char |
S |
short |
I |
int |
J |
long |
F |
float |
D |
double |
L full-qualified-class; |
完全限定的类,分号必须要有 |
[ type |
type[ ] |
(arg-types) ret-type |
(参数类型列表)返回值类型 |
int copyToClipboard(const std::string& paras) {
JniMethodInfo minfo;
if (JniHelper::getStaticMethodInfo(minfo,"org/cocos2dx/javascript/AppActivity","copyToClipboard","(Ljava/lang/String;)I"))
{
jstring jstr = minfo.env->NewStringUTF(paras.c_str());
int code = minfo.env->CallStaticIntMethod(minfo.classID,minfo.methodID,jstr);
return code;
}
#endif
return -1;
}
java中@H_404_4@
public class AppActivity extends Cocos2dxActivity {
static AppActivity sgsActivity;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sgsActivity = this;
}
static public int copyToClipboard(final String text)
{
final Context context = sgsActivity;
try
{
Log.d("cocos2dx","copyToClipboard " + text);
Runnable runnable = new Runnable() {
public void run() {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("Copied Text",text);
clipboard.setPrimaryClip(clip);
}
};
sgsActivity.runOnUiThread(runnable);
}catch(Exception e){
Log.d("cocos2dx","copyToClipboard error");
e.printStackTrace();
return -1;
}
return 0;
}