gpt4 book ai didi

android - 将 QR 码扫描器放入 Fragment 中

转载 作者:行者123 更新时间:2023-11-29 01:54:24 24 4
gpt4 key购买 nike

我正在使用安卓二维码处理库 - android QR code . 我正在扩展扫描仪的 DecoderActivity,现在我希望扫描仪位于 fragment 内,我使用 LocalActivityManager 将 Activity 嵌入 fragment 内。这是代码:

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 扫描仪现在无法使用。我调试了库代码,它需要一个 Activity 实例,我正在传递 fragment 内的 Activity 实例。希望我清楚这一点。请帮忙!

最佳答案

我找到了一个名为 Barcode Fragment library 的库它使用 fragment 来托管扫描仪功能。工作正常但不支持纵向模式支持,我已经按照 here 中的建议对库进行了更改.它就像一个魅力:)

关于android - 将 QR 码扫描器放入 Fragment 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16028115/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com