Android 通过Webview登录Linkedin时卡住
实际上,我的应用程序是通过linkedin应用程序和webview使用linkedin登录的。使用linkedin登录正常,但如果linkedin应用程序不可用,我将使用webview处理登录。这也很好,但今天它突然陷入了一些代码异常。我在我的Linkedin对话类中获得了空访问令牌,所以我喜欢放置try-catch,但之后它将显示空白的webview,我不知道该怎么做。这是我的linkedin对话代码Android 通过Webview登录Linkedin时卡住,android,exception,linkedin,linkedin-api,Android,Exception,Linkedin,Linkedin Api,实际上,我的应用程序是通过linkedin应用程序和webview使用linkedin登录的。使用linkedin登录正常,但如果linkedin应用程序不可用,我将使用webview处理登录。这也很好,但今天它突然陷入了一些代码异常。我在我的Linkedin对话类中获得了空访问令牌,所以我喜欢放置try-catch,但之后它将显示空白的webview,我不知道该怎么做。这是我的linkedin对话代码 public class LinkedinDialog extends Dialog { p
public class LinkedinDialog extends Dialog
{
private ProgressDialog progressDialog = null;
public static LinkedInApiClientFactory factory;
public static LinkedInOAuthService oAuthService;
public static LinkedInRequestToken liToken;
private WebView mWebView;
private Context mContext;
public LinkedinDialog(Context context, ProgressDialog progressDialog)
{
super(context);
mContext = context;
this.progressDialog = progressDialog;
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);// must call before super.
super.onCreate(savedInstanceState);
setContentView(R.layout.ln_dialog);
setWebView();
}
/**
* set webview.
*/
private void setWebView()
{
mWebView = (WebView) findViewById(R.id.webkitWebView1);
mWebView.getSettings().setJavaScriptEnabled(true);
try {
LinkedinDialog.oAuthService = LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(AppConstants.LINKEDIN_CONSUMER_KEY, AppConstants.LINKEDIN_CONSUMER_SECRET);
LinkedinDialog.factory = LinkedInApiClientFactory.newInstance(AppConstants.LINKEDIN_CONSUMER_KEY, AppConstants.LINKEDIN_CONSUMER_SECRET);
LinkedinDialog.liToken = LinkedinDialog.oAuthService.getOAuthRequestToken(AppConstants.OAUTH_CALLBACK_URL);
mWebView.loadUrl(LinkedinDialog.liToken.getAuthorizationUrl());
mWebView.setWebViewClient(new HelloWebViewClient());
mWebView.setPictureListener(new PictureListener() {
@Override
public void onNewPicture(WebView view, Picture picture) {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
});
}catch (ExceptionInInitializerError e){
AppLogs.printLogs("ExceptionInInitializerError :: " , " err ::");
LinkedinDialog.this.dismiss();
mWebView.goBack();
}catch (NoClassDefFoundError ex){
AppLogs.printLogs("NoClassDefFoundError :: " , " err ::");
ex.printStackTrace();
LinkedinDialog.this.dismiss();
mWebView.goBack();
}catch (Exception ee){
LinkedinDialog.this.dismiss();
mWebView.goBack();
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_DOWN){
switch(keyCode)
{
case KeyEvent.KEYCODE_BACK:
if (mWebView.canGoBack()) {
mWebView.goBack();
} else {
cancel();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}
class HelloWebViewClient extends WebViewClient
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if (url.contains(AppConstants.OAUTH_CALLBACK_URL))
{
Uri uri = Uri.parse(url);
String verifier = uri.getQueryParameter("oauth_verifier");
cancel();
for (OnVerifyListener d : listeners)
{
// call listener method
d.onVerify(verifier);
}
}
else if (url.contains("https://www.google.co.in/"))
{
cancel();
}
else
{
Log.e("LinkedinSample", "url: " + url);
view.loadUrl(url);
}
return true;
}
}
/**
* List of listener.
*/
private List<OnVerifyListener> listeners = new ArrayList<OnVerifyListener>();
/**
* Register a callback to be invoked when authentication have finished.
*
* @param data
* The callback that will run
*/
public void setVerifierListener(OnVerifyListener data)
{
listeners.add(data);
}
/**
* Listener for oauth_verifier.
*/
public interface OnVerifyListener
{
/**
* invoked when authentication have finished.
*
* @param verifier
* oauth_verifier code.
*/
public void onVerify(String verifier);
}
}
所有jar依赖项:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile project(':linkedin-sdk')
compile files('libs/linkedin-j-android.jar')
compile files('libs/commons-codec-1.3.jar')
compile files('libs/signpost-core-1.2.1.1.jar')
compile files('libs/signpost-commonshttp4-1.2.1.2.jar')
compile files('libs/signpost-jetty6-1.2.1.1.jar')
compile 'com.github.bumptech.glide:glide:3.5.2'
compile 'com.android.support:support-v4:22.0.0'
compile 'com.googlecode.libphonenumber:libphonenumber:7.0.4'
compile "com.google.android.gms:play-services:8.1.0"
compile 'org.apache.directory.studio:org.apache.commons.io:2.4'
compile 'com.android.support:multidex:1.0.0'}
第一次单击时收到的异常:
W/System.err﹕ java.lang.ExceptionInInitializerError
W/System.err﹕ at com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceImpl.getOAuthProvider(LinkedInOAuthServiceImpl.java:230)
W/System.err﹕ at com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceImpl.getOAuthRequestToken(LinkedInOAuthServiceImpl.java:170)
W/System.err﹕ at com.app.util.LinkedinDialog.setWebView(LinkedinDialog.java:64)
W/System.err﹕ at com.app.util.LinkedinDialog.onCreate(LinkedinDialog.java:51)
W/System.err﹕ at android.app.Dialog.dispatchOnCreate(Dialog.java:373)
W/System.err﹕ at android.app.Dialog.show(Dialog.java:274)
W/System.err﹕ at com.app.circles.LoginActivity.linkedInLogin(LoginActivity.java:228)
W/System.err﹕ at com.app.circles.LoginActivity.access$100(LoginActivity.java:72)
W/System.err﹕ at com.app.circles.LoginActivity$1.onClick(LoginActivity.java:158)
然后我按“上一步”按钮再次登录,然后出现如下新异常:
W/System.err﹕ java.lang.NoClassDefFoundError: com.google.code.linkedinapi.client.constant.LinkedInApiUrls
我自己解决了这个问题…我只清除了构建包装,然后删除了linkedin的现有jar文件,比如linkedin-j、路标核心、,commons编解码器并再次导入相同的文件,然后构建项目…现在它运行良好。是否有可能发布错误日志或stacktrace?@jagmohan请检查我的更新问题我自己解决了这个问题…我只清除了构建包装,然后删除了linkedin的现有jar文件,如linkedin-j、signpost core、,commons编解码器并再次导入相同的文件,然后构建项目…现在它运行良好。很高兴听到。继续
W/System.err﹕ java.lang.NoClassDefFoundError: com.google.code.linkedinapi.client.constant.LinkedInApiUrls