<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def scan(cls, formats=ALL_CODE_TYPES, camera=-1):


        app = AndroidApplication.instance()
        r = app.create_future()

            #: Initiate a scan
        pkg = BarcodePackage.instance()
        pkg.setBarcodeResultListener(pkg.getId())
        pkg.onBarcodeResult.connect(r.set_result)

        intent = cls(app)
        if formats:
            intent.setDesiredBarcodeFormats(formats)
        if camera != -1:
            intent.setCameraId(camera)
        intent.initiateScan()

        return r