예제 #1
0
  private void updateView() {
    Session session = Session.getActiveSession();
    if (session.isOpened()) {
      // Check for publish permissions
      List<String> permissions = session.getPermissions();
      if (!isSubsetOf(PERMISSIONS, permissions)) {
        Session.NewPermissionsRequest newPermissionsRequest =
            new Session.NewPermissionsRequest(this, PERMISSIONS);
        session.requestNewPublishPermissions(newPermissionsRequest);
      }

      makeMeRequest(session);

      // bLoginFacebook.setText(R.string.Log_Out);
      bLoginFacebook.setOnClickListener(
          new OnClickListener() {
            public void onClick(View view) {
              onClickLogout();
            }
          });
    } else {
      // bLoginFacebook.setText(R.string.Log_In);
      bLoginFacebook.setOnClickListener(
          new OnClickListener() {
            public void onClick(View view) {
              onClickLogin();
            }
          });
    }
  }
예제 #2
0
 public static void requestPublishPermissions(Activity activity, Session session) {
   if (session != null) {
     Session.NewPermissionsRequest newPermissionRequest =
         new Session.NewPermissionsRequest(activity, PERMISSIONS)
             .setRequestCode(REAUTH_ACTIVITY_CODE);
     session.requestNewPublishPermissions(newPermissionRequest);
   }
 }
예제 #3
0
 public boolean checkPermissions() {
   Session session = Session.getActiveSession();
   List<String> permissions = session.getPermissions();
   if (!isSubsetOf(FacebookHelper.PERMISSIONS, permissions)) {
     Session.NewPermissionsRequest newPermissionsRequest =
         new Session.NewPermissionsRequest(activity, FacebookHelper.PERMISSIONS);
     session.requestNewPublishPermissions(newPermissionsRequest);
     return false;
   }
   return true;
 }
예제 #4
0
 private void performPublish(PendingAction action) {
   Session session = Session.getActiveSession();
   if (session != null) {
     pendingAction = action;
     if (hasPublishPermission()) {
       // We can do the action right away.
       handlePendingAction();
     } else {
       // We need to get new permissions, then complete the action when we get called back.
       session.requestNewPublishPermissions(new Session.NewPermissionsRequest(this, PERMISSIONS));
     }
   }
 }
 private void onSessionStateChange(Session session, SessionState state, Exception exception) {
   if (state.isOpened()) {
     Log.i(TAG, "Logged in...");
     // Check for publish permissions
     List<String> permissions = session.getPermissions();
     if (!isSubsetOf(PERMISSIONS, permissions)) {
       Session.NewPermissionsRequest newPermissionsRequest =
           new Session.NewPermissionsRequest(this, PERMISSIONS);
       session.requestNewPublishPermissions(newPermissionsRequest);
       return;
     }
   } else if (state.isClosed()) {
     Log.i(TAG, "Logged out...");
   }
 }
 private void performPublishPermissionRequest() {
   Session session = Session.getActiveSession();
   if (session != null) {
     if (!hasPublishPermission()) {
       try {
         session.requestNewPublishPermissions(
             new Session.NewPermissionsRequest(this, PERMISSIONS));
       } catch (Exception e) {
         e.printStackTrace();
         setResultAndClose(false);
       }
     } else {
       setResultAndClose(true);
     }
   }
 }
 static void sessionOpenRequest(
     Session session,
     Session.StatusCallback callback,
     Activity activity,
     List<String> permissions,
     boolean publish) {
   if (session.isOpened()) {
     Session.NewPermissionsRequest req =
         getNewPermissionsRequest(session, callback, permissions, activity);
     if (publish) {
       session.requestNewPublishPermissions(req);
     } else {
       session.requestNewReadPermissions(req);
     }
   } else {
     OpenRequest req = getOpenRequest(callback, permissions, activity);
     if (publish) {
       session.openForPublish(req);
     } else {
       session.openForRead(req);
     }
   }
 }
예제 #8
0
  @Override
  protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    CheckBluetoothConenct = false;
    Threadrun = true;
    if (haveInternet()) {
      Session s = Session.getActiveSession();
      if (s.isOpened()) {
        try {
          if (s != null) {

            // Check for publish permissions
            List<String> permissions = s.getPermissions();

            if (!isSubsetOf(PERMISSIONS, permissions)) {
              pendingPublishReauthorization = true;
              Session.NewPermissionsRequest newPermissionsRequest =
                  new Session.NewPermissionsRequest(this, PERMISSIONS);
              s.requestNewPublishPermissions(newPermissionsRequest);
              return;
            }
          }
          Initial();
          if (getGPSService) {
            // 服務提供者、更新頻率毫秒、最短距離、地點改變時呼叫物件
            lms.requestLocationUpdates(bestProvider, 60000, 1, (LocationListener) this);
          }
        } catch (Exception e) {
          System.out.println(e.toString());
        }
      }
    } else {
      NoInternetDialog();
    }
  }
  public static void login(int cbIndex, String scope) {
    Log.i(TAG, "dsafsdfas");
    Session session = Session.getActiveSession();
    if (session == null) {
      session = new Session(mContext);
      Session.setActiveSession(session);
    }

    String[] permissions = null;
    mNeedPublishPermissions = false;
    if (scope != null) {
      permissions = scope.split(",");
      for (int i = 0; i < permissions.length; i++) {
        if (allPublishPermissions.contains(permissions[i])) {
          mNeedPublishPermissions = true;
          break;
        }
      }
    }

    if (session.isOpened()) {
      Log.i(TAG, "openActiveSession2");
      if (scope == null || session.getPermissions().containsAll(Arrays.asList(permissions))) {
        Log.e(TAG, "FB.login() called when user is already connected.");
      } else {
        mStatusCallback.mCallByMode = SessionStatusCallback.CallByLogin;
        mStatusCallback.mCallbackIndex = cbIndex;
        if (mNeedPublishPermissions) {
          session.requestNewPublishPermissions(
              new Session.NewPermissionsRequest(mActivity, Arrays.asList(permissions)));
        } else {
          session.requestNewReadPermissions(
              new Session.NewPermissionsRequest(mActivity, Arrays.asList(permissions)));
        }
      }
    } else {
      mStatusCallback.mCallByMode = SessionStatusCallback.CallByLogin;
      mStatusCallback.mCallbackIndex = cbIndex;
      Log.i(TAG, "openActiveSession1");
      if (!session.isClosed()) {
        mOpenRequest = new Session.OpenRequest(mActivity);
        if (permissions != null) mOpenRequest.setPermissions(Arrays.asList(permissions));
        mOpenRequest.setCallback(mStatusCallback);

        if (mNeedPublishPermissions) {
          Log.i(TAG, "openActiveSession4");
          session.openForPublish(mOpenRequest);
        } else {
          Log.i(TAG, "openActiveSession5");
          session.openForRead(mOpenRequest);
        }

      } else {
        Log.i(TAG, "openActiveSession");
        Session.openActiveSession(mActivity, true, mStatusCallback);
      }
    }

    /*
     * Session session = Session.getActiveSession(); if (!session.isOpened()
     * && !session.isClosed()) { session.openForRead(new
     * Session.OpenRequest(mActivity)
     * .setPermissions(Arrays.asList("basic_info")).setCallback(
     * mStatusCallback)); } else { Session.openActiveSession(mActivity,
     * true, mStatusCallback); }
     */
  }
예제 #10
0
 public void requestPermissions() {
   Session s = Session.getActiveSession();
   if (s != null)
     s.requestNewPublishPermissions(new Session.NewPermissionsRequest(this, PERMISSIONS));
 }