Java Question Wrapping lib error: onActivityResult: wi is null

laomms

Member
Licensed User
I reference Johan Schoeman and DonManfred's sample want wrpping a github google vision source code .
evething is well, I use SLC1.06 wrpping the lib successful.

but when inport the b4a, error occurred: onActivityResult: wi is null
 

Attachments

  • TextRecognition.zip
    75.6 KB · Views: 220
  • lib source.zip
    34.2 KB · Views: 215
  • 111.png
    111.png
    174.9 KB · Views: 235
  • 222.png
    222.png
    28 KB · Views: 253
  • libs.zip
    35.5 KB · Views: 217

Johan Schoeman

Expert
Licensed User
I reference Johan Schoeman and DonManfred's sample want wrpping a github google vision source code .
evething is well, I use SLC1.06 wrpping the lib successful.

but when inport the b4a, error occurred: onActivityResult: wi is null
The is probably something missing in your Manifest file.
 

laomms

Member
Licensed User
I have no idea about this: onActivityResult: wi is null
IOnActivityResult always released before the activity was resumed.

onActivityResult: wi is null
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
 

Johan Schoeman

Expert
Licensed User
I have no idea about this: onActivityResult: wi is null
IOnActivityResult always released before the activity was resumed.

onActivityResult: wi is null
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
I will PM you over the weekend. I have got it working (shortcut wrap) :)

1.png
 

Johan Schoeman

Expert
Licensed User
really, johan, great thanks!
Here it is - attached:
1. Extract the B4A project from b4aTra.zip
2. Unzip resource.zip and copy the resource folder and its contents to be on the same folder level as that of the /Objects and /Files folders of the B4A project
3. Unzip DemoRes.zip and copy the DemoRes folder and its contents to be on the same folder level as that of the /Objects and /Files folders of the B4A project
4. Extract the B4A lib files from b4aLibFiles.zip and copy the jar and xml to your additional library folder

I have also attached the Java code (src folder). Seeing that you have already managed to compile your project I assume you know how and where to add the "libs" folder with the necessary jars in order to compile the Java project with SLC.

I have done nothing special in the wrapper (such as raising events, etc) other than adding the ability to kick start the original project (i.e only a short cut wrap) from within a B4A project. You can modify it as you wish but the "onActivityResult: wi is null" error in not there...;)

Take note of the B4A project's Manifest file.

Enjoy!

JS
 

Attachments

  • b4aLibFiles.zip
    7.7 KB · Views: 229
  • b4aTra.zip
    9 KB · Views: 218
  • DemoRes.zip
    70.6 KB · Views: 212
  • resource.zip
    423 bytes · Views: 218
  • TheJavaCode.zip
    3.9 KB · Views: 230
Last edited:

laomms

Member
Licensed User
update to landscape only when Ocr, these is some piece source:

B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aTRA
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#AdditionalRes: ..\res
#AdditionalRes: ..\resource

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals


End Sub

Sub Globals
 
    Dim scan As OcrLib

    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("main")
 
    scan.Initialize("scan")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click
 
    scan.startDetection
 
End Sub

Sub scan_scanned_text(scannedText As String)
 
    Log("Scanned text = " & scannedText)

 
End Sub

Manifast shoud add
android:configChanges="keyboardHidden|orientation:
B4X:
        <activity android:name="com.tuts.prakash.simpleocr.MainActivity"
                  android:configChanges="keyboardHidden|orientation">
        </activity>

activity_main.xml modify:
B4X:
    android:orientation="horizontal"
    android:screenOrientation="landscape"


MainActivity.java add
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
B4X:
public class MainActivity extends AppCompatActivity  {

    private static final String TAG = "MainActivity";
    static AtomicBoolean surfaceExists = new AtomicBoolean(false);
    private static final int CAMERA_REQUEST_ID = 2122;
    public static final String mTextBlock = "String";


    private SurfaceHolder mSurfaceHolder;

    Camera mCamera;
    Context mContext;
    SurfaceView mCameraView;
    TextView mTextView;
    CameraSource mCameraSource;
    CameraInfo mCameraInfo;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        mTextView = (TextView)findViewById(R.id.text_view);
        mCameraView = (SurfaceView)findViewById(R.id.surfaceView);
   

        startCameraSource();
    }
 
 

    private void startCameraSource() {
        TextRecognizer textRecognizer = new TextRecognizer.Builder(this).build();
        if (textRecognizer.isOperational()) {
            mCameraSource = new CameraSource.Builder(this, textRecognizer)
                    .setFacing(CameraSource.CAMERA_FACING_BACK)
                    .setRequestedPreviewSize(1280, 1024)
                    .setRequestedFps(2.0f)
                    .setAutoFocusEnabled(true)
                    .build();
            mCameraView.getHolder().addCallback(new SurfaceHolder.Callback() {

                @Override
                public void surfaceCreated(SurfaceHolder surfaceHolder) {
                    try {
                        if (ActivityCompat.checkSelfPermission(MainActivity.this,Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
                            ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA},CAMERA_REQUEST_ID);
                            return;
                        }
                        mCameraSource.start(mCameraView.getHolder());
                   
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)  {
               
                }

                @Override
                public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
                    mCameraSource.stop();
                }
            });


            textRecognizer.setProcessor(new Detector.Processor<TextBlock>() {

                @Override
                public void release() {

                }

                @Override
                public void receiveDetections(Detector.Detections<TextBlock> detections) {
                    final SparseArray<TextBlock> items = detections.getDetectedItems();
                    mTextView.post(new Runnable() {
                        @Override
                        public void run() {
                            if (items.size() == 0) {
                                mTextView.setText("");
                                mTextView.setVisibility(View.INVISIBLE);
                            } else {
                                StringBuilder stringBuilder = new StringBuilder();
                                TextBlock text = null;
                                for (int i = 0; i < items.size(); i++) {
                                    if ((i < items.size()) && (i < 10)) {
                                        String str = ((TextBlock)items.valueAt(i)).getValue().replaceAll("[^0-9]", "");
                                        Log.d("tag", "Value: " + str);
                                        if ((str.length() == 16) || (str.length() == 19)) {         //read card No.
                                            BA.Log("Value: " + str);        
                                            Intent mIntent = new Intent();
                                            mIntent.putExtra(mTextBlock, str);
                                            MainActivity.this.setResult(0, mIntent);
                                            items.clear();
                                            finish();                                                           // close activaty
                                        }
                                    }
                                    else
                                    {
                                    return;
                                    }
                                }
                                mTextView.setText(stringBuilder.toString());
                                mTextView.setVisibility(View.VISIBLE);
                            }
                        }
                    });
                }
            });
        } else {
            Log.d(getClass().getSimpleName(), "Text Recognizer isn't ready yet");
        }
    }

}


use _scanned_textet event get text result:
B4X:
public class traWrapper extends AbsObjectWrapper<MainActivity> {

 
    @Hide
    public static BA ba;
    @Hide
    public static String eventName;
    private static MainActivity cv;
    private IOnActivityResult ion;
    private static final int RC_OCR_CAPTURE = 9003;
 
    Intent mIntent;
 

 
    public void Initialize(BA paramBA, String paramString) {
        eventName = paramString.toLowerCase(BA.cul);
        ba = paramBA;

        MainActivity cv = new MainActivity();
        String str = paramString.toLowerCase(BA.cul);
 
        setObject(cv);
        mIntent = new Intent(BA.applicationContext, MainActivity.class);
 
    }


     public void startDetection() {
        ion = new IOnActivityResult() {
       
            @Override
            public void ResultArrived(int arg0, Intent data) {
                BA.Log("ResultArrived");
                if (data != null) {
                    String text = data.getStringExtra(MainActivity.mTextBlock);
                    BA.Log("Text read: " + text);
                      if (traWrapper.ba.subExists(traWrapper.eventName + "_scanned_text")) {
                        traWrapper.ba.raiseEventFromDifferentThread(this, null, 0, traWrapper.eventName + "_scanned_text", true, new Object[] {text});
                      }              
               
                } else {
                    //statusMessage.setText(R.string.ocr_failure);
                    BA.Log("No Text captured, intent data is null");
                }
            }
        };
        ba.startActivityForResult(ion, mIntent);
    }
 

}


111.png
 
Last edited:
Top