Delphi - android - raw data

I am integrating a third party Bluetooth printer into my Delphi XE7 Android app. For this they have provided the Jar file, license file and the manual. I used the JAVA2OP tool to generated the Delphi native bridge file from the java library. In the manual they mentioned that the License file is required to be added in the raw folder of your application project. How we do this in the Delphi? what I done is in the Project->Deployment added this file and given the remote path as 'res\raw'. is it correct? Sec
ondly they are mentioning create an object of the class 'setup', I did it and working correctly. In the setup class there is one method named ActivateLibrary to activate all the libraries in the SDK. The syntax of this function is

Boolean blActivateLibrary(Context Jcontext, int iRawFileID) 
where Context should be the Application/global information about an application environment and iRaFileID is the configuration(license) file required for activate the library.

The Java example they provided is:
SetUp1 = new Setup();
boolean activate1 = SetUp1.ActivateLibrary(context,R.raw.licence);
if (activate == true) 
{
    Log("Library Activated.");
} else if (activate == false) {
    Log("Library Not Activated.");
}

What I did in Delphi for the same is:

Location := SharedActivityContext.getResources().getIdentifier(stringtojstring('licence'), stringtojstring('raw') , stringtojstring('com.embarcadero.PrinterTest'));
setup1 := TJsetup.Create;
if setup1 <>  nil then
begin
activate :=  setup1.blActivateLibrary(SharedActivityContext.getApplicationContext,Location) ;
if activate then
    showmessage('Library activated')
else
    showmessage('Library not activated');
end;

However, I am always getting the return value false. Is there anything wrong in it? I am not getting any support from the provider as they are not aware about Delphi.
0
Pramod
8/11/2015 2:39:42 AM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

7 Replies
2427 Views

Similar Articles

[PageSpeed] 1

Pramod wrote:

> what I done is in the Project->Deployment added this file and given
> the remote path as 'res\raw'. is it correct?

That, I cannot answer.

> Location := SharedActivityContext.getResources().getIdentifier(stringtojstring('licence'), 
stringtojstring('raw') , stringtojstring('com.embarcadero.PrinterTest'));

Did you verify that Location is not 0?  You could also try this:

{code}
Location := SharedActivityContext.getResources().getIdentifier(stringtojstring('com.embarcadero.PrinterTest:raw/licence'), 
nil, nil);
{code}

> activate := setup1.blActivateLibrary(SharedActivityContext.getApplicationContext, 
Location) ;

Have you tried using SharedActivityContext itself instead of getApplicationContext()?

{code}
activate := setup1.blActivateLibrary(SharedActivityContext, Location);
{code}

> However, I am always getting the return value false. Is there anything wrong in it?
> I am not getting any support from the provider as they are not aware about Delphi.

Any chance that the library is outputting some error information to Android's logcat to explain why it is failing?  Does the library provide any API to retrieve error information directly?

-- 
Remy Lebeau (TeamB)
0
Remy
8/11/2015 4:30:27 AM
Hello,

have you already run monitor.bat from you Android SDK's installation to
view the log messages during your program run? M;aybe they reveal something?

(I'd suspect a wrong path for the licence file)

Greetings

Markus
0
Markus
8/11/2015 9:33:13 PM
> Did you verify that Location is not 0? You could also try this:
yes the location is greater than zer, i tried the one you suggested and working 
> Have you tried using SharedActivityContext itself instead of getApplicationContext()?
yes getting the same result - False
> Any chance that the library is outputting some error information to Android's logcat to explain why it is failing? 
> have you already run monitor.bat 
I made below changes in the code and received the below log in the monotor.bat. Here it is showing the setup is the issue but i am getting a value greater than zero for the object when debug. Please advise

  setup1 := nil;
  log.d('Finding the Raw file id of the license');
  Loca :=  SharedActivityContext.getResources().getIdentifier(stringtojstring('licence'), stringtojstring('raw') , stringtojstring('com.embarcadero.PrinterTest2'));
  log.d('Initiliazing the setup');
  setup1 := TJsetup.Create;

  if setup1 <>  nil then
  begin
     log.d('activating the library');
     activate :=  setup1.blActivateLibrary(SharedActivityContext,Loca) ;
     if activate then
     begin
        log.d('Library activated');
        showmessage('Library activated');
     end
     else
     begin
        log.d('Library not activated');
        showmessage('Library not activated');
     end;
  end;


08-13 09:54:35.602: I/info(23870): FMX: PrinterTest2: Finding the Raw file id of the license
08-13 09:54:35.613: I/info(23870): FMX: PrinterTest2: Initiliazing the setup
*08-13 09:54:35.613: W/dalvikvm(23870): dvmFindClassByName rejecting 'com/prowesspride/api/Setup'*
08-13 09:54:35.623: I/info(23870): FMX: PrinterTest2: activating the library
08-13 09:54:35.623: I/info(23870): FMX: PrinterTest2: Library not activated
8-13 09:54:35.623: W/dalvikvm(23870): dvmFindClassByName rejecting 'com/embarcadero/firemonkey/dialogs/FMXDialogFactory'
08-13 09:54:35.623: W/dalvikvm(23870): dvmFindClassByName rejecting 'com/embarcadero/firemonkey/dialogs/FMXStandardDialog'
08-13 09:54:35.703: D/dalvikvm(23870): GC_FOR_ALLOC freed 170K, 11% free 8281K/9204K, paused 15ms, total 15ms
08-13 09:54:35.713: D/KeyguardUpdateMonitor(1434): sendKeyguardVisibilityChanged(true)
08-13 09:54:35.713: I/KeyguardUpdateMonitor(1434): visibility is same




> {quote:title=Markus Humm wrote:}{quote}
> Hello,
> 
> have you already run monitor.bat from you Android SDK's installation to
> view the log messages during your program run? M;aybe they reveal something?
> 
> (I'd suspect a wrong path for the licence file)
> 
> Greetings
> 
> Markus
0
Pramod
8/13/2015 5:09:26 AM
Pramod wrote:

> Please advise

Contact the API vendor and ask if they can provide you with a JAR that outputs 
diagnostic messages during activation, or throws an exception with error 
details, or something.  As it current stands, there is clearly a problem 
inside their API and nothing is telling you what is going wrong with it.

The only other possibility I can think of right now is if your project has 
a different raw resource named "license" that getIdentifier() is returning 
the ID of, and blActivateLibrary() is failing because it is not finding its 
expected license file.

-- 
Remy Lebeau (TeamB)
0
Remy
8/13/2015 6:28:25 AM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> The only other possibility I can think of right now is if your project has 
> a different raw resource named "license" that getIdentifier() is returning 
> the ID of, and blActivateLibrary() is failing because it is not finding its 
> expected license file.

Have you tried having your app open the resource data at runtime using the ID from getIdentifier(), and make sure it really is the same license file that you added to the Deployment Manager?

--
Remy Lebeau (TeamB)
0
Remy
8/13/2015 6:32:16 AM
> Have you tried having your app open the resource data at runtime using the ID from getIdentifier(), and make sure it really is the same license file that you added to the Deployment Manager?
I havent tried to open it but when I removed the license file from deployment manager then the getIdentifier returning zero that means it is working?
Also how can convert jstream to stream?

inputstream : JInputStream

inputStream = SharedActivityContext.getResources().getIdentifier(Loca);

> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> > {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> > The only other possibility I can think of right now is if your project has 
> > a different raw resource named "license" that getIdentifier() is returning 
> > the ID of, and blActivateLibrary() is failing because it is not finding its 
> > expected license file.
> 
> Have you tried having your app open the resource data at runtime using the ID from getIdentifier(), and make sure it really is the same license file that you added to the Deployment Manager?
> 
> --
> Remy Lebeau (TeamB)
0
Pramod
8/13/2015 9:43:00 AM
Pramod wrote:

> I havent tried to open it but when I removed the license file from
> deployment manager then the getIdentifier returning zero that means it
> is working?

I suppose so.

> Also how can convert jstream to stream?
> 
> inputstream : JInputStream
> 
> inputStream = SharedActivityContext.getResources().getIdentifier(Loca);

There is only one getIdentifier() method, and it does not return a stream, 
only an ID.  To get the actual data of a resource from its ID, use openRawResource() 
instead, which returns a JInputStream:

{code}
Loca := SharedActivityContext.getResources.getIdentifier(StringToJString('licence'), 
StringToJString('raw'), StringToJString('com.embarcadero.PrinterTest2'));
// alternatively, don't hard-code the app's package name, ask Android for 
it instead:
// ...getIdentifier(..., SharedActivityContext.getApplicationInfo.className);

if Loca > 0 then
begin
  inputStream := SharedActivityContext.getResources.openRawResource(Loca);
  // use inputStream as needed...
end;
{code}

You can use the JInputStream.read() methods to read the raw bytes of the 
resource.

-- 
Remy Lebeau (TeamB)
0
Remy
8/13/2015 5:23:20 PM
Reply: