gpt4 book ai didi

android - onActivityResult 永远不会被调用 Phonegap Cordova

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:25:35 24 4
gpt4 key购买 nike

我正在使用 PhoneGap 的 Barcode Scanner Plugin,使用 ZXing 作为库项目。

我有一个代码可以在 Galaxy Tab 2 (7") 上完美运行。相同的代码在 Galaxy S3 上不起作用。

问题:当 ZXing CaptureActivity 扫描条形码时,它刚刚完成 CaptureActivity 并且调用 Activity 永远不会返回 onActivityResult 方法。

主要节日。

<activity
android:name=".activity.MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="com.phonegap.plugins.barcodescanner.SCAN" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>

主 Activity .java

public void startActivityForResult(CordovaPlugin command, Intent intent,
int requestCode) {
this.activityResultCallback = command;
this.activityResultKeepRunning = this.keepRunning;

// If multitasking turned on, then disable it for activities that return
// results
if (command != null) {
this.keepRunning = false;
}

// Start activity
startActivityForResult(intent, requestCode);
}

protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
CordovaPlugin callback = this.activityResultCallback;
if (callback != null) {
callback.onActivityResult(requestCode, resultCode, intent);
} else {
Log.e(TAG, "Plugin callback null");
}
// else continue with any other code you need in the method

super.onActivityResult(requestCode, resultCode, intent);


}

条码扫描器插件

private static final String SCAN_INTENT = "com.phonegap.plugins.barcodescanner.SCAN";
public void scan() {

Intent intentScan = new Intent(SCAN_INTENT);
intentScan.addCategory(Intent.CATEGORY_DEFAULT);
this.cordova.startActivityForResult((CordovaPlugin) this, intentScan,
AppConstants.CAMERA_SCAN_REQUEST_CODE);

}

我有 ZXing projet 作为库项目。

帮助将不胜感激。

最佳答案

根据 Cordova web view documentation

您需要在您的 Activity 中包含此代码:

@Override
public void setActivityResultCallback(CordovaPlugin plugin) {
this.activityResultCallback = plugin;
}

public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode) {
this.activityResultCallback = command;
this.activityResultKeepRunning = this.keepRunning;

// If multitasking turned on, then disable it for activities that return results
if (command != null) {
this.keepRunning = false;
}

// Start activity
super.startActivityForResult(intent, requestCode);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
CordovaPlugin callback = this.activityResultCallback;
if (callback != null) {
callback.onActivityResult(requestCode, resultCode, intent);
}
}

除了:

this.cordova.startActivityForResult((CordovaPlugin) this, intentScan, AppConstants.CAMERA_SCAN_REQUEST_CODE);

你的插件需要有如下方法:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
//do something with the result
super.onActivityResult(requestCode, resultCode, intent);
}

关于android - onActivityResult 永远不会被调用 Phonegap Cordova,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18125415/

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