用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/itgoyo/hermes-skills --skill android-screenshot-share命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | android-screenshot-share |
| description | Android 页面截图分享模式 — 隐藏指定控件后截图,通过分享弹窗发送到微信/QQ/保存相册 |
| triggers | ["Android 页面截图分享","截图不含某些控件(返回键、分享按钮等)","CommonShareDialog 图片分享"] |
点击分享按钮
→ 隐藏不想出现的控件(INVISIBLE,保留占位)
→ rootView.post { } ← 等下一帧确保 visibility 已刷新
→ captureView(DecorView) → Bitmap
→ 恢复控件可见
→ 弹出分享弹窗传入 Bitmap
// import android.graphics.Bitmap;
// import android.graphics.Canvas;
private void takeScreenshotAndShare() {
// 1. 隐藏不需要出现在截图中的控件(用 INVISIBLE 保留占位,避免布局抖动)
backIV.setVisibility(View.INVISIBLE);
shareIV.setVisibility(View.INVISIBLE);
// 2. post 到下一帧,确保 visibility 变更已绘制
View rootView = getWindow().getDecorView().getRootView();
rootView.post(() -> {
Bitmap screenshot = captureView(rootView);
// 3. 恢复控件
backIV.setVisibility(View.VISIBLE);
shareIV.setVisibility(View.VISIBLE);
if (screenshot == null) return;
// 4. 弹出分享弹窗
new CommonShareDialog.Builder(this)
.setShareType(CommonShareDialog.TYPE_SHARE_IMG)
.setShareBitmap(screenshot)
.create()
.show();
});
}
private Bitmap captureView(View view) {
try {
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
} catch (Exception e) {
return null;
}
}
为什么用
INVISIBLE不用GONE?
GONE会触发 relayout,INVISIBLE只触发 redraw,截图前后布局稳定不跳动。
项目中 CommonShareDialog 的 TYPE_SHARE_IMG 分支默认为空,需要手动补全:
setShareBitmap// 字段
private Bitmap shareBitmap;
// Builder 方法
public Builder setShareBitmap(Bitmap bitmap) {
this.shareBitmap = bitmap;
return this;
}
// create() 里赋值
dialog.shareBitmap = shareBitmap;
case TYPE_SHARE_IMG:
if (shareBitmap != null) {
try {
AppHelper.wxShareBitmap(scene, shareBitmap);
} catch (Exception e) {
new CenterToast(mContext).show(
mContext.getString(R.string.Please_install_WeChat_first), Toast.LENGTH_SHORT);
}
}
break;
AppHelper.wxShareBitmap(int scene, Bitmap bitmap) 已封装好微信图片发送逻辑。
QQ SDK 图片分享需要本地文件路径,不能直接传 Bitmap:
private void qqShareBitmap(Bitmap bitmap) {
try {
// 1. 先保存到本地 cache(AppUtils2.saveBitmap 返回绝对路径)
String imgPath = AppUtils2.saveBitmap(mContext, bitmap);
if (imgPath == null || imgPath.isEmpty()) {
new CenterToast(mContext).show("分享失败,图片保存出错", Toast.LENGTH_SHORT);
return;
}
Activity topActivity = ActivityUtils.getTopActivity();
if (topActivity == null) return;
// 2. 通过 QQShare.SHARE_TO_QQ_TYPE_IMAGE 分享本地图片
android.os.Bundle params = new android.os.Bundle();
params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_IMAGE);
params.putString(QQShare.SHARE_TO_QQ_IMAGE_LOCAL_URL, imgPath);
params.putString(QQShare.SHARE_TO_QQ_APP_NAME, topActivity.getString(R.string.app_name));
Tencent.createInstance(BuildConfig.QQ_APP_ID, mContext)
.shareToQQ(topActivity, params, new IUiListener() {
@Override public void onComplete(Object o) {}
@Override public void onError(UiError uiError) {}
@Override public void {}
});
} (Exception e) {
(mContext).show(, Toast.LENGTH_SHORT);
}
}
图片模式下第四个按钮(原"复制链接")改为"保存图片":
private void handleSaveOrCopy() {
if (shareType == TYPE_SHARE_IMG && shareBitmap != null) {
// 保存到相册
AppUtils.insertPictureToSystem(
shareBitmap,
"report_" + System.currentTimeMillis(),
() -> new CenterToast(mContext).show("保存成功", Toast.LENGTH_SHORT)
);
} else {
// 复制链接(原有逻辑)
AppUtils2.copyStr(mContext, shareUrl);
new CenterToast(mContext).show(
mContext.getString(R.string.Copy_links_successfully), Toast.LENGTH_SHORT);
}
}
| 工具 | 方法 | 用途 |
|---|---|---|
AppHelper | wxShareBitmap(int scene, Bitmap) | 微信图片分享(已封装) |
AppUtils2 | saveBitmap(Context, Bitmap) → String | 保存 Bitmap 到 cache,返回路径 |
com.lib.utils.AppUtils | insertPictureToSystem(Bitmap, String, Runnable) | 保存 Bitmap 到系统相册 |
ActivityUtils | getTopActivity() | 获取当前顶部 Activity(QQ 分享需要) |
AppUtils2.saveBitmap 只有两参数版本 (Context, Bitmap),没有带文件名的三参数版本,不要传文件名captureView 截取的是 DecorView(包含状态栏),如果只想截内容区域,改用 findViewById(android.R.id.content) 或自定义根 View