Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi Experts,

I want to encode byte array to string in android 4.0 application,
and decode this string to byte array in C# .Net Web service.

I only want a function for encode byte array in android 4.0
and decode this string in .Net Web Service.

Any one can help me...?
Thanks in advance
Posted

Hello friend,

you can use this two methods for converting bytes to string encoding with base64 and visa versa

C#
internal byte[] StringToBytes(string streamString)
{
     return Convert.FromBase64String(streamString);
}

internal string BytesToString(byte[] stream)
{
    return Convert.ToBase64String(stream);
}


for android please review this links...

http://developer.android.com/reference/android/util/Base64.html[^]


http://www.javatips.net/blog/2011/08/how-to-encode-and-decode-in-base64-using-java[^]

http://www.rgagnon.com/javadetails/java-0598.html[^]
 
Share this answer
 
v2
Comments
Mr. Mahesh Patel 26-Feb-13 7:51am    
Are u sure that BytesToString is working fine in android...?
Tejas Vaishnav 26-Feb-13 7:57am    
its for C# only for your webservice, you need to find android base64bit converter on
http://developer.android.com/reference/android/util/Base64.html

http://www.javatips.net/blog/2011/08/how-to-encode-and-decode-in-base64-using-java

http://www.rgagnon.com/javadetails/java-0598.html
Just in case google isn't working for you I found this by doing a simple search:
Android:
android.util.Base64 extends java.lang.Object[^]

.NET:
http://msdn.microsoft.com/en-us/library/system.convert.frombase64string.aspx[^]

Regards,

— Manfred
 
Share this answer
 
Comments
Mr. Mahesh Patel 26-Feb-13 7:52am    
I have already use this both function but it is giving error of "Invalid image or unsupported image format" while i decode string in byte array and use it as image at .Net Side.
Manfred Rudolf Bihy 26-Feb-13 8:11am    
Then why didn't you include that information in your question.
Your are wasting ours and your time as well.
Please read the forum posting guidelines.
CPallini 26-Feb-13 8:33am    
If you have such problems you have to debug: see how Android side encodes and how the .NET side decodes. Base64 is not rocket science.
BTW could even be that .NET actually doesn't support the image format.
Manfred Rudolf Bihy 26-Feb-13 8:34am    
Just a thought: Why don't you start with somthing where you have a little more control. Fill a byte array with a sequence of bytes from 0 to 111. The convert that on Android and send it to .NET where you will decode it. You can then verify if the array contains the same sequence.
I suspect you may be having a problem with the image conversuin.

Please try to verify the basics operations first, before you build something more complex with it. It will help you pin down where your problems really are.

Regards,

<dd>—Manfred</dd>
Mr. Mahesh Patel 26-Feb-13 8:28am    
I have try lots of links, How can I post all the things,
You should have to give answer with confident and conformation.
Please don't give answer if you are not 100% sure.
Because I know googling very well...
Thanks for your time, I dont need more times from you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900