恐怕您尝试这样做的方式是不可能的。作为一名新的 Android 开发人员,您需要了解的一件事是活动之间的循环是如何工作的。在您的情况下,您正在运行一个Activity调用 anIntent从它获取数据的方法。然而,在 Android API 中,anIntent只能在它自己的时候被引用。这意味着您不能getImage()按照您尝试过的方式使用您的方法。
不过还是有希望的!
您首先需要做的是调用Intent. 您将通过您现在拥有的代码执行此操作getImage():
public void getImage() { // This has to be a void!
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);  
    intent.setType("image/*");
    startActivityForResult(intent, 10);
}
此方法现在将启动您希望用户从中选择的图像选择器。接下来,您必须捕获返回的内容。这不能从您的getImage()方法返回,而是必须从其他地方收集。
您必须实现以下方法:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        final int SELECT_PICTURE = 1; // Hardcoded from API
        if (requestCode == SELECT_PICTURE) {
            String pathToImage = data.getData().getPath(); // Get path to image, returned by the image picker Intent
            mDrawableBg = Drawable.createFromPath(pathToImage); // Get a Drawable from the path
        }
    }
}
最后,不要调用mDrawableBg = getResources().getDrawable(getImage());,只需调用getImage();。这将初始化图像选择器。
一些阅读:
祝你好运!