0

Hi I want to connect to the google services . I am OAuth Client API to connect to it. Th redirect uri I'm using is "http://localhost"

But when I select "Allow access" then I want to start start another activity . But as soon as I press "Allow access" , then it opens the intent chooser with the following options : 1) Browser 2) Project Name

It is showing this because I have started Activity with "View" Action and declared the target activity with "BROWSABLE" category.

But when I am removing "BROWSABLE" category, then it is directly showing browser and hence the page dosn't loads.

The code I'm using is :

String authenticationUrl= "https://accounts.google.com/o/oauth2/auth?   
scope=https://www.googleapis.com/"+
        "auth/userinfo.email+https://www.googleapis.com/auth/userinfo."+
            "profile";
    OAuthClientRequest request = null;
    try {
        request = OAuthClientRequest
               .authorizationLocation(authenticationUrl)
               .setClientId(CLIENT_ID)
               .setRedirectURI(REDIRECT_URI)
                .buildQueryMessage();
    } catch (OAuthSystemException e) {
        e.printStackTrace();
    }
    Intent intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse(request.getLocationUri() + "&response_type=code"));
    startActivity(intent);

In Manifest I have declared the target activity like this :

  <activity android:name=".TestActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT" />
                        <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http" android:host="localhost"/>
        </intent-filter>
    </activity>

My issue is that I don't want to open intent chooser when user selects "Allow access" button after getting authenticated .

Please help.

Shadab Ansari
  • 7,022
  • 2
  • 27
  • 45

1 Answers1

0

Instead of using this:

Intent intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse(request.getLocationUri() + "&response_type=code"));

You should create a webview and load the content of the url. This is how facebook or twitter do their authentification. If you choose to use the webview, I recomend you to use the WebViewClient since it will allow you a lot of customization.

jsaye
  • 914
  • 7
  • 12
  • I can use webview but when I pressed "Allow access" button it shows that screen which says http://localhost..... cannot be loaded. I want to redirect the user to my target activity that's why I used Intent. Now what should I do ? – Shadab Ansari May 17 '12 at 09:49
  • I told you to use a webview so you can handle errors by overriding the method and see what is happening. It seems like are not handling the callback. Maybe this helps: http://stackoverflow.com/questions/2378800/android-webview-click-opens-default-browser – jsaye May 17 '12 at 16:41
  • The only thing I did was in case the url is fetching error I didn't use view.load(url) . Thanks for all your help.. – Shadab Ansari May 18 '12 at 06:53