java.awt.Desktop class

前端 未结 1 1164
慢半拍i
慢半拍i 2021-01-13 10:34

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:

GoogleAuth         


        
1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-13 11:27

    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);
                }
            };
    

    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.

    0 讨论(0)
提交回复
热议问题