天天看点

https://developer.android.com/training/building-multimedia.html

multimedia n. 多媒体

leverage v. 利用;举债经营

prevalent adj. 流行的;普遍的,广传的

However, if you’d like the photos to remain private to your app only, you can instead use the directory provided by getExternalFilesDir(). On Android 4.3 and lower, writing to this directory also requires the WRITE_EXTERNAL_STORAGE permission. Beginning with Android 4.4, the permission is no longer required because the directory is not accessible by other apps, so you can declare the permission should be requested only on the lower versions of Android by adding the maxSdkVersion attribute:

如果你想让拍到的照片只让本应用可见,你可以用getExternalFilesDir()。在Android4.4以下往这个目录写文件要求写权限,但是Android4.4以上,不再要求权限,因为这个目录只有本应用可见,所以你可以在Manifest中这样声明权限:

<manifest ...>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
                     android:maxSdkVersion="18" />
    ...
</manifest>
           

rear-facing camera 后置摄像头

Getting an instance of the Camera object is the first step in the process of directly controlling the camera. As Android’s own Camera application does, the recommended way to access the camera is to open Camera on a separate thread that’s launched from onCreate(). This approach is a good idea since it can take a while and might bog down the UI thread. In a more basic implementation, opening the camera can be deferred to the onResume() method to facilitate code reuse and keep the flow of control simple.

推荐在onCreate()中重新开启一个线程来开启相机,因为开启相机可能会阻塞主线程。打开摄像头可以被延迟到onResume()方法中,以促进代码重用并保持控制流程的简单性。

安全的打开摄像头的方法

private boolean safeCameraOpen(int id) {
    boolean qOpened = false;

    try {
        releaseCameraAndPreview();
        mCamera = Camera.open(id);
        qOpened = (mCamera != null);
    } catch (Exception e) {
        Log.e(getString(R.string.app_name), "failed to open Camera");
        e.printStackTrace();
    }

    return qOpened;
}

private void releaseCameraAndPreview() {
    mPreview.setCamera(null);
    if (mCamera != null) {
        mCamera.release();
        mCamera = null;
    }
}
           

encapsulated adj. 密封的;包在荚膜内的

exposure compensation 曝光补偿

Android打印照片的简单方法

private void doPhotoPrint() {
    PrintHelper photoPrinter = new PrintHelper(getActivity());
    photoPrinter.setScaleMode(PrintHelper.SCALE_MODE_FIT);
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
            R.drawable.droids);
    photoPrinter.printBitmap("droids.jpg - test print", bitmap);
}
           
After the printBitmap() method is called, no further action from your application is required. The Android print user interface appears, allowing the user to select a printer and printing options. The user can then print the image or cancel the action. If the user chooses to print the image, a print job is created and a printing notification appears in the system bar.

执行printBitmap()后,你不需要执行更多的操作,手机会弹出相应的打印界面,你选择打印机后就可以打印,你也可以取消操作。

precise adj. 精确的;明确的;严格的