我制作了一个Android应用程序,它将用户身份验证到一个活动目录。目前,我已经按照http://www.windowsazure.com/en-us/documentation/articles/mobile-services-android-get-started-users/的教程进行了操作。
此时我只需要对用户进行身份验证。所以我做了以下几点: -
import com.microsoft.windowsazure.mobileservices.MobileServiceApplication;
import com.microsoft.windowsazure.mobileservices.MobileServiceAuthenticationProvider;
import com.microsoft.windowsazure.mobileservices.MobileServiceClient;
import com.microsoft.windowsazure.mobileservices.MobileServiceUser;
import com.microsoft.windowsazure.mobileservices.ServiceFilterResponse;
import com.microsoft.windowsazure.mobileservices.UserAuthenticationCallback;
public static MobileServiceClient mobileServiceClient;
public MobileServiceUser _user;
MobileServiceClient mCLient;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
web = (WebView)findViewById(R.id.webSignin);
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("https://login.microsoftonline.com/login.srf?wa=wsignin1%2E0&rpsnv=2&ct=1390811289&rver=6%2E1%2E6206%2E0&wp=MBI&wreply=https%3A%2F%2Fwww7679%2Esharepoint%2Ecom%2F%5Flayouts%2F15%2Flanding%2Easpx%3FSource%3Dhttps%253A%252F%252Fzevenseascom%252D11%252Esharepoint%252Eemea%252Emicrosoftonline%252Ecom%252F%255Fforms%252Fdefault%252Easpx&lc=16393&id=500046&guests=1");
authenticate();
}
private void authenticate()
{
// TODO Auto-generated method stub
mCLient.login(MobileServiceAuthenticationProvider.Google, new UserAuthenticationCallback()
{
@Override
public void onCompleted(MobileServiceUser user, Exception exception,
ServiceFilterResponse response)
{
// TODO Auto-generated method stub
if(exception == null)
{
createAndShowDialog(String.format("You are now logged in - %1$2s", user.getUserId()),"Success");
Intent myIntent = new Intent(MainActivity.this, Directory.class);
startActivity(myIntent);
}
else
{
createAndShowDialog("You must log in. Login Required", "Error");
}
}
});
}
但我收到以下错误: -
java.lang.NoClassDefFoundError: com.microsoft.windowsazure.mobileservices.MobileServiceAuthenticationProvider
01-28 10:34:04.732: E/AndroidRuntime(2150): at com.example.activedirectory.MainActivity.authenticate(MainActivity.java:68)
感谢任何帮助
答案 0 :(得分:0)
您是否尝试过this解决方案
Project Properties>Java Build Path>Order and Import tab
并检查您正在使用的libraries
。
似乎ADT更新22,您必须手动执行此操作:Libraries do not get added to APK anymore after upgrade to ADT 22。
答案 1 :(得分:0)
请为MobileServiceClient mCLient;
初始化你只是声明,而不是初始化。可能是
mClient = new MobileServiceClient(...);
错误:
-01-28 11:56:50.974: E/AndroidRuntime(6793):
java.lang.NoClassDefFoundError: com.google.gson.GsonBuilder 01-28 11:56:50.974: E/AndroidRuntime(6793): at com.microsoft.windowsazure.mobileservices.MobileServiceClient.createMobileServiceGsonBuilder(MobileServiceClient.java:136) 01-28 11:56:50.974:
E/AndroidRuntime(6793): at com.microsoft.windowsazure.mobileservices.MobileServiceClient.<init>(MobileServiceClient.java:187)
只需添加库:GSON