Call facebook autorize dialog - not shown - android

I'm trying to call FB autorize dialog with this code:
//return true if is autologged
//return false if facebook login dialog is called
public boolean LoginAsync(Activity act)
{
m_strLastError="";
boolean bTryLogin= true;
if ((m_fbkey != null) && (m_fbkey.length() > 0))
{
facebook.setAccessToken(m_fbkey);
bTryLogin = !facebook.isSessionValid();
}
if (bTryLogin)
{
facebook.authorize(act, new String[] { "email", "offline_access", "publish_stream", "read_stream"}, new LoginDialogListener());
return false;
}
//"succesfull 'autologin'
return true;
}
It worked fine in test app when click button, but stopped working when moved it to OnCreate.
Dialog doesn't appear anymore. Only empty screen.
Is it possible to fajl because of use in OnCreate?

If you call login and have a valid token then you will skip the login form and go straight to the onComplete callback.
http://facebook.stackoverflow.com/questions/9130133/authorize-method-called-twice-for-facebook-on-android
Thanks to mcnicholls.

Related

Android application does not relaunch when navigating to the home screen

We have a launcher application that works fine on older versions of Android. We have a device that is running Android 5.1, and are running into issues.
When pressing the back button from within the application, we allow the user to go to the settings page. Pressing the home key re-launches the application. Pressing the back button on other devices also relaunches the application.
On the new device, pressing the back button allows us to navigate to the Android home page. It does not launch the application.
We are overriding the back button like so:
#override
public void onBackPressed() {
// Display the password prompt if required
if (PreferencesManager.isPasswordPresent()) {
LeaveApplicationPasswordDialogFragment dialog = LeaveApplicationPasswordDialogFragment.getInstance();
dialog.show(getSupportFragmentManager(), "password");
}
else {
// Prompt whether we are about to leave the app
LeaveApplicationDialogFragment dialog = null;
MyApplication application = (MyApplication )
getApplication();
if (application.isDefaultLauncher()) {
dialog = LeaveApplicationDialogFragment.getInstance("Are you sure you want to leave ** to access the device's settings?");
}
else {
dialog = LeaveApplicationDialogFragment.getInstance("Are you sure you want to leave ***");
}
dialog.show(getFragmentManager(), "leaving");
}
}
In the dialog fragment, we accept the confirmation and process it like so:
public void exitToSettings() {
GUIAndroidTouchBaseActivity.this.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
shutdownOperations();
finish();
}
Per some research and other threads, I worked with our exit method like so:
public void exitToSettings() {
Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
GUIAndroidTouchBaseActivity.this.startActivity(intent);
shutdownOperations();
finish();
}
No dice. Same behavior.
What am I missing? Is there something in OS 5.1 that's overriding our launcher? Again, pressing the home button launches the app as expected. Navigating to the home page from the settings page by pressing the back button does not.
What we have works on other devices and OSs. We've had no issue with 4.1 and 6.1.
We are also overriding the back button like so:
#Override
public boolean onKeyDown(int keyCode, KeyEvent KEvent) {
int deviceid = KEvent.getDeviceId();
//Making sure not processing same key again
if (KEvent.getRepeatCount() != 0) {
return true;
}
if (!SettingsOpened) {
int keyaction = KEvent.getAction();
// "Esc" key can not be stooped id diveceid is non zero because it can be back key of android
if (KEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && deviceid != 0) {
return super.onKeyDown(keyCode, KEvent);
}
if (keyaction == KeyEvent.ACTION_DOWN) {
String key = KeyEvent.keyCodeToString(keyCode); //wont work in version 11 or less
if (keyCode != KeyEvent.KEYCODE_ENVELOPE) {
Matcher matcher = KEYCODE_PATTERN.matcher(key);
if (matcher.matches() || ExternalKeyboard.keyMatches(KEvent)) {
int keyunicode = KEvent.getUnicodeChar(KEvent.getMetaState());
char character = (char) keyunicode;
//toast.makeText(this, "onKeyDown" + _lastChar + repeatcount, toast.LENGTH_SHORT).show();
_lastChar = character;
_actionDown = true;
ExternalKeyboard.KeyboardAddChar(character);
}
}
}
return true;
}
else {
return super.onKeyDown(keyCode, KEvent);
}
}
Thanks!
Adding
android:stateNotNeeded="true"
android:clearTaskOnLaunch="false"
to my manifest took care of it.

Login, but then, error

I'm developing an app using Flash CC. I'm using the Google Play Services to login the people in the App, but I have a problem.
When I install the App, I have to login. When I'm logged in, I don't have problems. If I close the app and then I open again the game, says that I'm not logged in. So, I click login, I log in but then I recive the SIGN_IN_FAILS error. In the code, first I check if the user is logged in and if is not logged in, I show the Log In button. But what happens with the people who has connected before? I have an "else" telling that if he is already logged in, he can 'Continue'. But always says that I'm not logged and I have to log in! But if I log in another time I get the error!
PS. I'm using freshplanet/laurentiu ANE/library.
** EDIT **
CODE:
import com.freshplanet.ane.AirGooglePlayGames.AirGooglePlayGames;
import com.freshplanet.ane.AirGooglePlayGames.AirGooglePlayGamesEvent;
import com.laurentiu.ane.AirGooglePlayServices.AirGooglePlayServices;
var airGooglePlayGames: AirGooglePlayGames = AirGooglePlayGames.getInstance();
airGooglePlayGames.addEventListener(AirGooglePlayGamesEvent.ON_SIGN_IN_SUCCESS, onSignInSuccess);
airGooglePlayGames.addEventListener(AirGooglePlayGamesEvent.ON_SIGN_OUT_SUCCESS, onSignOutSuccess);
airGooglePlayGames.addEventListener(AirGooglePlayGamesEvent.ON_SIGN_IN_FAIL, onSignInFail);
this.checkeStatus();
button_login.addEventListener(MouseEvent.CLICK, googleSignIn);
btn_out.addEventListener(MouseEvent.CLICK, googleSignOut);
btn_out.visible = false;
button_login.visible = false;
function googleSignIn(e: MouseEvent = null): void {
AirGooglePlayGames.getInstance().signIn();
}
function checkeStatus() {
if (!AirGooglePlayGames.getInstance().isSignedIn()) {
// Always stay here when I reopen the app
btn_out.visible = false;
button_login.visible = true;
} else {
// I never arrive here
texto.text = "PLAYERID: " + AirGooglePlayGames.getInstance().getActivePlayerID();
loadingBar.gotoAndStop(2);
button_login.visible = false;
btn_out.visible = true;
}
}
function onSignInSuccess(e: AirGooglePlayGamesEvent): void {
// I only arrive here if is the first time I open the app and login for first time
texto.text = "PLAYERID: " + AirGooglePlayGames.getInstance().getActivePlayerID();
loadingBar.gotoAndStop(2);
button_login.visible = false;
btn_out.visible = true;
}
function onSignOutSuccess(e: AirGooglePlayGamesEvent): void {
texto.text = "SIGN OUT OKAY!";
loadingBar.gotoAndStop(1);
button_login.visible = true;
btn_out.visible = false;
}
function onSignInFail(e: AirGooglePlayGamesEvent): void {
texto.text = "SING IN FAIL: " + e;
loadingBar.gotoAndStop(1);
button_login.visible = true;
btn_out.visible = false;
}
function googleSignOut(e: AirGooglePlayGamesEvent): void {
texto.text = "SIGN OUT PROGRESS";
airGooglePlayGames.signOut();
loadingBar.gotoAndStop(1);
button_login.visible = true;
btn_out.visible = false;
}
Any idea what could happen?
A few things that might help:
I think your stuff at the top should be in a constructor function. For this type of code, with event listeners, you might be much better off making an external .as3 file and attach to a document class or movieClip base class, than putting the code in the timeline, as I think your code might not always be available as you move around??
And I notice you do:
this.checkeStatus();
Right away, which might do this:
btn_out.visible = false;
button_login.visible = true;
Or it might do this:
button_login.visible = false;
btn_out.visible = true;
But I think it doesn't matter because right after that, you return to the line under this.checkeStatus(), and get this:
btn_out.visible = false;
button_login.visible = false;
So no matter what happened with this.checkeStatus(), you end up with both buttons turned off, no? So maybe try moving this.checkeStatus(); down to the bottom of the constructor function so it goes last.
It might be more compact and less confusing to break off all these repeating visible = false / true lines into their own function like:
private function setStatusButtonsVisible(status:Boolean){
button_login.visible = status;
btn_out.visible = !status;
if (status){
loadingBar.gotoAndStop(2);
}else{
loadingBar.gotoAndStop(1);
}
}
Since in all cases but the first you're toggling the 2nd to be the opposite of the first.

Sharing to Facebook shows error "We are Sorry, this post is no longer available. It may have been removed"

I'm trying to implement Facebook sharing in my game using Unity 3D + Facebook Unity SDK. But when I tried testing to post to my wall, this error shows up: "We are Sorry, this post is no longer available. It may have been removed." Can anybody help me? Thanks in advance.
BTW, here's my code:
using UnityEngine;
using System.Collections;
public class FacebookController : MonoBehaviour {
public bool isUsingFacebook = true; //Are we using Facebook SDK? This variable is only
//Feed parameters.
private string link = "market://details?id=com.LaserCookie.Queue"; //The link that will show the user the game's google play store address
private string linkName = "Queue"; //The link name
private string linkCaption = "Wow this game is great! 10/10 must play!"; // The caption of the link
private string linkDescription = "I achieved the score of " + PlayerController.instance.score.ToString() + "! Try to beat me if you can!"; //The description of the link
private string picture = "http://www.drycreekequestriancenter.com/testImage.jpeg"; //This is the image / game icon for the link. For now, it's shamelessly got from a random source. Thank you, random citizen...
void Awake()
{
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
//Init FB
private void Init()
{
if (!FB.IsInitialized)
{
FB.Init(OnInitComplete, OnHideUnity);
}
}
//Callback that will be called when the initialization is completed
private void OnInitComplete()
{
Debug.Log("FB.Init completed: Is user logged in? " + FB.IsLoggedIn);
//Check if we are logged in.
//If not, we will log in.
//If we are, post status.
if (!FB.IsLoggedIn)
{
LoginWithPublish();
}
else
{
PostImpl();
}
}
//Callback that will be called when the game is shown / not
private void OnHideUnity(bool isGameShown)
{
Debug.Log("Is game showing? " + isGameShown);
}
//Post to Facebook. This is the only exposed method because we only use this to post to Facebook.
//The initialization and login will be called when needed.
//It will first detect whether or not we have been initialized. And will init if we haven't.
//Then it will check whether or not we have been logged in with publish. And will log in if not.
public void PostToFacebook()
{
//Are we using facebook SDK?
if (isUsingFacebook)
{
if (!FB.IsInitialized) //Check for initialization
{
Init();
}
else if (!FB.IsLoggedIn) //Check for login
{
LoginWithPublish();
}
else //Post if we are already initia;ized and logged in
{
PostImpl();
}
}
}
//The true implementation of the posting
private void PostImpl()
{
FB.Feed("",link, linkName,linkCaption,linkDescription,picture);
}
//Login to Facebook with publish
private void LoginWithPublish()
{
// It is generally good behavior to split asking for read and publish
// permissions rather than ask for them all at once.
//
// In your own game, consider postponing this call until the moment
// you actually need it.
FB.Login("publish_actions", LoginCallback);
}
//Login callback
void LoginCallback(FBResult result)
{
if (result.Error != null)
{
Debug.Log( "Error Response:\n" + result.Error );
//TODO: Retry login if we have error? Or do we display a pop up?
}
else if (!FB.IsLoggedIn)
{
Debug.Log( "Login cancelled by Player" );
//TODO: Do we display a pop up?
}
else
{
Debug.Log( "Login was successful!" );
PostImpl();
}
}
}
You need to add Key Hash for FB application.
Go to My Apps, select you application, open Setting tab, add platform for android, and add you key hash.
check this link out
Setting a Release Key Hash
I've fixed the issue. It turns out it's because I used my still in development google store address as the link. I thought it would be automatically recognized regardless of my app is live or not. Thank you anyway. :)

HelloFacebookSample onBackpressed gives status success message even not post status

I have integrated sdk in my application but when i am going to sharedialog and press back button sdk gives "success" even not post click.
For more details SDK v 3.5 and it's code which given success while i am trying to test using real Facebook account and pressing cancel.but while using test account and when i check with this "getNativeDialogCompletionGesture" method it's working but not in real account.
My requirement is while pressing cancel it should not show success on backpressed.
public static boolean handleActivityResult(Context context, PendingCall appCall, int requestCode, Intent data,
Callback callback) {
if (requestCode != appCall.getRequestCode()) {
return false;
}
if (attachmentStore != null) {
attachmentStore.cleanupAttachmentsForCall(context, appCall.getCallId());
}
if (callback != null) {
if (NativeProtocol.isErrorResult(data)) {
Exception error = NativeProtocol.getErrorFromResult(data);
callback.onError(appCall, error, data.getExtras());
} else {
callback.onComplete(appCall, data.getExtras());
}
}
return true;
}

Freeze activity/method execution until get a response from an dialog

I am trying to implement an administration mode when the user tap 7 times on back button.
Then, A dialog message will be called with editText asking for a password. if the password matches with the one in the database, I set passwordMacthes as TRUE and return it to whatever calls the dialog setTapCount and to start administration mode activity.
However, return passordMatches always return FALSE because it finishes the execution before the dialogMessage verifies the password and be dismissed or canceled by the user.
here is my setTapCount method :
public static boolean setTapCount(Context context){
tapCount = tapCount + 1;
if(tapCount == 7){
tapCount = 0;
dialogMessage(context);
return passwordMatches;
}else{
return false;
}
}
Does anyone know how to call the line below of dialogMessage(context) only once it is finished ?
thanks
Move that line to the handler for the accept button in the dialog, and rewrite your app to be event-driven (e.g., have setTapCount() accept a result listener object that can be notified of what the user did, rather than return a boolean).

Categories

Resources