Android 为每个登录清除用户的登录详细信息

Android 为每个登录清除用户的登录详细信息,android,authentication,Android,Authentication,我正在构建一个应用程序,我想为用户清除Facebook的用户登录详细信息。因为一旦它保存了详细信息,它每次都会使用相同的详细信息,但我想知道的是,它应该在用户每次打开应用程序时要求用户登录?在定义Webview的同时编写以下语句 myWebView.clearCache(true); myContext.deleteDatabase("webview.db"); myContext.deleteDatabase("webviewCache.db"); 你好,阿米特 当你登录facebook时,

我正在构建一个应用程序,我想为用户清除Facebook的用户登录详细信息。因为一旦它保存了详细信息,它每次都会使用相同的详细信息,但我想知道的是,它应该在用户每次打开应用程序时要求用户登录?

在定义Webview的同时编写以下语句

myWebView.clearCache(true);
myContext.deleteDatabase("webview.db");
myContext.deleteDatabase("webviewCache.db");
你好,阿米特

当你登录facebook时,facebook会给你“SessionId”和 facebook每次都会使用此会话

 /**
 * Authorize method that grants custom permissions.
 *
 * See authorize() below for @params.
 */
public void authorize(Activity activity, String[] permissions,
        final DialogListener listener) {
    authorize(activity, permissions, DEFAULT_AUTH_ACTIVITY_CODE, listener);
}
如果您想每次登录,那么您可以在 活动的后退按钮


如果您没有使用任何jar和库类,那么下面是代码片段供您理解

来自Facebook.java

用于调用“登录活动”对话框的静态变量

 public static final int FORCE_DIALOG_AUTH = -1;

 private static final String LOGIN = "oauth";

 // Used as default activityCode by authorize(). See authorize() below.
 private static final int DEFAULT_AUTH_ACTIVITY_CODE = 32665;
下面是此类的授权方法,用于授权用户,如果您使用强制对话框\u AUTH您的应用程序每次都会提示您登录,而不是使用默认的\u AUTH\u活动\u代码

 /**
 * Authorize method that grants custom permissions.
 *
 * See authorize() below for @params.
 */
public void authorize(Activity activity, String[] permissions,
        final DialogListener listener) {
    authorize(activity, permissions, DEFAULT_AUTH_ACTIVITY_CODE, listener);
}
这个Facebook.java类中的另一个authorize方法如下所示,该方法导致您进行单点登录(SSO)。有关更多信息,您可以查看我在回答中包含的此方法的注释

/**
 * Full authorize method.
 *
 * Starts either an Activity or a dialog which prompts the user to log in to
 * Facebook and grant the requested permissions to the given application.
 *
 * This method will, when possible, use Facebook's single sign-on for
 * Android to obtain an access token. This involves proxying a call through
 * the Facebook for Android stand-alone application, which will handle the
 * authentication flow, and return an OAuth access token for making API
 * calls.
 *
 * Because this process will not be available for all users, if single
 * sign-on is not possible, this method will automatically fall back to the
 * OAuth 2.0 User-Agent flow. In this flow, the user credentials are handled
 * by Facebook in an embedded WebView, not by the client application. As
 * such, the dialog makes a network request and renders HTML content rather
 * than a native UI. The access token is retrieved from a redirect to a
 * special URL that the WebView handles.
 *
 * Note that User credentials could be handled natively using the OAuth 2.0
 * Username and Password Flow, but this is not supported by this SDK.
 *
 * See http://developers.facebook.com/docs/authentication/ and
 * http://wiki.oauth.net/OAuth-2 for more details.
 *
 * Note that this method is asynchronous and the callback will be invoked in
 * the original calling thread (not in a background thread).
 *
 * Also note that requests may be made to the API without calling authorize
 * first, in which case only public information is returned.
 *
 * IMPORTANT: Note that single sign-on authentication will not function
 * correctly if you do not include a call to the authorizeCallback() method
 * in your onActivityResult() function! Please see below for more
 * information. single sign-on may be disabled by passing FORCE_DIALOG_AUTH
 * as the activityCode parameter in your call to authorize().
 *
 * @param activity
 *            The Android activity in which we want to display the
 *            authorization dialog.
 * @param applicationId
 *            The Facebook application identifier e.g. "350685531728"
 * @param permissions
 *            A list of permissions required for this application: e.g.
 *            "read_stream", "publish_stream", "offline_access", etc. see
 *            http://developers.facebook.com/docs/authentication/permissions
 *            This parameter should not be null -- if you do not require any
 *            permissions, then pass in an empty String array.
 * @param activityCode
 *            Single sign-on requires an activity result to be called back
 *            to the client application -- if you are waiting on other
 *            activities to return data, pass a custom activity code here to
 *            avoid collisions. If you would like to force the use of legacy
 *            dialog-based authorization, pass FORCE_DIALOG_AUTH for this
 *            parameter. Otherwise just omit this parameter and Facebook
 *            will use a suitable default. See
 *            http://developer.android.com/reference/android/
 *              app/Activity.html for more information.
 * @param listener
 *            Callback interface for notifying the calling application when
 *            the authentication dialog has completed, failed, or been
 *            canceled.
 */
public void authorize(Activity activity, String[] permissions,
        int activityCode, final DialogListener listener) {

    boolean singleSignOnStarted = false;

    mAuthDialogListener = listener;

    // Prefer single sign-on, where available.
    if (activityCode >= 0) {
        singleSignOnStarted = startSingleSignOn(activity, mAppId,
                permissions, activityCode);
    }
    // Otherwise fall back to traditional dialog.
    if (!singleSignOnStarted) {
        startDialogAuth(activity, permissions);
    }
}
编辑:


我说的是内联facebook库,如上图所示。您必须从默认\u AUTH\u ACTIVITY\u CODE更改为强制对话框\u AUTH,以使您的应用程序在每次请求facebook时都请求凭据。

您是使用facebook SDK还是仅在webview中打开URL?我使用facebook SDK。。当您使用facebook SDkLogout代码时,此答案适用于此处,一旦它获得用户的登录详细信息,它就会存储这些信息,直到卸载应用程序…Dinesh,你能详细说明一下吗?你的项目中有facebook.java类吗?是的,我有..但是在按照你说的对其进行更改之后,我也面临着同样的问题…当你面临一些问题时,通过编辑你的问题来发布你的日志。如果我这样做,那么它会给我“不幸的是,应用程序已停止”错误。