Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Facebook login on android
Qt 6.11 is out! See what's new in the release blog

Facebook login on android

Scheduled Pinned Locked Moved Solved Mobile and Embedded
23 Posts 10 Posters 13.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    julienw
    wrote on last edited by
    #11

    As the behaviour is strange and seems to doesn't correspond to the design pattern of Android, I stopped this way.

    So, I came back to your solution and I could run multiple QtActivity without issue.
    Just declare a simple activity for class that are not the main class (without <intent-filter>) in the application tag.
    in addition to the previous code, my TMain.java is :

    @package com.appli.test;

    import org.qtproject.qt5.android.bindings.QtApplication;
    import org.qtproject.qt5.android.bindings.QtActivity;
    import android.os.Bundle;
    import android.content.Intent;
    import android.util.Log;

    public class TMain extends QtActivity
    {
    public static void startFacebook()
    {// Called from JNI
    getInstance().startFacebookObject();
    }

    public static TMain g_instance;
    public TMain()
    {
    }
    public static TMain getInstance()
    {
        return g_instance;
    }
    public void startFacebookObject()
    {
        try
        {
            Intent s = new Intent(TMain.this, TFacebook.class);
            this.startActivity(s);
        }catch (Exception e)
        {
            e.printStackTrace();
        }
    }
    
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        try
        {
            Log.e(QtApplication.QtTAG, "Creating FKMain");
            super.onCreate(savedInstanceState);
            g_instance = this;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
    }
    

    }
    @

    Do you know why using finish() in TFacebook closes the application and don't resume to the previous activity?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      the_scrabi
      wrote on last edited by
      #12

      Well well.
      So at least my code is working to.
      But a bit embarrassing is that it could have worked weeks ago if I just didn't forget to include the package to my app into the code. That's the reason Intent couldn't find my class xD.

      Now to your code. I think I don't understand it fully. Did you replace the main QtActivity with your TMain activity, and then use a second implementation of it to start your Tfacebook Activity ?!?
      If so don't do that, its bad xD. Also it was bedder if you implemented everything in your Tfacebook Activity:

      [code]
      package com.appli.test;

      import org.qtproject.qt5.android.QtNative;
      import android.os.Bundle;
      import android.content.Intent;
      import android.app.Activity;
      import android.util.Log;

      public class TFacebook extends Activity
      {
      private class MyWebViewClient extends WebViewClient {
      @Override
      public boolean shouldOverrideUrlLoading(WebView view, String url) {
      view.loadUrl(url);
      return true;
      }
      }
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
      super.onCreate(savedInstanceState);

          Log.e(QtApplication.QtTAG, "Setting Webview");
          setContentView(R.layout.activity);
          WebView myWebView = (WebView) findViewById(R.id.webview);
          myWebView.setWebViewClient(new MyWebViewClient());
          myWebView.loadUrl("http://www.google.com");
      }
      

      public static void login() {
      try {
      Activity mother = QtNative.activity();
      Intent s = new Intent(mother, TFacebook.class);
      } catch (Exception e) {
      e.printStackTrace();
      }
      }
      }
      [/code]

      Now you only have to call:
      [code]
      QAndroidObject::callStaticMethod("com.appli.test.TFacebook", "login");
      [/code]

      This also shouldn't close the whole app if you call finish().

      (No guarantee that its completely working. I didn't test this code here.)

      With best regards, Schabi. xD

      1 Reply Last reply
      0
      • J Offline
        J Offline
        julienw
        wrote on last edited by
        #13

        Haha, error reporting is "great" when it comes from android ^^

        I'm using the QML interface (I know you don't). So, I need to keep the activity from Qt, it's why I need to extends the QtActivity (and I will not have only facebook in native side)
        In addition, examples from digia about hangman (for paiment) and their notifications example extends the QtActivity too.
        So I don't think that it's bad ;)

        For the finish(), it was just the " xmlns:android" in the layout that is an error. I detected it by implementing a new application from Eclispe : it could give me error on UI where Qt don't.
        So, I could have something working too ;). I can login and use the Graph API to get what I need.

        The main issue for now is to keep the session open (access token is only for one hour). Do you know what we need to do? (like storing cookies in the app maybe)

        1 Reply Last reply
        0
        • T Offline
          T Offline
          the_scrabi
          wrote on last edited by
          #14

          Seams like we need to request a long live access token witch leasts for 60 days:
          https://developers.facebook.com/docs/facebook-login/access-tokens/#extending

          1 Reply Last reply
          0
          • T Offline
            T Offline
            the_scrabi
            wrote on last edited by
            #15

            I finally got it working !!!
            I was able to merge the Facebook SDK into my Android app, to get 60 day longterm accesstoken.
            If someone is interested please answer me, or write me a mail. Then I'll try to prepare the code so everyone can have it :)

            but despite its working, its not very nice.

            chears schabi

            V 1 Reply Last reply
            0
            • F Offline
              F Offline
              feldifux
              wrote on last edited by
              #16

              Nice work schabi, you can add a link to your code here in the forums if you like?

              Since a couple of days, we now also have a Facebook Qt 5 plugin ready for Android & iOS. You can have a look at the sample on github and the tutorials here:

              • "How to integrate Facebook into Qt 5 Apps":http://plugins.v-play.net/blog/2014/05/integrate-facebook-in-your-qt-5-apps/
              • "Tutorial & Sample Code for Facebook Login in Qt 5":http://plugins.v-play.net/blog/2014/06/how-to-benefit-from-facebook-login-in-your-qt-5-app/
              • "Facebook Plugin Overview":http://plugins.v-play.net/plugins/facebook/
              • "Facebook Plugin Documentation":http://plugins.v-play.net/doc/plugin-facebook/

              Founder of Felgo SDK - http://felgo.com/qt

              Felgo simplifies

              • Mobile App Dev with Qt esp. iOS & Android
              • Game Development with Qt

              What others say

              Felgo scored #1 in Cross-Platform App Development Tools Report - see why: https://goo.gl/rgp3rq

              1 Reply Last reply
              0
              • D Offline
                D Offline
                DonRico
                wrote on last edited by
                #17

                the_scrabi, I would really appreciate a working example to study. My desired result is to add Google Login to Qt Android app and the problem (missing webview) is fairly similar. Also could help me to resolve the Google maps integration issues.

                Another good exmaple to study is probably "Qt hangman ":http://blog.qt.digia.com/blog/2013/12/12/implementing-in-app-purchase-on-android/ since it implements android in-app purchasing an that can't be too different compared to what we need to achieve.

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  the_scrabi
                  wrote on last edited by
                  #18

                  All right I'll try to get it ready the next days. But I need to apologise, it still has some problems, and I do this in my spare time. So it will take me a few days to get it working correctly.

                  Also this is NOT using a Web login any more !!! Since you could only get short term access token from Web login I went over to the regular facebook sdk for android.

                  But if you want to do Web Login here is something that might help you:

                  Android Activity Doc:
                  http://developer.android.com/reference/android/app/Activity.html

                  Intent Doc (you need intent to start new activitys):
                  http://developer.android.com/reference/android/content/Intent.html

                  QtAndroidExtras (you need it to call/run java code):
                  http://qt-project.org/doc/qt-5/qtandroidextras-index.html

                  Here a link to an older example of my facebook login thing. It still uses Web login:
                  https://github.com/theScrabi/FbLoginQtAndroid.git

                  If something is not clear, or you still have questions feel free to mail me :)

                  greetings schabi

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    the_scrabi
                    wrote on last edited by
                    #19

                    All right i said i would need a few days. I guess I overestimated my self a bit. It now took me about two full months to get it working that prober to give it to other people. But now I also did a small documentation.
                    I hope it will help somebody. And if you still have questions or any wishes feel free to mail me.

                    Github repository: https://github.com/theScrabi/TizFbExample

                    Chears schabi

                    1 Reply Last reply
                    1
                    • T the_scrabi

                      I finally got it working !!!
                      I was able to merge the Facebook SDK into my Android app, to get 60 day longterm accesstoken.
                      If someone is interested please answer me, or write me a mail. Then I'll try to prepare the code so everyone can have it :)

                      but despite its working, its not very nice.

                      chears schabi

                      V Offline
                      V Offline
                      Vicky Sharma
                      wrote on last edited by Vicky Sharma
                      #20

                      @the_scrabi

                      I also stuck to use Fb login in my QML.
                      Would you like to share me how to do yourself so will be able to do myself too.

                      Yeah ..
                      This example is working as per requirement thanks for this.. :)

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        Danibray
                        Banned
                        wrote on last edited by Danibray
                        #21
                        This post is deleted!
                        aha_1980A 1 Reply Last reply
                        -2
                        • D Danibray

                          This post is deleted!

                          aha_1980A Offline
                          aha_1980A Offline
                          aha_1980
                          Lifetime Qt Champion
                          wrote on last edited by
                          #22
                          This post is deleted!
                          1 Reply Last reply
                          0
                          • J Offline
                            J Offline
                            junaidbyrd
                            Banned
                            wrote on last edited by
                            #23
                            This post is deleted!
                            1 Reply Last reply
                            -1

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved