From d59eca42188903d83f9462138059a7117e3067fd Mon Sep 17 00:00:00 2001 From: SheYu <2893251844@qq.com> Date: Sun, 7 Jan 2024 22:51:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=B2=E7=AA=81=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/micode/notes/ui/NoteEditActivity.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/src/main/java/net/micode/notes/ui/NoteEditActivity.java index 02cea3d..b740b4a 100644 --- a/src/main/java/net/micode/notes/ui/NoteEditActivity.java +++ b/src/main/java/net/micode/notes/ui/NoteEditActivity.java @@ -38,6 +38,8 @@ import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; +import androidx.core.app.ActivityCompat; + import net.micode.notes.R; import net.micode.notes.data.Notes; import net.micode.notes.data.Notes.TextNote; @@ -114,6 +116,12 @@ public class NoteEditActivity extends Activity implements OnClickListener, sFontSelectorSelectionMap.put(ResourceParser.TEXT_SUPER, R.id.iv_super_select); } + public static final int PHOTO_REQUEST = 1;//添加图片 + private static final int REQUEST_EXTERNAL_STORAGE=1;//权限申请 + private static String[] PERMISSIONS_STORAGE = { + "android.permission.READ_EXTERNAL_STORAGE", + "android.permission.WRITE_EXTERNAL_STORAGE" };//权限名称 + private static final String TAG = "NoteEditActivity"; private HeadViewHolder mNoteHeaderHolder; private View mHeadViewPanel; @@ -212,6 +220,23 @@ public class NoteEditActivity extends Activity implements OnClickListener, return; } initResources(); + + final ImageButton add_img_btn = (ImageButton) findViewById(R.id.add_img_btn);//根据id获取添加图片按钮 + //为点击图片按钮设置监听器 + add_img_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Log.d(TAG, "onClick: click add image button"); + //ACTION_GET_CONTENT: 允许用户选择特殊种类的数据,并返回(特殊种类的数据:照一张相片或录一段音) + Intent loadImage = new Intent(Intent.ACTION_GET_CONTENT); + //Category属性用于指定当前动作(Action)被执行的环境. + //CATEGORY_OPENABLE; 用来指示一个ACTION_GET_CONTENT的intent + loadImage.addCategory(Intent.CATEGORY_OPENABLE); + loadImage.setType("image/*"); + startActivityForResult(loadImage, PHOTO_REQUEST); + } + }); + convertToImage();//将路径显示为图片 } /**