enter code here
我在项目中使用的是OneSignal。从proxy
开始使用时如何设置OneSignal
?
以下是我的代码,但没有proxy
在互联网上使用:
new Thread(new Runnable() {
@Override
public void run() {
try {
String userName = "userNAme";
String pass = "Pass";
Authenticator authenticator = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return (new PasswordAuthentication(userName, pass.toCharArray()));
}
};
Authenticator.setDefault(authenticator);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("xx.xxx.xx", 443));
HttpURLConnection connection = (HttpURLConnection) new URL("https://onesignal.com/").openConnection(proxy);
connection.usingProxy();
connection.setAllowUserInteraction(true);
connection.connect();
if (connection.getResponseCode() == 200) {
OneSignal.startInit(App.this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.setNotificationReceivedHandler(new NotificationReceivedHandler())
.setNotificationOpenedHandler(new NotificationOpenedHandler(App.this))
.unsubscribeWhenNotificationsAreDisabled(true)
.init();
}
} catch (Exception ex) {
}
}
}).start();