Setting Avatar using asmack - android

I am making a chat application for android and i am using asmack. My question is how do i set v-card avatar using asmack. what i am doing is as follows but the avatar is not getting saved. when i retrive avatar i got null
public static void setAvatarInVCard(){
urldefault=new URL("https://s3.amazonaws.com/ksr/avatars/3075521/Avatar.small.jpg");
java.io.InputStream stream = urldefault.openStream();
byte[] avatar1 = IOUtils.toByteArray(stream);
System.out.println("avatar length "+avatar1.length);
VCard vCard = new VCard();
vCard.setAvatar(avatar1, "avatar1/jpg");
vCard.save(MyService.getConnection());
}
when i logcat result using asmack what stanza it was sending is as follows and the ending tags were not present either.
PM SENT (1090972696): <iq id="7hY4J-7" from="111#192.168.1.7/Smack" type="set"><vCard xmlns='vcard-temp'><PHOTO><BINVAL>/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAICAgICAQICAgIDAgIDAwYEAwMDAwcFBQQGCAcJCAgHCAgJCg0LCQoMCggICw8LDA0ODg8OCQsQERAOEQ0ODg7/2wBDAQIDAwMDAwcEBAcOCQgJDg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg7/wAARCABQAFADASIAAhEBAxEB/8QAHQAAAgIDAQEBAAAAAAAAAAAABwgFBgMECQECAP/EAEIQAAEEAQMCBAMEBQcNAAAAAAECAwQFBgcREgAhCBMiMQkUQSMyUWEVFhhCkSQzNFNnccEXUmJyc4GDkqGisbXw/8QAGgEAAwADAQAAAAAAAAAAAAAABQYHAgQIA//EAC8RAAEDAgQEBAcAAwAAAAAAAAECAxEABAUhMUEGElGhExRhgSIjMnGx0fAHkfH/2gAMAwEAAhEDEQA/AGL8xe331f8AN0r3ioznKsU0VgwMYta6BJu5JiOoekrTPkN7buIjAIUlACdyt5RHBPZPqUD0z3SIeMS+xl3JsKxBcGvk5LwXayZC2kKltxWifJYQo+pKXHQpZA2BDXfseqdibhaslkGDUA4fYD
i also try sending the URL directly like this
vCard.setAvatar(urldefault);
but still avatar not getting saved the log-cat result is as follows.
03-14 18:06:37.199: D/SMACK(3210): 06:06:37 PM SENT (1090973048): <iq id="5SfDm-9" from="111#192.168.1.7/Smack" type="set"><vCard xmlns='vcard-temp'/>
03-14 18:06:37.289: D/SMACK(3210): 06:06:37 PM RCV (1090973048): <iq type="result" id="5SfDm-9" to="111#192.168.1.7/Smack"/>
Thanks for the help in advance.

How big is the size of this image , i think its supposed be well within a range of 1 mb (Guess approx) or less, because i face the same issue and i get XML Stanza is too big as a response and the connection breaks , im looking at options to minimize the bitmap size

Related

Maintaining session with cookies android

Hi I am developing android application in which i wanted to set cookies for session handling.
I am using datadroid library for network call which uses HttpURLConnection in background. After log in process I tried to set cookies and after that for every call i tried to pass cookies. But it gives me no valid session. I did this in following ways.
after login process :
header = result.headerMap //this gves me header part after log in responce.
so this header variable looks like
{Cache-Control=[no-store, no-cache, must-revalidate, post-check=0, pre-check=0],
***Connection=[close]***, Content-Encoding=[gzip], Content-Length=[173], Content-Location=
[login.php], Content-Type=[application/json], Date=[Wed, 20 Mar 2013 04:05:38 GMT],
Expires=[Thu, 19 Nov 1981 08:52:00 GMT], Pragma=[no-cache], Server=[Apache/2.2.22
(Fedora)],
***Set-Cookie***=[QCSESSID=mckdk1povn625jk1bhs11m0t97; path=/,
QCSESSID=d44cnlf6gv2ii8lt76tr7vbqm4; path=/], TCN=[choice], Vary=[negotiate,Accept-
Encoding,User-Agent]}
SO for my next web call i using Set-Cookies part
connect_status= header.get("Connection");
login_cookie= header.get("Set-Cookie");
cookie1=login_cookie.get(0);
cookie2=login_cookie.get(1);
// This is datadroid syntax. So here I m setting cookies for my next call
login_header.put("User-Agent"," Apache-HttpClient/4.2.3 (java 1.5)");
login_header.put("Connection" ,"Keep-Alive");
login_header.put("Cookie", cookie2);
networkConnection.setHeaderList(login_header);
But still it gives me error that no valid session exits. My header response showing me that parameter for connection is closed so i tried with connection "keep-alive as well" But that also not working. Am I doing something wrong? Need help. How to solve this problem.
If I tried it with one of my GET API call its working fine. But when i use it with my PUT API call it gives me session problem "Session does not exit".
Thank you.

asmack pubsub getItems error

I'm trying to publish some information to server using the Pubsub nodes.unfortunately,I failed to retrieve the node that published before.Just very similar as the problem in the following link:
http://community.igniterealtime.org/message/199690#199690
to be specific, the code snippets like following :
try {
LeafNode node = mPubsub.getPEPNode(USEINFONODE,mFrom);
if(null != node){
List<Item> items = node.getItems();
Log.i("items",items.toString());
}
} catch (XMPPException e) {
Log.e("userInfoExtension","error : and the error is " + e.toString());
}
and the output error is no resposne from server.
the output of the debug is just like this:
<iq id="B9tI0-4" to="pubsub.mymachine" type="get"><query xmlns="http://jabber.org/protocol/disco#info" node="theNode"></query></iq>
<iq id="B9tI0-5" to="pubsub.mymachine" type="get"><pubsub xmlns="http://jabber.org/protocol/pubsub"><items node='theNode'/></pubsub></iq>
However according to the link mentioned above, the expected iq stanza shall be like this:
<iq type='get'
from='notifyserver#mymachine'
to='pubsub.mymachine'
id='items1'>
<query xmlns='http://jabber.org/protocol/disco#items'
node='theNode'/>
</iq>
so It shows that I miss the from field in the iq stanza,I'm wondering how can I put the from ='client#server' into the iq stanza. I have tried asmack libraries including :
asmack-android-7.jar , asmack-android-7-beem.jar asmack-android-16-beem.jar,all failed.
Can anyone help with this? Thanks very much.
I have found that it has something to do with receiving the packet. actually I have received the packet that I needed, the trouble is that the packet may can not be processed by smack in somewhere, and it will throw no response from sever exception.
so I think the problem is actually not receiving incoming packet correctly .
so does in my other question:
http://stackoverflow.com/questions/14357707/how-to-send-and-listen-to-custom-xmpp-presence-packet-with-asmack-the-library
I'm sorry to mislead you ! the error is caused by my extension provider which lead the parsing
packet into an endless loop, thus ,caused the no response from server exception.

Comment on an update in linkedin from android application

Can anyone help me to send a comment/reply on a particular post in linkedin?
I am able to send direct message to linked in via my android application using following code using person id.
id = update.getUpdateContent().getPerson().getId()
.....
LinkedInAccessToken accessToken = new LinkedInAccessToken(
linkedInTokens[0], linkedInTokens[1]);
LinkedInApiClientFactory clientFactory = LinkedInApiClientFactory
.newInstance(LinkedInConstants.LINKEDIN_CONSUMER_KEY,
LinkedInConstants.LINKEDIN_CONSUMER_SECRET);
LinkedInApiClient client = clientFactory
.createLinkedInApiClient(accessToken);
client.sendMessage(Arrays.asList(id), "subjectText",
"postingText");
can anyone help me to reply a post?
Thank you
Assuming you know the network update key of the update you'd like to comment on, the API call to do this would be:
POST http://api.linkedin.com/v1/people/~/network/updates/key={NETWORK UPDATE KEY}/update-comments
An example of the XML body of the comment:
<?xml version='1.0' encoding='UTF-8'?>
<update-comment>
<comment>Really great article!</comment>
</update-comment>

Android URLConnection class cannot get content lenght using 3G internet connection

I've got the following piece of code:
URL url = new URL("http://myserver.com/getFile.php");
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
Everything works fine until I work with WiFi connection. If I try to run this code when there is only GPRS/3G connection available, conexion.getContentLength() returns -1.
Any idea why?
EDIT:
I've check the headers using getHeaderFields(). They are different if I use 3G network. Basically there is no Content-Length in this case. Any idea why server returns different headers? I'm not using any special script to provide the file, I only get the file that is placed at given location.
Entire header for the WiFi case:
{Accept-Ranges=[bytes], Connection=[Keep-Alive], Content-Length=[628254], Content-Type=[text/plain; charset=UTF-8], Date=[Tue, 29 Nov 2011 11:22:50 GMT], ETag=["7a0c7-9961e-4af3f38778500"], Keep-Alive=[timeout=15], Last-Modified=[Fri, 14 Oct 2011 09:52:52 GMT], Server=[Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny9 with Suhosin-Patch mod_python/3.3.1 Python/2.6.6 mod_ssl/2.2.9 OpenSSL/0.9.8o mod_wsgi/3.3 mod_perl/2.0.4 Perl/v5.10.0]}
Entire header for the case when using 3G:
{Accept-Ranges=[bytes], Connection=[Keep-Alive], Content-Type=[text/plain; charset=UTF-8], Date=[Tue, 29 Nov 2011 11:20:33 GMT], ETag=["7a0c7-9961e-4af3f38778500"], Keep-Alive=[timeout=15], Last-Modified=[Fri, 14 Oct 2011 09:52:52 GMT], Server=[Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny9 with Suhosin-Patch mod_python/3.3.1 Python/2.6.6 mod_ssl/2.2.9 OpenSSL/0.9.8o mod_wsgi/3.3 mod_perl/2.0.4 Perl/v5.10.0], Transfer-Encoding=[chunked], Warning=[214 warkaz-fe07 "Transformation applied"]}
Are you sure that the server provides the content length by sending the Content-Length header in the response?
From the headers it's clear that your provider has some kind of proxy in place that does a transformation, stripping the content-length in the process. The warning header clearly indicates this. You could try returning a different type of content type (you are now getting text/plain), maybe this particular proxy won't touch it. It's not a great solution of course, there are a lot things carriers may have to "optimize" their network in some way.
You could also try a HEAD request using a range header to get a ballpark of the content size. In that case you'd guess a few ranges, like 100k, 1000k etc to see if the server thinks that's an acceptable range. You could use that fake range for your progress. Again, this isn't a very good solution but if you really need the progress, it's something to try.
In the end it's best to just show the progress as unknown if there's no length known.
Since you are using
new URL("http://myserver.com/getFile.php");
I suppose you are using a personal server that you have set up, and when using WiFi your phone is in your local network and thereby can see your server, but when you are trying to connect via GPRs/3G you are trying to access your local server from the internet.
It is probably due to a limitation from your carrier. Try to avoid needing this value. (for example, by reading the inputStream until you cannot read it).

Android streaming from icecast server get track information

I have a stream from an icecast server downloading, and I can grab the information in the headers by doing the following:
URLConnection cn = new URL(mediaUrl).openConnection();
cn.connect();
int pos=1;
String x;
String y;
while (cn.getHeaderField(pos) != null)
{
x=cn.getHeaderFieldKey(pos);
y = cn.getHeaderField(x);
Log.e(":::::",""+x+" : "+y);
pos++;
}
When I do this all of the headers I receive are shown as:
content-type : audio/mpeg
icy-br : 64
ice-audio-info : ice-samplerate=22050;ice-bitrate=64;ice-channels=2
icy-br : 64
icy-description : RadioStation
icy-genre : Classical, New Age, Ambient
icy-name : RadioStation Example
icy-private : 0
icy-pub : 1
icy-url : http://exampleradio.com
server : Icecast 2.3.2
cache-control : no-cache
However if I open my stream in mplayer I get:
ICY Info: StreamTitle='artist - album - trackname'
and with each time the song is changed, the new track information is sent appearing the same way in mplayer.
In android when I attempt to read the icy-info all I get returned is null. Also how would I go about retrieving the new information from the headers while I am buffering from the stream? Because even if I try to read the header of something I already know exists whilst buffering such as:
Log.e(getClass().getName()," "+cn.getHeaderField("icy-br"));
All I get returned is null.
I hope this makes sense, I can post more code on request.
I realize this question is old, but for others who are facing this challenge, I am using this project: http://code.google.com/p/streamscraper/ to get track information from an icecast stream. I'm using it on android and so far it works as expected.
All you need is to setDataSource() and pass the URL as a String, then you must prepareAsync() and with a mp.setOnPreparedListener(this); or etc. you will get noticed when the MediaPlayer is done buffering, then all you need to do is mp.start(); P.S.: Don't forget to mp.stop, mp.reset and mp.release upon destroying the application. ;) I'm still thinking of a way to read the ICY info... I must either make my own buffering mechanism and write a buffer file (init the MediaPlayer with FileDescriptor) or make a separate connection from time to time to check for ICY info tags and close the connection... Any better ideas anyone?

Categories

Resources