Android 没有UI的片段
我正在开发一个android应用程序,我想在其中添加Facebook登录 我使用的是一个片段,在这里我想获得个人资料图片,登录用户的名称和位置,并显示在我的侧菜单中。 我使用了一个片段,但它显示了一个用户界面。 所以我的问题是,我不想为片段设置UI。我只想在没有UI的情况下获取数据。我可以在侧菜单中设置数据 有人能告诉我如何使用没有UI的片段吗Android 没有UI的片段,android,facebook,facebook-graph-api,android-fragments,Android,Facebook,Facebook Graph Api,Android Fragments,我正在开发一个android应用程序,我想在其中添加Facebook登录 我使用的是一个片段,在这里我想获得个人资料图片,登录用户的名称和位置,并显示在我的侧菜单中。 我使用了一个片段,但它显示了一个用户界面。 所以我的问题是,我不想为片段设置UI。我只想在没有UI的情况下获取数据。我可以在侧菜单中设置数据 有人能告诉我如何使用没有UI的片段吗 一个片段表示活动中的一个行为或用户界面的一部分。请检查这个我已经读过了。但是我无法理解给出的示例类:试试这个。。。 private void login
一个片段表示活动中的一个行为或用户界面的一部分。请检查这个我已经读过了。但是我无法理解给出的示例类:试试这个。。。
private void login()
{
status = true;
// start Facebook Login
Session.openActiveSession(fa, this, true, new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
if (session.isOpened()) {
Toast.makeText(getActivity(), "Access token :" + session.getAccessToken() + "\n" +"Expires at "+session.getExpirationDate().toLocaleString(), Toast.LENGTH_LONG).show();
Log.i("sessionToken", session.getAccessToken());
Log.i("sessionTokenDueDate", session.getExpirationDate().toLocaleString());
access_token =session.getAccessToken();
Editor prefsEditor = pref.edit();
edt.putString("Access token", access_token);
edt.commit();
/**
* getting user's name and location
*/
// make request to the /me API
Request.newMeRequest(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null)
{
welcome = (TextView) ll.findViewById(R.id.name);
welcome.setText("Hello " + user.getName() + "!");
dispname = user.getName();
id = user.getId();
location = (TextView) ll.findViewById(R.id.location);
Object userLocation = user.getLocation();
Log.i("Profile information", ""+response);
// strLocation = "location not avail";
String strLocation = (userLocation != null)? ((GraphObject) userLocation).getProperty("name").toString() : "Address not mentioned";
location.setText("Lives in " + strLocation + "!");
disploc = strLocation;
((MainActivity)getActivity()).dispatchInformations(dispname,disploc);
}
}
}).executeAsync();
/**
* Getting user's profile picture
*/
Bundle params = new Bundle();
params.putBoolean("redirect", false);
params.putString("type", "normal");
params.putString("height", "200");
params.putString("width", "200");
new Request(
Session.getActiveSession(),
"/me/picture",
params,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
Log.i("Profile pic", ""+response);
GraphObject graph=response.getGraphObject();
JSONObject jsonObj=graph.getInnerJSONObject();
JSONObject object;
String imageURL;
img = (ImageView)ll.findViewById(R.id.picture_pic);
try {
object = jsonObj.getJSONObject("data");
imageURL=object.getString("url");
new DownloadImageTask(img).execute(imageURL);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
).executeAsync();
}
}