Turning on the Zebra TC21 scanner from c++ code with jni

f finito Alain 2 weeks ago
35 0 0

Hello, 

i'm currently making an app on android, and i would like to create a button on this app to just turn on the scanner.

I am currently stuck, although i used datawedge and everything, the app crashes when i call BroadcastReceiver create().

I'm using c++ builder 11 with the firemonkey (fmx) library.

Could seomone help me or at least give me tips?

 

here's the code, i could be doing things wrong, i'm still learning 

 

//---------------------------------------------------------------------------

#include <fmx.h>
#include <System.IOUtils.hpp>
#ifdef __ANDROID__
    #include <Androidapi.Helpers.hpp>
   #include <Androidapi.JNI.Os.hpp>
   #include <FMX.Platform.Android.hpp>
    #include <Androidapi.JNI.GraphicsContentViewText.hpp>
   #include <Androidapi.JNI.App.hpp>
   #include <Androidapi.JNI.JavaTypes.hpp>
    #include <Androidapi.JNI.Util.hpp>
#endif
#include <FMX.DialogService.hpp>
#pragma hdrstop

#include "photo.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TFPhoto *FPhoto;
//---------------------------------------------------------------------------
__fastcall TFPhoto::TFPhoto(TComponent* Owner)
    : TForm(Owner)
{
#ifdef __ANDROID__
    FPermissionCamera = JStringToString(TJManifest_permission::JavaClass->CAMERA);
#endif
}
// ---------------------------------------------------------------------------
void __fastcall TFPhoto::DisplayRationale(TObject *Sender, const TClassicStringDynArray APermissions, const _di_TProc APostRationaleProc)
{
    String RationaleMsg;
    for (int i = 0; i < APermissions.Length; i++)
    {
        if (APermissions[i] == FPermissionCamera)
            RationaleMsg = RationaleMsg + "The app needs to access the camera to take a photo" + sLineBreak + sLineBreak;
        else if (APermissions[i] == FPermissionReadExternalStorage)
            RationaleMsg = RationaleMsg + "The app needs to read a photo file from your device";
    }

    // Show an explanation to the user *asynchronously* - don't block this thread waiting for the user's response!
    // After the user sees the explanation, invoke the post-rationale routine to request the permissions
    TDialogService::ShowMessage(RationaleMsg,
        [APostRationaleProc](TModalResult AKey)
        {
            APostRationaleProc->Invoke();
        });
}

void __fastcall TFPhoto::sendTextViaIntent(System::UnicodeString text)
{

//    Androidapi::Jni::Graphicscontentviewtext::_di_JIntent intent = TJIntent::Create();
//    intent->setType(StringToJString("text/cpp")); intent->setAction(TJIntent::JavaClass->ACTION_VIEW);
//    intent->putExtra(TJIntent:: JavaClass-> EXTRA_TEXT,StringToJString(text));
//    if (MainActivity()->getPackageManager()->queryIntentActivities (intent, TJPackageManager::JavaClass->MATCH_DEFAULT_ONLY)->size() > 0) {
//    MainActivity()->startActivity(intent);
//    }
//    else {
//    ShowMessage ("Receiver not found");
//    }
}

// ---------------------------------------------------------------------------
void __fastcall TFPhoto::TakePicturePermissionRequestResult(TObject *Sender, const TClassicStringDynArray APermissions, const TClassicPermissionStatusDynArray AGrantResults)
{

}
//---------------------------------------------------------------------------

void __fastcall TFPhoto::btTakePhotoClick(TObject *Sender)
{
    DynamicArray<String> permissions {FPermissionCamera};

    PermissionsService()->RequestPermissions(permissions, TakePicturePermissionRequestResult, DisplayRationale);

    //Envoi d'un intent pour activer le scanner du Zebra TC21 via DataWedge
    Androidapi::Jni::Graphicscontentviewtext::_di_JIntent intent = TJIntent::Create();
    intent->setAction(StringToJString("com.symbol.datawedge.api.ACTION"));
    intent->putExtra(StringToJString("com.symbol.datawedge.api.SCANNER_INPUT_PLUGIN"), StringToJString("ENABLE_PLUGIN"));
    intent->putExtra(StringToJString("SEND_RESULT"), StringToJString("true"));
    intent->putExtra(StringToJString("COMMAND_IDENTIFIER"), StringToJString("MY_ENABLE_SCANNER"));
    MainActivity()->sendBroadcast(intent);
}

//---------------------------------------------------------------------------
void __fastcall TFPhoto::FormCreate(TObject *Sender)
{
    Androidapi::Jni::Graphicscontentviewtext::_di_JIntentFilter filter = TJIntentFilter::Create();
    filter->addAction(StringToJString("com.symbol.datawedge.api.RESULT_ACTION"));
//    Androidapi::Jni::Graphicscontentviewtext::_di_JBroadcastReceiver receiver = TJBroadcastReceiver::Create();

//    MainActivity()->registerReceiver(receiver, filter);
}
//----

CONTACT
Can’t find what you’re looking for?