新到Android - 如何使用SocialAuthAdapter类中找到的“uploadImage'的方法 [英] new to android - how to use the 'uploadImage' method found in SocialAuthAdapter class

查看:119
本文介绍了新到Android - 如何使用SocialAuthAdapter类中找到的“uploadImage'的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上传图片到Twitter。 <一href=\"https://$c$c.google.com/p/socialauth-android/source/browse/trunk/socialauth-android/src/org/brickred/socialauth/android/SocialAuthAdapter.java?r=319\"相对=nofollow> SocialAuthAdapter类包含了一个'uploadImage方法,它应该这样做。

下面是我的code:

 公共无效post_image(){
文件imgFile =新的文件(/存储/ sdcard0 / pic_app / ubgthyghu.com2013923.png);
bitmap2 =去codeFILE(imgFile); //这只是带回一个调整位图,它的工作..我测试了它
尝试{
Log.d(标签*********************图象将要被更新的...);
INT返回值= adapter.uploadImage(弗雷德,ubgthyghu.com2013923.png,bitmap2,3);
Log.d(标签,这里是返回值:+返回值);
}赶上(例外五){Log.d(标签,你长了一个错误豪斯); e.printStackTrace();}
} // post_image

然而

我收到以下消息后面:

  7月9日至27日:39:16.280:D / ShareButtonActivity(11622):***********图片将要被更新...
7月9日至27日:39:16.400:D / dalvikvm(11622):GC_CONCURRENT释放424K,免费10%12775K / 14151K,暂停11毫秒+ 1毫秒,总19ms
7月9日至27日:39:16.400:D / dalvikvm(11622):WAIT_FOR_CONCURRENT_GC 7毫秒受阻
7月9日至27日:39:16.400:I / TwitterImpl(11622):上载图片:: ubgthyghu.com2013923.png,消息::弗雷德
7月9日至27日:39:16.405:D / ShareButtonActivity(11622):你长了一个错误豪斯
7月9日至27日:39:16.405:W / System.err的(11622):org.brickred.socialauth.exception.SocialAuthException:图片上传错误
7月9日至27日:39:16.405:W / System.err的(11622):在org.brickred.socialauth.android.SocialAuthAdapter.uploadImage(SocialAuthAdapter.java:1137)
7月9日至27日:39:16.405:W / System.err的(11622):在com.example.twitter_stuff.ShareButtonActivity.post_image(ShareButtonActivity.java:273)
7月9日至27日:39:16.405:W / System.err的(11622):在com.example.twitter_stuff.ShareButtonActivity$ResponseListener$1.onClick(ShareButtonActivity.java:171)
7月9日至27日:39:16.405:W / System.err的(11622):在android.view.View.performClick(View.java:4223)
7月9日至27日:39:16.405:W / System.err的(11622):在android.view.View $ PerformClick.run(View.java:17281)
7月9日至27日:39:16.405:W / System.err的(11622):在android.os.Handler.handleCallback(Handler.java:615)
7月9日至27日:39:16.405:W / System.err的(11622):在android.os.Handler.dispatchMessage(Handler.java:92)
7月9日至27日:39:16.405:W / System.err的(11622):在android.os.Looper.loop(Looper.java:137)
7月9日至27日:39:16.405:W / System.err的(11622):在android.app.ActivityThread.main(ActivityThread.java:4898)
7月9日至27日:39:16.405:W / System.err的(11622):在java.lang.reflect.Method.invokeNative(本机方法)
7月9日至27日:39:16.410:W / System.err的(11622):在java.lang.reflect.Method.invoke(Method.java:511)
7月9日至27日:39:16.410:W / System.err的(11622):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1008)
7月9日至27日:39:16.410:W / System.err的(11622):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
7月9日至27日:39:16.410:W / System.err的(11622):在dalvik.system.NativeStart.main(本机方法)
7月9日至27日:39:16.440:D / SocialAuthError(11622):org.brickred.socialauth.exception.SocialAuthException:无法更新状态上http://api.twitter.com/1.1/statuses/update.json?status = hjjhhj。状态:403
7月9日至27日:39:16.440:D / ShareButton(11622):身份验证错误:消息未发布
7月9日至27日:39:16.455:D / SocialAuthError(11622):org.brickred.socialauth.exception.SocialAuthException:无法更新状态上http://api.twitter.com/1.1/statuses/update.json?status = hjjhhj。状态:403
7月9日至27日:39:16.455:D / ShareButton(11622):身份验证错误:消息未发布

我知道这是相当混乱就绪 - 抱歉,但它从主code这需要修复的是:

  INT返回值= adapter.uploadImage(弗雷德,ubgthyghu.com2013923.png,bitmap2,3);


解决方案

使用 adapter.uploadImageAsync
你是含蓄执行上的主UI威胁 HTTP 操作。 Android的犯规一样,

I am trying to upload an image to twitter. SocialAuthAdapter class contains an 'uploadImage' method which should do it.

Here is my code:

public void post_image(){ 
File imgFile = new  File("/storage/sdcard0/pic_app/ubgthyghu.com2013923.png");
bitmap2 = decodeFile(imgFile); //this just brings back a resized bitmap, it works.. i  tested it
try {
Log.d(tag,"********************* picture is going to be updated...");
int returnvalue  = adapter.uploadImage("fred", "ubgthyghu.com2013923.png", bitmap2, 3);
Log.d(tag,"here is the return value:  " + returnvalue );
} catch (Exception e) {Log.d(tag,"u got an error haus");  e.printStackTrace();}
}//post_image

however i get the following message back:

09-27 07:39:16.280: D/ShareButtonActivity(11622): ********************* picture is going to be updated...
09-27 07:39:16.400: D/dalvikvm(11622): GC_CONCURRENT freed 424K, 10% free 12775K/14151K, paused 11ms+1ms, total 19ms
09-27 07:39:16.400: D/dalvikvm(11622): WAIT_FOR_CONCURRENT_GC blocked 7ms
09-27 07:39:16.400: I/TwitterImpl(11622): Uploading Image :: ubgthyghu.com2013923.png, message :: fred
09-27 07:39:16.405: D/ShareButtonActivity(11622): u got an error haus
09-27 07:39:16.405: W/System.err(11622): org.brickred.socialauth.exception.SocialAuthException: Image Upload Error
09-27 07:39:16.405: W/System.err(11622): at org.brickred.socialauth.android.SocialAuthAdapter.uploadImage(SocialAuthAdapter.java:1137)
09-27 07:39:16.405: W/System.err(11622): at com.example.twitter_stuff.ShareButtonActivity.post_image(ShareButtonActivity.java:273)
09-27 07:39:16.405: W/System.err(11622): at com.example.twitter_stuff.ShareButtonActivity$ResponseListener$1.onClick(ShareButtonActivity.java:171)
09-27 07:39:16.405: W/System.err(11622): at android.view.View.performClick(View.java:4223)
09-27 07:39:16.405: W/System.err(11622): at android.view.View$PerformClick.run(View.java:17281)
09-27 07:39:16.405: W/System.err(11622): at android.os.Handler.handleCallback(Handler.java:615)
09-27 07:39:16.405: W/System.err(11622): at android.os.Handler.dispatchMessage(Handler.java:92)
09-27 07:39:16.405: W/System.err(11622): at android.os.Looper.loop(Looper.java:137)
09-27 07:39:16.405: W/System.err(11622): at android.app.ActivityThread.main(ActivityThread.java:4898)
09-27 07:39:16.405: W/System.err(11622): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 07:39:16.410: W/System.err(11622): at java.lang.reflect.Method.invoke(Method.java:511)
09-27 07:39:16.410: W/System.err(11622): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
09-27 07:39:16.410: W/System.err(11622): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
09-27 07:39:16.410: W/System.err(11622): at dalvik.system.NativeStart.main(Native Method)
09-27 07:39:16.440: D/SocialAuthError(11622): org.brickred.socialauth.exception.SocialAuthException: Failed to update status on http://api.twitter.com/1.1/statuses/update.json?status=hjjhhj. Status :403
09-27 07:39:16.440: D/ShareButton(11622): Authentication Error: Message Not Posted
09-27 07:39:16.455: D/SocialAuthError(11622): org.brickred.socialauth.exception.SocialAuthException: Failed to update status on http://api.twitter.com/1.1/statuses/update.json?status=hjjhhj. Status :403
09-27 07:39:16.455: D/ShareButton(11622): Authentication Error: Message Not Posted

I know that is quite messy to ready - sorry but the main code from it which needs to be fixed is this:

int returnvalue  = adapter.uploadImage("fred", "ubgthyghu.com2013923.png", bitmap2, 3);

解决方案

Use adapter.uploadImageAsync You are implicity performing a http action on the main ui threat. Android doesnt like that

这篇关于新到Android - 如何使用SocialAuthAdapter类中找到的“uploadImage'的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆