[0]LayaAir中二次开发如何传递Context对象给安卓原生层调用?

我在Java中的代码是
public class CameraManager {
    public static final int REQUEST_IMAGE_CAPTURE = 1;
    private static String currentPhotoPath; 
    public static void openCamera(Context context, Activity activity) {
        // Create a file for the photo
        File photoFile = null;
        try {
            photoFile = createImageFile(context);
        } catch (IOException ex) {
            // Error occurred while creating the File
            ex.printStackTrace();
        }
        // Continue only if the file was successfully created
        if (photoFile != null) {
            currentPhotoPath = photoFile.getAbsolutePath();
            // Create the Intent
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            // Set the file Uri for the photo
            Uri photoURI = FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            // Launch the camera activity
            if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) {
                activity.startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
            }
        }
    } 
    private static File createImageFile(Context context) throws IOException {
        // Create an image file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "JPEG_" + timeStamp + "_";
        File storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        File image = File.createTempFile(
                imageFileName,  /* prefix */
                ".jpg",         /* suffix */
                storageDir      /* directory */
        ); 
        // Save a file: path for use with ACTION_VIEW intents
        return image;
    }
}现在我需要调用OpenCamera这个方法的时候,需要传入Context对象和Activity对象,请问我再JS中应该怎么传入啊? JavaScript中的低吗大概是这样的,但是我不知道怎么传这两个对象
      var os = conchConfig.getOS();
      var bridge;
      var obj = {};
      if (os == "Conch-ios") {
          // bridge = PlatformClass.createClass("JSBridge");//创建脚步代理
      }
      else if (os == "Conch-android") {
        //需要完整的类路径,注意与iOS的不同
        bridge = PlatformClass.createClass("demo.CameraManager");//创建脚步代理
      }
      if (os == "Conch-android") {bridge = call.("openCamera",[context,activity]);
      }
      else if(os == "Conch-ios"){ 
      }
    }
 
已邀请:

LayaAir3

赞同来自:

Context对象和Activity对象都是Java层的,Java层自己存好,直接在方法里调用就行。不用从JS中传入,所以openCamera方法就没有参数

要回复问题请先

商务合作
商务合作