Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Android service Web
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:17am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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  
v2
Comments
Mr. Mahesh Patel at 26-Feb-13 7:51am
   
Are u sure that BytesToString is working fine in android...?
Tejas Vaishnav at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 at 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 R. Bihy at 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 at 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 R. Bihy at 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 at 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.
CPallini at 26-Feb-13 8:31am
   
I'm confident he is confident.
Manfred R. Bihy at 26-Feb-13 8:38am
   
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 at 26-Feb-13 8:31am
   
My 5.
Manfred R. Bihy at 26-Feb-13 8:38am
   
Thank you!

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



Advertise | Privacy | Mobile
Web03 | 2.8.141022.2 | Last Updated 26 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100