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
Forum Updated to NodeBB v4.3 + New Features

Facebook login on android

Scheduled Pinned Locked Moved Solved Mobile and Embedded
23 Posts 10 Posters 13.1k 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.
  • T Offline
    T Offline
    the_scrabi
    wrote on last edited by
    #8

    Nop. Not jet. Well since I couldn't solve the problem I worked on something different. But a few days ago I started working on it again. I want to crate a second Android Activity so I can access the regular Android GUI to run WebView, with witch I can show the facebook login page to my app. Well my problem at the moment is, to get another Activity running, besides the QtActivity with witch the qt surface runs. I asked that already in another thread: http://qt-project.org/forums/viewthread/37854/

    But i still couldn't get it working.

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

      I'll trying this way too and trying to understand how QtActivity and Intend works.
      But I have one theorical question : if we can subclass the main QtActivity that is used by the application, the only thing that we need is to swap the setContentView.
      Maybe this could resolve our issue without having to run multiple activity?

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

        from https://blog.qt.digia.com/blog/2013/07/23/anatomy-of-a-qt-5-for-android-application/
        I can follow my idea as events are dispatched on subclasses.

        And after some tests, It seems that I have a start of solution: I could open a webview into my own View.

        My manifest :
        @ <application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="@string/app_name" android:icon="@drawable/icon">
        <activity android:screenOrientation="portrait" android:name="com.appli.test.TFacebook" android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" android:label="@string/app_name">
        <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>

        ...
        <uses-permission android:name="android.permission.INTERNET"/>
        @

        My Layout.xml (in res/layout folder)
        @<?xml version="1.0" encoding="utf-8"?>
        <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <Webiew xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webview"
        android:layout_x="150px"
        android:layout_y="150px"
        android:width="100px"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
        </AbsoluteLayout>
        @
        My .java code (in src/com/appli/test)
        @
        public class TFacebook extends QtActivity
        {
        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");
        

        }
        }
        @

        Note : shouldOverrideUrlLoading avoid to open an external browser.
        The next step will be to come back to the previous layout of the main application.

        I hope this way lead to something.

        1 Reply Last reply
        0
        • 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