我正在努力通过 Intent 调用捕获图像功能。
我已经成功地从非 Activity 类实现 startActivityforResult 。我在那里得到活动上下文。
现在,我想在同一个 java 类中接收 onActivityResult。据我所知,必须有 Activity 类才能接收此方法。
有可能吗?
我尝试使用Java Proxy、 InvocationHandler 链接进行调用,但没有成功。
代码:
public class NovusAPI {
private Context mContext;
private NativeActivity nativeactivity;
static final int REQUEST_IMAGE_CAPTURE = 1;
/**
* Constructor. Save reference to NativeActivity object
**/
NovusAPI(NativeActivity ref) {
nativeactivity = ref;
Log.d(TAG, "NovusAPI constructor called");
}
public void captureImage(){
Log.d(TAG, "Image Capture Call");
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "novus");
values.put(MediaStore.Images.Media.DESCRIPTION, "novus camera capture");
// capture image camera
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
nativeactivity.startActivityForResult(intent,REQUEST_IMAGE_CAPTURE);
}
编辑:
PreferenceManager Class:
public interface OnActivityResultListener {
/**
* See Activity's onActivityResult.
*
* @return Whether the request code was handled (in which case
* subsequent listeners will not be called.
*/
boolean onActivityResult(int requestCode, int resultCode, Intent data);
}
OnActivityResultListener 是 Android Preference 类的接口。所以,我做这个到 InvocationHanlder 链接的工作。