android – 通过Webview登录Linkedin登录

android – 通过Webview登录Linkedin登录,第1张

概述实际上我的应用程序使用linkedin通过linkedin应用程序和webview登录.使用linkedin登录工作正常,但如果以后的应用程序不可用,我使用webview处理登录.这也工作得很好,但今天突然陷入了一些代码异常行列.我在我的Linkedin对话框类中获取null访问令牌,所以我想把try catch但是之后它会显示空白的webview我不知道该怎么做.这是我的linkedin对话框代 实际上我的应用程序使用linkedin通过linkedin应用程序和webvIEw登录.使用linkedin登录工作正常,但如果以后的应用程序不可用,我使用webvIEw处理登录.这也工作得很好,但今天突然陷入了一些代码异常行列.我在我的linkedin对话框类中获取null访问令牌,所以我想把try catch但是之后它会显示空白的webvIEw我不知道该怎么做.这是我的linkedin对话框代码

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;}@OverrIDeprotected 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();    }}@OverrIDepublic 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);}}

这是登录按钮上的函数调用

private voID linkedInLogin(){    mProgressDialog = new ProgressDialog(LoginActivity.this);    mProgressDialog.setMessage(AppConstants.sLoadingMsg);    mProgressDialog.setCancelable(true);    mProgressDialog.show();    d = new linkedindialog(LoginActivity.this,mProgressDialog);    d.show();    d.setVerifIErListener(new linkedindialog.OnVerifyListener() {        @Suppresslint("NewAPI")        @OverrIDe        public voID onVerify(String verifIEr) {            try {                accesstoken = linkedindialog.oAuthService.getoAuthAccesstoken(linkedindialog.liToken,verifIEr);                linkedindialog.factory.createlinkedInapiclient(accesstoken);                clIEnt = factory.createlinkedInapiclient(accesstoken);                AppLogs.printLogs("linkedinSample","ln_access_token: " + accesstoken.getToken());                mAccesstokenLogin = accesstoken.getToken();                com.Google.code.linkedinAPI.schema.Person p = null;                p = clIEnt.getProfileForCurrentUser(EnumSet.of(                        ProfileFIEld.ID,ProfileFIEld.FirsT_name,ProfileFIEld.LAST_name,ProfileFIEld.headliNE,ProfileFIEld.SUMMARY,ProfileFIEld.PUBliC_PROfile_URL,ProfileFIEld.INDUSTRY,ProfileFIEld.PICTURE_URL,ProfileFIEld.LOCATION,ProfileFIEld.LOCATION_name,ProfileFIEld.EMAIL_ADDRESS));                AppLogs.printLogs("linkedin ID"," :: "+p.getID());                Userlinkedindata userlinkedindata = Userlinkedindata.getInstance();                try {                    if (p.getEmailAddress() == null | p.getEmailAddress().isEmpty()) {                        userlinkedindata.setmEmailAddress(AppConstants.sNotAvailable);                    } else {                        userlinkedindata.setmEmailAddress(p.getEmailAddress());                    }                }catch (Exception e){                    userlinkedindata.setmEmailAddress(AppConstants.sNotAvailable);                }                try {                    if (!p.getFirstname().isEmpty()) {                        userlinkedindata.setmFirstname(p.getFirstname());                    } else {                        userlinkedindata.setmFirstname(AppConstants.sNotAvailable);                    }                }catch (Exception e){                    userlinkedindata.setmFirstname(AppConstants.sNotAvailable);                }                }                                 }    });    mProgressDialog.dismiss();}

所有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.ExceptionInInitializerErrorW/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.access0(LoginActivity.java:72)W/System.err﹕ at com.app.circles.LoginActivity.onClick(LoginActivity.java:158)

然后我按回按钮再次登录然后得到这样的新异常:

W/System.err﹕ java.lang.NoClassDefFoundError: com.Google.code.linkedinAPI.clIEnt.constant.linkedInAPIUrls
解决方法 我自己解决了这个问题…我只清除构建包装然后我删除了现有的jar文件,如linkedin-j,signpost-core,commons-codec,再次导入相同的文件,然后构建项目……现在它正在运行好. 总结

以上是内存溢出为你收集整理的android – 通过Webview登录Linkedin登录全部内容,希望文章能够帮你解决android – 通过Webview登录Linkedin登录所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1123649.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存