【Cocos2d-x】截图分享功能
发布时间:2020-12-14 20:38:28 所属栏目:百科 来源:网络整理
导读:Cocos2d-x截图实现 a target=_blank id="L1" href="http://blog.csdn.net/linchaolong/article/details/44452205#L1" rel="#L1" style="text-decoration: none; color: rgb(12,137,207);" 1/aa target=_blank id="L2" href="http://blog.csdn.net/linchaolon
Cocos2d-x截图实现
来自CODE的代码片
|
Intent
shareIntent
=
new
Intent
(
Intent
.
ACTION_SEND
);
//shareIntent.putExtra(Intent.EXTRA_TEXT,文本);
String
imgPath
=
图片路径
;
File
file
=
new
File
(
imgPath
);
if
(
file
.
exists
())
{
try
{
//一般情况下,保存的图片文件权限为rw- rw- rw-(外部可读写),但有的机型可能是rw- --- ---(外部不可读写),如果是后者会分享失败,因为外部不能读取这张图片。为了保证正常分享,需要通过chmod命令修改图片文件的权限。
// 修改文件权限为-rw-r--r--,外部可读
Process
p
=
Runtime
.
getRuntime
().
exec
(
"chmod 644 "
+
imgPath
);
int
status
=
p
.
waitFor
();
//让当前线程等待
if
(
status
==
0
)
{
// 返回0表示正常终止
Log
.
d
(
TAG
,
"chmod succeed"
);
}
else
{
Log
.
d
(
TAG
,240)">"chmod failure"
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
Uri
uri
=
Uri
.
fromFile
(
file
);
shareIntent
.
putExtra
(
Intent
.
EXTRA_STREAM
,
uri
);
shareIntent
.
setType
(
"image/png"
);
startActivity
(
Intent
.
createChooser
(
shareIntent
,
getResources
().
getText
(
R
.
string
.
SHARE
)));
}
|