我想在Android中以编程方式打开前闪光灯(不是使用相机预览).我用谷歌搜索了它,但我发现的帮助将我推荐到了这个页面
有没有人有任何链接或示例代码?
我想做的事情似乎很简单,但经过几天的搜索,我无法弄明白.
我有一个应用程序,允许用户选择多个(最多5个)图像.我正在使用ImageView.当用户点击时ImageView,我想允许他们选择
我开始使用ACTION_GET_CONTENT意图,这对于进入画廊非常有用.那么我尝试使用ACTION_PICK_ACTIVITY意图允许用户选择相机或图库:
Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
Intent gallIntent=new Intent(Intent.ACTION_GET_CONTENT);
gallIntent.setType("image/*");
Intent camIntent = new Intent("android.media.action.IMAGE_CAPTURE");
pickIntent.putExtra(Intent.EXTRA_INTENT, camIntent);
pickIntent.putExtra(Intent.EXTRA_INTENT, gallIntent)
pickIntent.putExtra(Intent.EXTRA_TITLE, "Select Source");
startActivityForResult(pickIntent, IMAGE_SELECTOR);
Run Code Online (Sandbox Code Playgroud)
但似乎我只能添加一个EXTRA_INTENT.菜单按预期显示,但唯一的选项是图库和文件....没有相机).
有没有更好/更简单的方法来做到这一点,我错过了?谢谢你的帮助.
android android-intent android-gallery android-camera android-intent-chooser
新的camera2 API让我很困惑.我想开发一个使用该设备相机的应用程序(适用于Android API 10 - 21).如前所述这里,我应该使用"相机" API.
但是,当我尝试将"Camera"API (android.hardware.Camera)添加到清单的用户功能时,它被标记为已弃用.另一方面,我无法将其更改为"camera2"API (android.hardware.camera2),因为它只与Android API 21+(Android 5 - Lollipop)兼容 - 也会链接它,但我只能添加2个链接.
我不仅希望我的应用程序在旧版本的Android上运行,而且还需要最新版本的...
我一直在努力在Android上制作自定义相机活动,但是当旋转相机时,表面视图的纵横比会变得混乱.
在我的oncreate活动中,我设置了framelayout,它保存了显示摄像机参数的表面视图.
//FrameLayout that will hold the camera preview
FrameLayout previewHolder = (FrameLayout) findViewById(R.id.camerapreview);
//Setting camera's preview size to the best preview size
Size optimalSize = null;
camera = getCameraInstance();
double aspectRatio = 0;
if(camera != null){
//Setting the camera's aspect ratio
Camera.Parameters parameters = camera.getParameters();
List<Size> sizes = parameters.getSupportedPreviewSizes();
optimalSize = CameraPreview.getOptimalPreviewSize(sizes, getResources().getDisplayMetrics().widthPixels, getResources().getDisplayMetrics().heightPixels);
aspectRatio = (float)optimalSize.width/optimalSize.height;
}
if(optimalSize!= null){
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int)(getResources().getDisplayMetrics().widthPixels*aspectRatio));
previewHolder.setLayoutParams(params);
LayoutParams surfaceParams = new LayoutParams(LayoutParams.MATCH_PARENT, (int)(getResources().getDisplayMetrics().widthPixels*aspectRatio));
cameraPreview.setLayoutParams(surfaceParams);
}
cameraPreview.setCamera(camera);
//Adding the preview …Run Code Online (Sandbox Code Playgroud) 我有一个包含多个活动的android应用程序.
在其中一个我正在使用一个按钮,它将调用设备摄像头:
public void onClick(View view) {
Intent photoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(photoIntent, IMAGE_CAPTURE);
}
Run Code Online (Sandbox Code Playgroud)
在同一个活动中,我调用OnActivityResult图像结果的方法:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == IMAGE_CAPTURE) {
if (resultCode == RESULT_OK) {
Bitmap image = (Bitmap) data.getExtras().get("data");
ImageView imageview = (ImageView) findViewById(R.id.pic);
imageview.setImageBitmap(image);
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "CANCELED ", Toast.LENGTH_LONG).show();
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是intent data是null并且OnActivityResult方法直接转到,(resultCode == RESULT_CANCELED)并且应用程序返回到先前的avtivity.
如何修复此问题,并在调用相机后,应用程序返回当前活动,其中包含ImageView将包含拍摄的照片?
谢谢
if android.hardware.Camera is deprecated and you cannot use the variable Camera, then what would be the alternative to this?
我需要将一个意图推送到默认的相机应用程序,使其拍摄照片,保存并返回URI.有没有办法做到这一点?
更一般地说,如果设备有多个嵌入式摄像头,是否有办法初始化其中一个?
我没有在Android参考文档中找到它:
三星SHW-M100S有两个摄像头.如果没有参考使用两个相机,任何想法三星怎么做...?
在我的应用程序中,如果设备有相机,我想使用相机.有没有运行Android的设备没有摄像头?通过在我的清单中包含以下内容:
<uses-feature android:name="android.hardware.camera" android:required="false"/>
Run Code Online (Sandbox Code Playgroud)
然后它基本上说"我会使用相机,如果存在,但不需要一个运行应用程序".
在尝试使用Camera类之前,如何检查设备上是否存在相机?
我正在尝试让我的应用程序为新的Android M权限更改做好准备,并发现了一些奇怪的行为.我的应用程序使用相机意图机制允许用户从相机获取图片.但是在另一个活动中需要使用具有Camera权限的摄像头本身(因为需要这个的库依赖card.io).
但是,当我尝试启动Camera意图时,只需要相机意图的活动中的M我看到以下崩溃(如果我从Manifest中删除了Camera权限,则不会发生这种情况),
> 09-25 21:57:55.260 774-8053/? I/ActivityManager: START u0
> {act=android.media.action.IMAGE_CAPTURE flg=0x3000003
> pkg=com.google.android.GoogleCamera
> cmp=com.google.android.GoogleCamera/com.android.camera.CaptureActivity
> (has clip) (has extras)} from uid 10098 on display 0 09-25
> 21:57:55.261 774-8053/? W/ActivityManager: Permission Denial: starting
> Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3000003
> pkg=com.google.android.GoogleCamera
> cmp=com.google.android.GoogleCamera/com.android.camera.CaptureActivity
> (has clip) (has extras) } from null (pid=-1, uid=10098) with revoked
> permission android.permission.CAMERA 09-25 21:57:55.263 32657-32657/?
> E/ResolverActivity: Unable to launch as uid 10098 package
> com.example.me.mycamerselectapp, while running in android:ui 09-25
> …Run Code Online (Sandbox Code Playgroud) android android-camera android-camera-intent android-permissions android-6.0-marshmallow