我無法獲取Facebook個人資料圖片,以便將其顯示在我的片段中。名稱,生日和鏈接已成功獲取,但是當我試圖獲取個人資料圖片時,應用程序停止工作。如何擺脫這種情況?無法獲取Facebook個人資料圖片,插入ImageView
private FacebookCallback<LoginResult> callback=new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken=loginResult.getAccessToken();
Profile profile=Profile.getCurrentProfile();
//DisplayMessage(profile);
GraphRequest request=GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
try{
tv1=(TextView)getView().findViewById(R.id.name);
tv1.setText("Name : " + object.getString("name"));
tv2=(TextView)getView().findViewById(R.id.birthday);
tv2.setText("BirthDay : " + object.getString("birthday"));
tv3=(TextView)getView().findViewById(R.id.id);
tv3.setText("link : " + object.getString("link"));
String id=object.getString("id");
Bitmap mBitmap = getFacebookProfilePicture(id);
img.setImageBitmap(mBitmap);
/*Toast.makeText(getActivity().getApplicationContext(), object.getString("name") + object.getString("birthday") +object.getString("link")
, Toast.LENGTH_SHORT).show();*/
}catch (JSONException e){
e.printStackTrace();
}
}
});
Bundle parameters= new Bundle();
parameters.putString("fields","name,birthday,link");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
}
};
public Bitmap getFacebookProfilePicture(String userID) {
Bitmap bitmap = null;
try {
URL imageURL = new URL("https://graph.facebook.com/" + userID
+ "/picture?type=large");
bitmap = BitmapFactory.decodeStream(imageURL.openConnection()
.getInputStream());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bitmap;
}
如何將圖像加載程序庫下載到圖像視圖中。我是一名初學者。你能否詳細說明一下。謝謝。 –