从使用Facebook的服务Android SDK中 [英] Using facebook android sdk from service

查看:108
本文介绍了从使用Facebook的服务Android SDK中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有一个发送服务器和(需要)张贴在Facebook上的一些内容的功能。它使用服务来发送(用于存储数据,我使用SQLite)。是否有可能从服务处理的Facebook会话e.t.c?我需要它,因为当内容将被存储在DB和发送时间可以是不同的时间(可能是连接将丢失在很长的时间和连接后开始发送将是可利用的,但仅发送我的申请的服务将在此被激活时间)。我找不到这种情况下,任何解决方案(和很好的解决方案将是伟大的)。请帮助。

My application has functionality that send some content on server and (need) post it on facebook. It uses service for sending (for store data I'm use sqlite). Is it possible to handle facebook sessions e.t.c from service? I need it because time when content will be stored in DB and sending time can be different (may be connection will be lost on very long time and sending starts after connection will be available, but only sending service of my application will be active in this time). I can't find any solution for this case(and good solution will be great). Please help.

推荐答案

用户必须明确授予权限的应用程序,而Android服务不支持Activity.startActivityForResult(),所以它是不可能打开一个Session或添加新通过重新授权权限从服务。

Users must explicitly grant permissions to the application, and Android services do not support Activity.startActivityForResult(), so it is not possible to open a Session or add new permissions via reauthorize from a service.

然而,如果你打开​​/在你的应用程序的活动之一重新授权会话,会话的状态默认保存到共享preferences。如果一个服务创建一个会话这种情况后,会在SessionState.CREATED_TOKEN_LOADED结束。如果Session.getState()被CREATED_TOKEN_LOADED,会话是保证能够openForRead()不带UI,并且是合法的传递一个空的活动。该会议将已保存您的活动授予的所有权限。

However, if you open/reauthorize a Session in one of the Activities of your app, the state of the Session is saved to SharedPreferences by default. If a Service creates a Session after this happens, it will end up in SessionState.CREATED_TOKEN_LOADED. If the Session.getState() is CREATED_TOKEN_LOADED, the Session is guaranteed to be able to openForRead() with no UI, and it is legal to pass a null Activity. The Session will have all the permissions granted that were saved by your Activity.

要简化这一切,你的服务可以叫:

To simplify all this, your service can just call:

Session session = Session.openActiveSession(this);

此调用返回null,如果没有有效的标记是共享preferences。

This call returns null if no valid token was in SharedPreferences.

如果您的应用程序的用户界面有一个设置区域,一个简单的方法来获取存储在首位令牌是包含一个LoginFragment的设置面板之一。这将让您的用户登录/注销,并应保存会话状态,这样你的服务能够把它捡起来如果是在相同的应用程序。

If your app UI has a settings area, an easy way to get the token stored in the first place is to include a LoginFragment as one of the settings panels. This will let your users log in/log out, and should save the Session state such that your service can pick it up if it is in the same app.

这篇关于从使用Facebook的服务Android SDK中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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