我正在使用android QR代码处理库-android QR代码 我正在扩展扫描仪的DecoderActivity,现在我希望扫描仪位于片段内,我已经使用LocalActivityManager将Activity嵌入片段内。 这是代码:

public class QrCodeProcessorFragment extends SherlockFragment {

private static final String KEY_STATE_BUNDLE = "localActivityManagerState";

private LocalActivityManager mLocalActivityManager;

Button generate_qr_code;

private QuickPayManagerActivity parent;

protected LocalActivityManager getLocalActivityManager() {
    return mLocalActivityManager;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle state = null;
    if (savedInstanceState != null) {
        state = savedInstanceState.getBundle(KEY_STATE_BUNDLE);
    }

    mLocalActivityManager = new LocalActivityManager(getActivity(), true);
    mLocalActivityManager.dispatchCreate(state);
}

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // This is where you specify you activity class
    Intent i = new Intent(getSherlockActivity(), CaptureActivity.class);
    Window w = mLocalActivityManager.startActivity("tag", i);
    View currentView = w.getDecorView();
    ViewGroup vg = (ViewGroup) (currentView.getParent());
    if (vg != null)
        vg.removeView(currentView);

    currentView.setVisibility(View.VISIBLE);
    currentView.setFocusableInTouchMode(true);
    ((ViewGroup) currentView)
            .setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

    return currentView;
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putBundle(KEY_STATE_BUNDLE,
            mLocalActivityManager.saveInstanceState());
}

@Override
public void onResume() {
    System.out.println("lam onresume");
    super.onResume();
    mLocalActivityManager.dispatchResume();
}

@Override
public void onPause() {
    System.out.println("lam onpause");
    super.onPause();
    mLocalActivityManager.dispatchPause(getActivity().isFinishing());
}

@Override
public void onStop() {
    super.onStop();
    mLocalActivityManager.dispatchStop();
}

@Override
public void onDestroy() {
    super.onDestroy();
    mLocalActivityManager.dispatchDestroy(getActivity().isFinishing());
}}

QR扫描仪现在无法正常工作。 我调试了库代码,它期待一个活动实例,并且我传递了片段内的活动实例。 希望我对此清楚。 请帮忙!

===============>>#1 票数:1 已采纳

我找到了一个名为Barcode Fragment库的库 ,该使用一个片段来承载扫描仪功能。 工作正常,但不支持纵向模式支持,我已经按照此处的建议对库进行了更改。 它就像一个魅力:)

  ask by CodeFury translate from so

未解决问题?本站智能推荐: