Hi i created an android project in which i make a main activity
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String ss="https://accounts.google.com/o/oauth2/auth?client_id=anonymous&redirect_uri=https://cloudspokeproject.appspot.com/oauth2callback&response_type=code&scope=https://www.googleapis.com/auth/apps.groups.settings https://apps-apis.google.com/a/feeds/groups/";
Uri url=Uri.parse(ss);
Intent in=new Intent(Intent.ACTION_VIEW,url);
startActivity(in);
}
and then created a Response Activity
with code
public class Response extends Activity {
@Override
public void onCreate(Bundle bundle){
super.onCreate(bundle);
TextView text=new TextView(this);
Uri uri=this.getIntent().getData();
String code=uri.getQueryParameter("code");
URL url;
try {
url = new URL("https://accounts.google.com/o/oauth2/token");
String param="code="+code+"&client_id=anonymous&client_secret=anonymous&redirect_uri=https://cloudspokeproject.appspot.com/oauth2callback&grant_type=authorization_code";
HttpURLConnection connection =
(HttpURLConnection)url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
connection.getOutputStream().write( param.getBytes() );
InputStream str= connection.getInputStream();
BufferedReader reader=new BufferedReader(new InputStreamReader(str));
String l="";
String l1="";
while((l=reader.readLine())!=null){
l1+=l;
}
text.setText(l1);
setContentView(text);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}}
and here is my menifest file code
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Response"
android:label="Hello World"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:host="cloudspokeproject.appspot.com/oauth2callback" android:scheme="https"/>
</intent-filter>
</activity>
</application>
i am trying to implement google Authentication for an app and Main Activity is opening a google login and after signing in it is redirected to clouspokeproject.appspot.com/oauth2callback but as i put an intent filter in Response activity in menifest .when url cloudspokeproject.apspot.com/oauth2callback is called in browser then android should redirect it to activity Response.i successfully implemented oauth for twitter and couple of other apis but this time its not redirecting to Response activity
can any one please tell where i am wrong.i know mistake is very minor please point me so that i can rectify it.
Hi for returning back to my my activity intent filter should be like
i have to remove /oauth2callback in host attribute because its a very rare url and used for only once in project so its working fine for me now.