Click here to Skip to main content
Sign Up to vote bad
good
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 26 Feb '13 - 1:17


2 solutions

Hello friend,
 
you can use this two methods for converting bytes to string encoding with base64 and visa versa
 
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[^]
  Permalink  
Comments
Mr. Mahesh Patel - 26 Feb '13 - 7:51
Are u sure that BytesToString is working fine in android...?
Tejas Vaishnav - 26 Feb '13 - 7:57
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
  Permalink  
Comments
Mr. Mahesh Patel - 26 Feb '13 - 7:52
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 R. Bihy - 26 Feb '13 - 8:11
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:33
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 R. Bihy - 26 Feb '13 - 8:34
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:28
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.
CPallini - 26 Feb '13 - 8:31
I'm confident he is confident.
Manfred R. Bihy - 26 Feb '13 - 8:38
Please don't be abusive, you are the one asking the questions, not I. Read my comment where I'm guiding you on how to go about finding where you problems really are. And you are not supposed post everything you tried, but that doesn't mean not giving anything about what you did at all is any better. Start using your brain, and quit being obnoxious. I'll consider reporting the abuse. Regards, <dd>— Manfred</dd>
CPallini - 26 Feb '13 - 8:31
My 5.
Manfred R. Bihy - 26 Feb '13 - 8:38
Thank you!

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 178
1 Tadit Dash 144
2 Santhosh G_ 140
3 Sergey Alexandrovich Kryukov 134
4 Espen Harlinn 120
0 Sergey Alexandrovich Kryukov 10,348
1 OriginalGriff 7,965
2 CPallini 4,241
3 Rohan Leuva 3,522
4 Maciej Los 3,184


Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 26 Feb 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid