I have this exception and I was reading a thread on this, and it seemed confusing:
I already added this line to my manifest:
<uses-permission android:name="android.permission.INTERNET" />
I have a function which is getting a url a returning a string but it gives an error of network thread exception. I searched about it ad i got the solution that i should use async task but problem is i cannot figure out how to use the function using async task and return a string This is my function
private String createEnterprise() throws IOException {
// Initiate signup process.
System.out.println("Creating signup URL...");
final SignupUrl[] signupUrl = androidManagementClient
.signupUrls()
.create()
.setProjectId(PROJECT_ID)
.setCallbackUrl("https://localhost:80")
.execute();
System.out.print(
"To sign up for a new enterprise, open this URL in your browser: ");
System.out.println(signupUrl[0].getUrl());
System.out.println(
"After signup, you will see an error page in the browser.");
System.out.print(
"Paste the enterpriseToken value from the error page URL here: ");
String enterpriseToken =
new BufferedReader(new InputStreamReader(System.in)).readLine();
// Create the enterprise.
System.out.println("Creating enterprise...");
return androidManagementClient
.enterprises()
.create(new Enterprise())
.setProjectId(PROJECT_ID)
.setSignupUrlName(signupUrl[0].getName())
.setEnterpriseToken(enterpriseToken)
.execute()
.getName();
}
and here i am using this function in a string
String enterpriseName = createEnterprise();
Please help to figure out how to use with a async task or some other method