2012-05-17 27 views
0

嗨我想連接到谷歌服務。 我是OAuth客戶端API來連接到它。 Th重定向我使用的URI是 「http:// localhost」如何在不向用戶顯示瀏覽器的情況下連接到Google服務?

但是,當我選擇「允許訪問」,然後我想開始啓動另一個活動。 但只要我按「允許訪問」,然後打開包含下列選項的意圖選擇器: 1)瀏覽器 2)項目名稱

其顯示的用「查看」動作,因爲我已經開始活動並以「BROWSABLE」類別宣佈目標活動。

但是當我刪除「可瀏覽」類別時,它直接顯示瀏覽器,因此頁面無法加載。

我正在使用的代碼是:

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); 

清單中我已經宣佈這樣的目標活動:

<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> 

我的問題是,我不想打開意圖選擇器當用戶在獲得認證後選擇「允許訪問」按鈕時。

請幫忙。

回答

0

而不是使用這個的:

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

您應該創建一個web視圖並加載URL的內容。這是如何Facebook或Twitter做他們的認證。如果您選擇使用webview,我建議您使用WebViewClient,因爲它會允許您進行大量自定義。

+0

我可以使用webview,但是當我按下「允許訪問」按鈕時,它會顯示說http:// localhost .....的屏幕無法加載。我想將用戶重定向到我的目標活動,這就是我使用Intent的原因。現在我該怎麼辦? –

+0

我告訴過你要使用webview,這樣你可以通過覆蓋方法來處理錯誤,看看發生了什麼。它似乎不處理回調。也許這有助於:http://stackoverflow.com/questions/2378800/android-webview-click-opens-default-browser – jsaye

+0

我做的唯一的事情是萬一網址提取錯誤我沒有使用view.load( url)。感謝你的幫助.. –

相關問題