有必要创建一个相机以将其放入片段 (android) 中吗?
It is necessary to create an camera to put it inside an fragment (android)?
我只需要在我的 main activity 的三个片段之一中放置一个相机,比如 ([f]-[f]-[C]),其中 () 是我的 main activity, [] 是一个片段,C 是相机,f 只是一个片段(它们是全屏可滑动的)。我需要为它创建一个完整的相机(编码等),或者可以调用 android 本机相机应用程序来实现片段?
您可以使用 Intent 启动 camara,它会启动 camara 默认应用程序。请注意检测何时显示您的 "C" 片段,此处:How to determine when Fragment becomes visible in ViewPager
如果您不这样做,android 会在显示之前预先缓存片段,然后您的 intent 就会触发。
在你的 activity 上使用:
@Override public void onResume() {
super.onResume();
if(viewPager.getCurrentItem() == 2){
//Your code here. Executed when fragment is seen by user.
// create Intent to take a picture and return control to the calling application
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
}
查看带有意图选项的相机启动:http://developer.android.com/guide/topics/media/camera.html#intent-image
如果你需要拍照,你可以只使用一个意图来启动系统相机应用程序。这样做会使编码更容易,但您将无法显示实时预览,因为您实际上是通过该意图处理对相机应用程序的控制。
手动处理整个相机生命周期使您可以控制预览并在您的应用中实时显示。此外,如果您需要 在您的应用程序中进行实时预览,这是可行的方法,仅使用 Intent
.
无法实现
您可能会在该存储库中找到 UltimateAndroidCameraGuide on GitHub very helpful for your problem, particularly the SimpleCameraIntentFragment and the NativeCameraFragment 文件。
I need to create a whole camera (coding , etc) just for it
是的,无论您自己编写还是使用库中的。
or it is possible to call android native camera app with intent to an fagment?
不,您不能将第三方应用程序嵌入到您的应用程序片段中。
我只需要在我的 main activity 的三个片段之一中放置一个相机,比如 ([f]-[f]-[C]),其中 () 是我的 main activity, [] 是一个片段,C 是相机,f 只是一个片段(它们是全屏可滑动的)。我需要为它创建一个完整的相机(编码等),或者可以调用 android 本机相机应用程序来实现片段?
您可以使用 Intent 启动 camara,它会启动 camara 默认应用程序。请注意检测何时显示您的 "C" 片段,此处:How to determine when Fragment becomes visible in ViewPager
如果您不这样做,android 会在显示之前预先缓存片段,然后您的 intent 就会触发。
在你的 activity 上使用:
@Override public void onResume() {
super.onResume();
if(viewPager.getCurrentItem() == 2){
//Your code here. Executed when fragment is seen by user.
// create Intent to take a picture and return control to the calling application
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
}
查看带有意图选项的相机启动:http://developer.android.com/guide/topics/media/camera.html#intent-image
如果你需要拍照,你可以只使用一个意图来启动系统相机应用程序。这样做会使编码更容易,但您将无法显示实时预览,因为您实际上是通过该意图处理对相机应用程序的控制。
手动处理整个相机生命周期使您可以控制预览并在您的应用中实时显示。此外,如果您需要 在您的应用程序中进行实时预览,这是可行的方法,仅使用 Intent
.
您可能会在该存储库中找到 UltimateAndroidCameraGuide on GitHub very helpful for your problem, particularly the SimpleCameraIntentFragment and the NativeCameraFragment 文件。
I need to create a whole camera (coding , etc) just for it
是的,无论您自己编写还是使用库中的。
or it is possible to call android native camera app with intent to an fagment?
不,您不能将第三方应用程序嵌入到您的应用程序片段中。