Java 错误描述:无法返回到提供的重定向uri
我正在尝试创建一个应用程序,其中一个功能是添加用户登录/注销 我是这样说的: 因此,我的活动中有一个按钮,单击该按钮,它会将您重定向到浏览器以登录stack overflow网站。我想在用户登录后返回到我的应用程序。但是它说,“不能返回到提供的重定向uri” 这里是我的Java 错误描述:无法返回到提供的重定向uri,java,android,api,stack,Java,Android,Api,Stack,我正在尝试创建一个应用程序,其中一个功能是添加用户登录/注销 我是这样说的: 因此,我的活动中有一个按钮,单击该按钮,它会将您重定向到浏览器以登录stack overflow网站。我想在用户登录后返回到我的应用程序。但是它说,“不能返回到提供的重定向uri” 这里是我的AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vivek.stack.client">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".retro.Login"
android:label="@string/app_name"
android:configChanges="keyboard|orientation|screenSize">
<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:host="aahost"
android:scheme="bbscheme" />
</intent-filter>
</activity>
<activity android:name=".Mine">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER"></category>
<action android:name="android.intent.action.MAIN"></action>
</intent-filter>
</activity>
</application>
</manifest>
登录成功后,它应返回应用程序 回答我自己的问题
解决方案是确保您的
android:host
和android:scheme
与注册应用程序时提供的redirect\u uri
匹配 我希望能得到一些帮助(
package com.vivek.stack.client.retro;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import com.vivek.stack.client.R;
/**
* Created by Shiva on 14-04-2016.
*/
public class Login extends AppCompatActivity {
RelativeLayout relativeLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
relativeLayout = (RelativeLayout)findViewById(R.id.snack);
Button loginButton =(Button) findViewById(R.id.loginbutton);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String uri = "https://stackexchange.com/oauth?\n" +
"scope=private_info&\n" +
"redirect_uri=bbscheme://aahost&\n"+
"client_id=" ;
Intent intent = new Intent(
Intent.ACTION_VIEW,
Uri.parse(uri));
if(intent.resolveActivity(getPackageManager())!=null)
startActivity(intent);
}
});
}
@Override
protected void onResume() {
super.onResume();
// the intent filter defined in AndroidManifest will handle the return from ACTION_VIEW intent
Uri uri = getIntent().getData();
if (uri != null && uri.toString().startsWith(redirectUri)) {
// use the parameter your API exposes for the code (mostly it's "code")
String code = uri.getQueryParameter("code");
if (code != null) {
// get access token
Log.i("MYCODECODE" , code);
Snackbar.make(relativeLayout ,code , Snackbar.LENGTH_LONG).show();
} else if (uri.getQueryParameter("error") != null) {
// show an error message here
Log.i("NO CODE" , "NO CODE");
Snackbar.make(relativeLayout ,"we did not get" , Snackbar.LENGTH_LONG).show();
}
}
}
}