我试图让用户从图库中选择图像,或者用相机拍照.我试过这个:
Intent imageIntent = new Intent(Intent.ACTION_GET_CONTENT);
imageIntent.setType("image/*");
startActivityForResult(Intent.createChooser(imageIntent, "Select Picture"), GET_IMAGE_REQUEST);
Run Code Online (Sandbox Code Playgroud)
但它自动显示图库,甚至没有提供选择活动的选项.似乎应该有一些更好的方法来实现这个,而不是在这个问题中给出的解决方案.这真的是唯一的方法吗?
android android-intent android-gallery android-camera android-intent-chooser
我有一个ImageView子类,我用它来绘制带圆角的图像.代码基于这个答案,如下:
public class ImageViewRoundedCorners extends ImageView {
...
@Override
protected void onDraw(Canvas canvas) {
Bitmap scaledBitmap = Bitmap.createBitmap(getMeasuredWidth(),
getMeasuredHeight(),
Bitmap.Config.ARGB_8888);
Canvas scaledCanvas = new Canvas(scaledBitmap);
super.onDraw(scaledCanvas);
drawRoundedCornerBitmap(canvas, scaledBitmap,
getMeasuredWidth(), getMeasuredHeight());
scaledBitmap.recycle();
}
protected void drawRoundedCornerBitmap(Canvas outputCanvas, Bitmap input, int w, int h) {
Bitmap output = Bitmap.createBitmap(w, h, Config.ARGB_8888);
Canvas canvas = new Canvas(output);
mPaint.reset();
mPaint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
mPaint.setStyle(Paint.Style.FILL);
canvas.drawPath(mClipPath, mPaint);
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(input, 0, 0, mPaint);
outputCanvas.drawBitmap(output, 0, 0, null);
}
}
Run Code Online (Sandbox Code Playgroud)
使用此代码,可以使用正确的圆角绘制图像.为了避免前两行的分配 …
我正在尝试在收到推送通知时更新UI的状态.为了做到这一点,我需要启动一个AsyncTask执行一些网络操作,然后根据结果更新UI.
根据文档BroadcastReceiver,在接收器中执行异步操作是不安全的,因为执行它的进程可能会在onReceive()返回时立即终止,假设该进程中没有其他"应用程序组件".
是BroadcastReceiver在自己的进程中运行,还是在与包含Activity的进程相同的进程中运行?因为我只关心任务的完成,只要有更新的UI,我不担心AsyncTask如果活动关闭就会死亡.假设BroadcastReceiver与活动处于同一个进程中,这是否可以安全地启动我在接收器中描述的任务?
编辑:
为了澄清,我在活动中注册接收者onResume()并取消注册onPause(),因此它应该只在活动已经激活时接收意图.
我正在尝试用汇编编写一个简单的程序,它将写出程序的名称。使用 gdb 进行调试,我确定对 sys_write 的调用返回 -14 (EFAULT)。我还能够验证我的 strlen 函数是否正常工作。似乎存在某种内存访问问题,但鉴于 strlen 正在访问相同的内存并且工作正常,我不明白可能有什么问题。出了什么问题?
谢谢!
完整代码:
section .text
global _start
_start:
mov rax, [rsp+8]
push rax
call strlen
add rsp, 8
mov rdx, rax ; bytes to write
mov rax, 4 ; sys_write
mov rbx, 1 ; stdout
mov rcx, [rsp+8] ; addr of string
int 0x80
; exit
mov rax, 1
mov rbx, 0
int 0x80
strlen:
mov rax, 0
mov rbx, [rsp+8]
strlen_loop:
cmp byte [rbx+rax], 0
je strlen_end
inc rax …Run Code Online (Sandbox Code Playgroud)