java.awt.Desktop类 [英] java.awt.Desktop class

查看:94
本文介绍了java.awt.Desktop类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用适用于Android的Google API.由于适用于Android的Google API/G Suite快速入门参考了他们的Java示例,因此我正在尝试实现这一点:

I am using a Google API for android. Since Google API/G Suite Quickstart for android refers to their java examples, I am trying to implement this:

GoogleAuthorizationCodeFlow flow =
            new GoogleAuthorizationCodeFlow.Builder(
                    ReadMail.HTTP_TRANSPORT, ReadMail.JSON_FACTORY, clientSecrets, ReadMail.SCOPES)
                    .setDataStoreFactory(ReadMail.DATA_STORE_FACTORY)
                    .setAccessType("offline")
                    .build();


    AuthorizationCodeInstalledApp authCodeInstalledApp = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver());
    Credential credential = authCodeInstalledApp.authorize("user");

我现在遇到的问题是Android仅支持JDK类的子集.因此,不支持java.awt.Desktop. 但是我真的需要这个类,因为AuthorizationCodeInstalledAppauthorize()迟早会调用其内部函数browse().此功能需要Desktop类.

The problem, I am encountering now is that Android just support a subset of JDK classes. Therefore java.awt.Desktop isn't supported. But I really need this class, since AuthorizationCodeInstalledApp's authorize() will soon or later call its intern function browse(). This function needs the Desktop class.

有没有办法为Android获取该类?还是有其他解决方法可以通过Google进行身份验证?

Is there a way to get that class for android? Or is there another workaround to authenticate with Google?

推荐答案

我现在自己解决了它.我没有尝试从java.awt.Desktop获取Desktop类,而是改写了on Authorization方法:

I solved it by myself now. Instead of trying to get the Desktop class from java.awt.Desktop, I just overwrote the on Authorization method:

AuthorizationCodeInstalledApp ab = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()){
        protected void onAuthorization(AuthorizationCodeRequestUrl authorizationUrl) throws IOException {
                String url = (authorizationUrl.build());
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                main_Activity.startActivity(browserIntent);
            }
        };

之所以这样做,是因为authorize()将调用onAuthorization(),后者将调用Browse(),后者会检查是否支持Desktop. 因此,通过重写onAuthorization()方法,我将不再需要该类. 我改写的课程只会在您的android设备中使用该授权网址启动一个新的Browserwindow.

The reason I did this is because authorize() will call onAuthorization() which will call browse(), which checks if Desktop is supported or not. So by rewriting the onAuthorization() method, I won't need that class anymore. My rewritten class will just start a new Browserwindow with that authorization-URL in your android device.

我希望,我能够为遇到此问题的任何人提供帮助.

I hope, I was able to help anyone, who encounteres this problem.

这篇关于java.awt.Desktop类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆