Android Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsMobile ProgrammingAndroid Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 21st, 2013, 07:27 PM
rfabbc rfabbc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 rfabbc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 29 sec
Reputation Power: 0
Question [B instead of byte[]

Hi guys,

There is a private method as the following:

Code:
private void android.telephony.SmsManager.sendRawPdu(byte[],byte[],android.app.PendingIntent,android.app.PendingIntent)


And this code snippet DOES work well:

Code:
private void sendSMS(byte[] encodedAddress, byte[] encodedMessage) {
Method mtd1 = SmsManager.class.getDeclaredMethod("sendRawPdu", byte[].class, byte[].class, PendingIntent.class, PendingIntent.class);
mtd1.setAccessible(true);
mtd1.invoke(SmsManager.getDefault(), encodedAddress, encodedMessage, null, null);
}



On another device, there is another signature for this method, as below:

Code:
private void android.telephony.SmsManager.sendRawPdu([B,[B,android.app.PendingIntent,android.app.PendingIntent)


This one uses '[B' instead of 'byte[]'. I've tried the above code snippet but it does NOT work. Please help me to re-write the code.

Thanks a lot.

Reply With Quote
  #2  
Old February 22nd, 2013, 12:57 AM
salem's Avatar
salem salem is online now
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,906 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 4 Days 1 h 31 m 41 sec
Reputation Power: 1774
> This one uses '[B' instead of 'byte[]'. I've tried the above code snippet but it does NOT work. Please help me to re-write the code.
Is that something you copied off a web page?

Because it seems to me that it's far more likely that some HTML formatting got carried away and munged the code.
[B by itself makes no syntactic sense.

The first one works, and would work on any Android device.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
  #3  
Old February 22nd, 2013, 04:59 AM
rfabbc rfabbc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 rfabbc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 29 sec
Reputation Power: 0
Quote:
Originally Posted by salem
> This one uses '[B' instead of 'byte[]'. I've tried the above code snippet but it does NOT work. Please help me to re-write the code.
Is that something you copied off a web page?

Because it seems to me that it's far more likely that some HTML formatting got carried away and munged the code.
[B by itself makes no syntactic sense.

The first one works, and would work on any Android device.

hi salem, thank you for your response.

It is not a mispelling, [B is a class name of the byte array byte[]
you can see the link here: stackoverflow.com/questions/4606864/what-kind-of-java-type-is-b

The problem is that the sendRawPdu method does not exist on all Android devices, and the signature also are not the same. On some device it does NOT exist at all. On some device it exists with the signature #1, on other devices with the signature #2...

With the signature #1, the above code work well. But it does not work with signature #2, although [B and byte[] are almost the "same".

I dont know why and how to correct the code?

Reply With Quote
  #4  
Old February 22nd, 2013, 07:11 AM
salem's Avatar
salem salem is online now
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,906 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 4 Days 1 h 31 m 41 sec
Reputation Power: 1774
Yes, the keyword being "JNI"

The Java Native Interface uses coded strings ( like [B ) to allow the native implementation (C or C++) to correctly specify the APIs it implements, so the Java runtime knows what it is calling.

As far as I know, it does not appear in Java code proper, and if it's screwing up, then it seems the JNI implementation is broken.

Reply With Quote
  #5  
Old February 22nd, 2013, 07:40 AM
rfabbc rfabbc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 rfabbc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 29 sec
Reputation Power: 0
Quote:
Originally Posted by salem
Yes, the keyword being "JNI"

The Java Native Interface uses coded strings ( like [B ) to allow the native implementation (C or C++) to correctly specify the APIs it implements, so the Java runtime knows what it is calling.

As far as I know, it does not appear in Java code proper, and if it's screwing up, then it seems the JNI implementation is broken.


So what I can do with the 2-nd signature?

How can I write the code?

Reply With Quote
  #6  
Old February 22nd, 2013, 10:30 AM
salem's Avatar
salem salem is online now
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,906 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 4 Days 1 h 31 m 41 sec
Reputation Power: 1774
I don't know.

Perhaps you should post more information.

Like for example, actual URLs of where the WHOLE code of what you found can be read by all (to establish the context).

One line of code and "it doesn't work" is hardly the basis of a meaningful error report.

All I can say is that case 1 works and case 2 doesn't (because it doesn't look like any Java I've seen before).
I've just searched all of the Android source tree, and there's nothing like that in any of the standard Java code.

The only place where you see the [B notation is in JNI interfaces - eg.
Code:
// ./frameworks/base/core/jni/android_os_Parcel.cpp

static const JNINativeMethod gParcelMethods[] = {
...
    {"nativePushAllowFds",        "(IZ)Z", (void*)android_os_Parcel_pushAllowFds},
    {"nativeRestoreAllowFds",     "(IZ)V", (void*)android_os_Parcel_restoreAllowFds},

    {"nativeWriteByteArray",      "(I[BII)V", (void*)android_os_Parcel_writeNative},
...

So the C++ function android_os_Parcel_writeNative expects to be able to extract from the Java call frame (amongst other things) a byte array, as signified by "[B" in the control string.

> So what I can do with the 2-nd signature?
Delete it and replace it with the first one which works perhaps.

The second seems to be some random crap you found that could never work, so I fail to see the point of expending any more effort on it. You have something which works, go with it.

Reply With Quote
  #7  
Old February 23rd, 2013, 09:55 AM
rfabbc rfabbc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 rfabbc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 29 sec
Reputation Power: 0
Quote:
Originally Posted by salem
I don't know.

Perhaps you should post more information.

Like for example, actual URLs of where the WHOLE code of what you found can be read by all (to establish the context).

One line of code and "it doesn't work" is hardly the basis of a meaningful error report.

All I can say is that case 1 works and case 2 doesn't (because it doesn't look like any Java I've seen before).
I've just searched all of the Android source tree, and there's nothing like that in any of the standard Java code.

The only place where you see the [B notation is in JNI interfaces - eg.
Code:
// ./frameworks/base/core/jni/android_os_Parcel.cpp

static const JNINativeMethod gParcelMethods[] = {
...
    {"nativePushAllowFds",        "(IZ)Z", (void*)android_os_Parcel_pushAllowFds},
    {"nativeRestoreAllowFds",     "(IZ)V", (void*)android_os_Parcel_restoreAllowFds},

    {"nativeWriteByteArray",      "(I[BII)V", (void*)android_os_Parcel_writeNative},
...

So the C++ function android_os_Parcel_writeNative expects to be able to extract from the Java call frame (amongst other things) a byte array, as signified by "[B" in the control string.

> So what I can do with the 2-nd signature?
Delete it and replace it with the first one which works perhaps.

The second seems to be some random crap you found that could never work, so I fail to see the point of expending any more effort on it. You have something which works, go with it.


Hi salem,

The method is at the target (customer) device and I cannot delete or modify it.

BTW the code I took from here:

http://www.tutorialforandroid.com/2009/11/calling-private-methods-in-android.html

However this code is for signature #1.

On some other device the signature is as #2. And this code does not work anymore.

Reply With Quote
Reply

Viewing: Dev Shed ForumsMobile ProgrammingAndroid Development > [B instead of byte[]

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap