Create multiply photo with Android SDK and save there

Numerous manual describes how to take a single photo and get his data(uri or Bundlee) in Activity in method onActivityResult. How to make a few photos and get this result in the Activity??? We can create own realization of SurfaceHolder, Camera etc… And we can create standart Action to call standart Camera application and… get all photos. In this very short state, we will show how


CameraEventReceiver.NEED_LISTEN = true;
                    Intent intent = new Intent(
                            MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
                    PhotoFragment.this.startActivity(intent);

its own Intent. We can call his from button

Receiver, who listen adding new photos to MediaStore from camera.

public class CameraEventReceiver extends BroadcastReceiver {

    public static boolean NEED_LISTEN = false;

    @Override
    public void onReceive(Context context, Intent intent) {
        if(NEED_LISTEN){
            if(intent!=null){
                Uri currenturi = intent.getData();
                String pathPhoto = getPath(context,currenturi);
                File sourceFile = new File(pathPhoto);
                File f = new File(Environment.getExternalStorageDirectory()+File.separator+"OwnFolder", sourceFile.getName());
                /**
                 * Here we can save photos in our storage or do with it whatever we like
                 /*
            }
        }

    }

    public static String getPath(Context context, Uri uri)
    {
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
        if (cursor == null) return null;
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        String s=cursor.getString(column_index);
        cursor.close();
        return s;
    }
}

and do not forget to add a listener to the manifest

 <receiver
       android:name=".receiver.CameraEventReceiver"
       android:enabled="true">
       <intent-filter>
           <action android:name="com.android.camera.NEW_PICTURE"/>
           <action android:name="android.hardware.action.NEW_PICTURE" />
           <data android:mimeType="image/*"/>
       </intent-filter>
</receiver>

It’s all!!!

Leave a Reply

Этот сайт использует Akismet для борьбы со спамом. Узнайте как обрабатываются ваши данные комментариев.