我想在user profile pic
中展示ImageView
,我正在使用AsyncTask
来获取图片,请参阅下面的Log
:
08-20 01:22:13.621: I/ActivityManager(288): Force stopping package com.example.loginfb appid=10050 user=-1
08-20 01:22:13.621: I/ActivityManager(288): Killing proc 1146:com.example.loginfb/u0a10050: force stop com.example.loginfb
08-20 01:22:13.631: W/ActivityManager(288): Force removing ActivityRecord{4191dcd8 u0 com.example.loginfb/.MainActivity}: app died, no saved state
08-20 01:22:13.841: I/WindowState(288): WIN DEATH: Window{41951e38 u0 com.example.loginfb/com.example.loginfb.MainActivity}
08-20 01:22:14.111: I/PackageManager(288): Package com.example.loginfb codePath changed from /data/app/com.example.loginfb-2.apk to /data/app/com.example.loginfb-1.apk; Retaining data and using new
08-20 01:22:14.131: I/PackageManager(288): Running dexopt on: com.example.loginfb
08-20 01:22:16.931: D/dalvikvm(1241): DexOpt: load 475ms, verify+opt 1516ms, 1783388 bytes
08-20 01:22:17.041: I/ActivityManager(288): Force stopping package com.example.loginfb appid=10050 user=-1
08-20 01:22:17.041: W/PackageManager(288): Code path for pkg : com.example.loginfb changing from /data/app/com.example.loginfb-2.apk to /data/app/com.example.loginfb-1.apk
08-20 01:22:17.061: W/PackageManager(288): Resource path for pkg : com.example.loginfb changing from /data/app/com.example.loginfb-2.apk to /data/app/com.example.loginfb-1.apk
08-20 01:22:17.371: D/BackupManagerService(288): Now staging backup of android
08-20 01:22:17.392: I/ActivityManager(288): Force stopping package com.example.loginfb appid=10050 user=0
08-20 01:22:17.501: D/dalvikvm(417): GC_EXPLICIT freed 154K, 30% free 8464K/11948K, paused 4ms+14ms, total 92ms
08-20 01:22:17.561: D/dalvikvm(470): GC_EXPLICIT freed 191K, 14% free 2867K/3304K, paused 3ms+5ms, total 76ms
08-20 01:22:17.601: E/StrictMode(470): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
08-20 01:22:17.601: E/StrictMode(470): java.lang.Throwable: Explicit termination method 'close' not called
08-20 01:22:17.601: E/StrictMode(470): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
08-20 01:22:17.601: E/StrictMode(470): at android.os.ParcelFileDescriptor.<init>(ParcelFileDescriptor.java:405)
08-20 01:22:17.601: E/StrictMode(470): at android.os.Parcel.readFileDescriptor(Parcel.java:1502)
08-20 01:22:17.601: E/StrictMode(470): at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:434)
08-20 01:22:17.601: E/StrictMode(470): at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:431)
08-20 01:22:17.601: E/StrictMode(470): at android.app.IBackupAgent$Stub.onTransact(IBackupAgent.java:57)
08-20 01:22:17.601: E/StrictMode(470): at android.os.Binder.execTransact(Binder.java:388)
08-20 01:22:17.601: E/StrictMode(470): at dalvik.system.NativeStart.run(Native Method)
08-20 01:22:17.841: D/dalvikvm(288): GC_FOR_ALLOC freed 812K, 24% free 5848K/7656K, paused 89ms, total 96ms
08-20 01:22:17.871: I/InputReader(288): Reconfiguring input devices. changes=0x00000010
08-20 01:22:17.891: D/BackupManagerService(288): Received broadcast Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:com.example.loginfb flg=0x8000010 (has extras) }
08-20 01:22:17.931: W/ContextImpl(1052): Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1385 android.content.ContextWrapper.startService:473 android.content.ContextWrapper.startService:473 com.android.keychain.KeyChainBroadcastReceiver.onReceive:12 android.app.ActivityThread.handleReceiver:2424
08-20 01:22:18.021: E/StrictMode(470): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
08-20 01:22:18.021: E/StrictMode(470): java.lang.Throwable: Explicit termination method 'close' not called
08-20 01:22:18.021: E/StrictMode(470): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
08-20 01:22:18.021: E/StrictMode(470): at android.os.ParcelFileDescriptor.<init>(ParcelFileDescriptor.java:405)
08-20 01:22:18.021: E/StrictMode(470): at android.os.Parcel.readFileDescriptor(Parcel.java:1502)
08-20 01:22:18.021: E/StrictMode(470): at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:434)
08-20 01:22:18.021: E/StrictMode(470): at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:431)
08-20 01:22:18.021: E/StrictMode(470): at android.app.IBackupAgent$Stub.onTransact(IBackupAgent.java:64)
08-20 01:22:18.021: E/StrictMode(470): at android.os.Binder.execTransact(Binder.java:388)
08-20 01:22:18.021: E/StrictMode(470): at dalvik.system.NativeStart.run(Native Method)
08-20 01:22:18.061: E/StrictMode(470): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
08-20 01:22:18.061: E/StrictMode(470): java.lang.Throwable: Explicit termination method 'close' not called
08-20 01:22:18.061: E/StrictMode(470): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
08-20 01:22:18.061: E/StrictMode(470): at android.os.ParcelFileDescriptor.<init>(ParcelFileDescriptor.java:405)
08-20 01:22:18.061: E/StrictMode(470): at android.os.Parcel.readFileDescriptor(Parcel.java:1502)
08-20 01:22:18.061: E/StrictMode(470): at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:434)
08-20 01:22:18.061: E/StrictMode(470): at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:431)
08-20 01:22:18.061: E/StrictMode(470): at android.app.IBackupAgent$Stub.onTransact(IBackupAgent.java:71)
08-20 01:22:18.061: E/StrictMode(470): at android.os.Binder.execTransact(Binder.java:388)
08-20 01:22:18.061: E/StrictMode(470): at dalvik.system.NativeStart.run(Native Method)
08-20 01:22:18.131: I/InputReader(288): Reconfiguring input devices. changes=0x00000010
08-20 01:22:18.171: D/BackupManagerService(288): Received broadcast Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.example.loginfb flg=0x8000010 (has extras) }
08-20 01:22:18.171: V/BackupManagerService(288): removePackageParticipantsLocked: uid=10050 #1
08-20 01:22:18.191: V/BackupManagerService(288): addPackageParticipantsLocked: #1
08-20 01:22:18.741: I/Choreographer(417): Skipped 138 frames! The application may be doing too much work on its main thread.
08-20 01:22:19.841: D/dalvikvm(417): GC_FOR_ALLOC freed 4102K, 47% free 6352K/11948K, paused 58ms, total 77ms
08-20 01:22:20.061: I/Choreographer(417): Skipped 286 frames! The application may be doing too much work on its main thread.
08-20 01:22:20.341: D/dalvikvm(417): GC_FOR_ALLOC freed 834K, 53% free 5670K/11948K, paused 57ms, total 75ms
08-20 01:22:20.351: I/dalvikvm-heap(417): Grow heap (frag case) to 6.918MB for 1386256-byte allocation
08-20 01:22:20.401: D/dalvikvm(417): GC_FOR_ALLOC freed 367K, 45% free 6657K/11948K, paused 43ms, total 43ms
08-20 01:22:20.481: I/Choreographer(417): Skipped 54 frames! The application may be doing too much work on its main thread.
08-20 01:22:21.121: D/dalvikvm(417): GC_FOR_ALLOC freed 154K, 35% free 7787K/11948K, paused 44ms, total 44ms
08-20 01:22:21.531: D/dalvikvm(288): GC_EXPLICIT freed 925K, 32% free 5220K/7656K, paused 4ms+41ms, total 2737ms
08-20 01:22:21.571: D/AndroidRuntime(1230): Shutting down VM
08-20 01:22:21.571: D/jdwp(1230): Got wake-up signal, bailing out of select
08-20 01:22:21.571: D/dalvikvm(1230): Debugger has detached; object registry had 1 entries
08-20 01:22:21.681: W/RecognitionManagerService(288): no available voice recognition services found for user 0
08-20 01:22:22.361: D/AndroidRuntime(1250): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
08-20 01:22:22.361: D/AndroidRuntime(1250): CheckJNI is ON
08-20 01:22:22.411: D/dalvikvm(1250): Trying to load lib libjavacore.so 0x0
08-20 01:22:22.421: D/dalvikvm(1250): Added shared lib libjavacore.so 0x0
08-20 01:22:22.471: D/dalvikvm(1250): Trying to load lib libnativehelper.so 0x0
08-20 01:22:22.471: D/dalvikvm(1250): Added shared lib libnativehelper.so 0x0
08-20 01:22:22.611: E/cutils-trace(1250): Error opening trace file: No such file or directory (2)
08-20 01:22:23.182: D/AndroidRuntime(1250): Calling main entry com.android.commands.am.Am
08-20 01:22:23.191: D/dalvikvm(1250): Note: class Landroid/app/ActivityManagerNative; has 163 unimplemented (abstract) methods
08-20 01:22:23.222: I/ActivityManager(288): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.loginfb/.MainActivity} from pid 1250
08-20 01:22:23.301: W/WindowManager(288): Screenshot failure taking screenshot for (164x273) to layer 21005
08-20 01:22:23.351: D/AndroidRuntime(1250): Shutting down VM
08-20 01:22:23.351: D/jdwp(1250): Got wake-up signal, bailing out of select
08-20 01:22:23.351: D/dalvikvm(1250): Debugger has detached; object registry had 1 entries
08-20 01:22:23.381: W/dalvikvm(1261): PR_CAPBSET_DROP 0 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.381: W/dalvikvm(1261): PR_CAPBSET_DROP 1 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.391: W/dalvikvm(1261): PR_CAPBSET_DROP 2 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.391: W/dalvikvm(1261): PR_CAPBSET_DROP 3 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.391: W/dalvikvm(1261): PR_CAPBSET_DROP 4 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.401: W/dalvikvm(1261): PR_CAPBSET_DROP 5 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.401: W/dalvikvm(1261): PR_CAPBSET_DROP 6 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.411: W/dalvikvm(1261): PR_CAPBSET_DROP 7 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.411: W/dalvikvm(1261): PR_CAPBSET_DROP 8 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.431: W/dalvikvm(1261): PR_CAPBSET_DROP 9 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.431: W/dalvikvm(1261): PR_CAPBSET_DROP 10 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.431: W/dalvikvm(1261): PR_CAPBSET_DROP 11 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.431: W/dalvikvm(1261): PR_CAPBSET_DROP 12 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.431: W/dalvikvm(1261): PR_CAPBSET_DROP 13 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.431: W/dalvikvm(1261): PR_CAPBSET_DROP 14 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.431: W/dalvikvm(1261): PR_CAPBSET_DROP 15 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.431: W/dalvikvm(1261): PR_CAPBSET_DROP 16 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.431: W/dalvikvm(1261): PR_CAPBSET_DROP 17 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.431: W/dalvikvm(1261): PR_CAPBSET_DROP 18 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.441: W/dalvikvm(1261): PR_CAPBSET_DROP 19 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.441: W/dalvikvm(1261): PR_CAPBSET_DROP 20 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.441: W/dalvikvm(1261): PR_CAPBSET_DROP 21 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.441: W/dalvikvm(1261): PR_CAPBSET_DROP 22 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.441: W/dalvikvm(1261): PR_CAPBSET_DROP 23 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.441: W/dalvikvm(1261): PR_CAPBSET_DROP 24 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.441: W/dalvikvm(1261): PR_CAPBSET_DROP 25 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.441: W/dalvikvm(1261): PR_CAPBSET_DROP 26 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.451: W/dalvikvm(1261): PR_CAPBSET_DROP 27 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.451: W/dalvikvm(1261): PR_CAPBSET_DROP 28 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.451: W/dalvikvm(1261): PR_CAPBSET_DROP 29 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.461: W/dalvikvm(1261): PR_CAPBSET_DROP 30 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.461: W/dalvikvm(1261): PR_CAPBSET_DROP 31 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.461: W/dalvikvm(1261): PR_CAPBSET_DROP 32 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.461: W/dalvikvm(1261): PR_CAPBSET_DROP 33 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
08-20 01:22:23.461: D/dalvikvm(1261): Not late-enabling CheckJNI (already on)
08-20 01:22:23.481: I/ActivityManager(288): Start proc com.example.loginfb for activity com.example.loginfb/.MainActivity: pid=1261 uid=10050 gids={50050, 3003, 1028}
08-20 01:22:23.481: I/Choreographer(417): Skipped 43 frames! The application may be doing too much work on its main thread.
08-20 01:22:25.501: I/Choreographer(417): Skipped 55 frames! The application may be doing too much work on its main thread.
08-20 01:22:26.192: I/MainActivity(1261): Logged in...
08-20 01:22:26.192: I/MainActivity(1261): Access TokenCAAHDQUrqKcEBABT1j4aJsklzsbExlt4ImTqja2SpD54HMGTtRCZA29tTG9jbYMcl8as3DTfbVMXX6UP23usqA9yU7zBKeGC8EPBM1eSZAEgdZA0DyHyZAE5hpW87qFNC0TypV7EKFkQZCeAAjcqnK9ryL95fEIifx5bMskSDwy01jvuu4EoGZAZAEJYYu5DZC0b7wX9BtzU2B9nMYVHyT8bi
08-20 01:22:26.292: D/gralloc_goldfish(1261): Emulator without GPU emulation detected.
08-20 01:22:26.372: I/ActivityManager(288): Displayed com.example.loginfb/.MainActivity: +3s30ms
08-20 01:22:26.581: D/Request(1261): Warning: Sessionless Request needs token but missing either application ID or client token.
08-20 01:22:27.511: D/dalvikvm(1261): GC_FOR_ALLOC freed 244K, 10% free 2775K/3080K, paused 40ms, total 40ms
08-20 01:22:29.851: D/dalvikvm(1261): GC_FOR_ALLOC freed 421K, 15% free 2866K/3348K, paused 31ms, total 32ms
08-20 01:22:30.471: D/skia(1261): --- SkImageDecoder::Factory returned null
这是我的代码,i am using to get user profile picture
,见下文:
authButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
@Override
public void onUserInfoFetched(GraphUser user) {
try {
if (user != null) {
final String strId = user.getId();
AsyncTask<Void, Void, Bitmap> t = new AsyncTask<Void, Void, Bitmap>(){
protected Bitmap doInBackground(Void... p) {
try {
URL img_value = null;
img_value = new URL("http://graph.facebook.com/"+strId+"/picture");
HttpURLConnection connection = (HttpURLConnection) img_value.openConnection(); HttpURLConnection.setFollowRedirects(HttpURLConnection.getFollowRedirects());
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
bitmap= BitmapFactory.decodeStream(input);
} catch (IOException e) {
Log.d("TAG", "Loading Picture FAILED");
e.printStackTrace();
}
return bitmap;
}
protected void onPostExecute(Bitmap bm){
imageView.setImageBitmap(bitmap);
}
};
t.execute();
我测试了我的URL in web
和getting my profile pic
,但不知道为什么会发生这种情况,同时尝试以编程方式在ImageView中显示和显示图像!
答案 0 :(得分:0)
最后,我发现easy and smart way
获得了User's profile picture
,我使用了Facebook SDK中提供的ProfilePictureView
功能
AsycTask
我的代码to get image from URL
,no usage
HttpConnection
,Bitmap
以及其他代码中不再需要...
答案 1 :(得分:-2)
使用Aquery Library,
aQuery.id(R.id.image1).image(your image url);