I am trying to create very basic network application, which will connect to google through socket, and send "GET" and print the output in a text view. but it appears that socket never connects... what am I doing wrong ??
here is the code
MainActiviy:
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import java.io.*;
import java.net.*;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tva = (TextView) this.findViewById(R.id.tv);
String str = "";
try {
Socket sock = new Socket("www.google.com", 80);
str = sock.getRemoteSocketAddress().toString();
tva.setText("Connected to: " + str);
DataOutputStream out = new DataOutputStream(sock.getOutputStream());
out.writeUTF("GET //");
BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
str = br.readLine();
while(str != null) {
tva.setText(str);
str = br.readLine();
}
out.close();
br.close();
sock.close();
} catch(Exception ex) {
}
}
}
manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.onik.netw"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.onik.netw.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
you are trying to use sockets on main UI thread, you will get exception android.os.NetworkOnMainThreadException
Move the try {} block into a separate thread. Since this will run on non-UI thread you cant access UI elements, so you need to pass the data back to main thread may be via Handler, so it can display the data received.
For a quick test, enclose that entire try block inside an anonymous thread
new Thread() {
public void run() {
// your try block goes here
}
}.start();
replace tva.setText with Log.d("test", str)
Related
My app to access a simple JSON and display it runs perfectly fine on the emulator(PIXEL 2 API 24) but not on any actual device I connect to it. Tried with both S8 and Note10, neither have data saver on either.
I even checked the apps data use afterwards and it said "0 B".
Here are the files:
MainActivity.java:
package com.example.internettest;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
Button button;
TextView textView;
ProgressDialog pd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
textView = (TextView) findViewById(R.id.textView);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
new JsonTask().execute("http://46d30cf268b0.ngrok.io/LEATest/");
}
});
}
private class JsonTask extends AsyncTask<String, String, String> {
protected void onPreExecute() {
super.onPreExecute();
//pd = new ProgressDialog(MainActivity.this);
//pd.setMessage("Please wait");
//pd.setCancelable(false);
//pd.show();
}
protected String doInBackground(String... params) {
HttpURLConnection connection = null;
BufferedReader reader = null;
try {
URL url = new URL(params[0]);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
InputStream stream = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(stream));
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = reader.readLine()) != null) {
buffer.append(line+"\n");
Log.d("Response: ", "> " + line); //here u ll get whole response...... :-)
}
return buffer.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();
}
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
#Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
//if (pd.isShowing()){
// pd.dismiss();
//}
Toast toast = Toast.makeText(getApplicationContext(),
"Before Try = |" + result + "|",
Toast.LENGTH_SHORT);
toast.show();
textView.setText(result);
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.internettest">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here's the result of pressing the button on the emulator(all fake username/passwords):
Execure your JsonTask as follows -
new JsonTask().execute("https://46d30cf268b0.ngrok.io/LEATest/");
As suggested by #isthemartin, when you are running you app in actual device (S8 and Note10) the traffic is getting block because HTTP connection is not allowed.
Either you can add android:usesCleartextTraffic="true" but then you app will allow non secure HTTP connections.
I tried your API URL (https://46d30cf268b0.ngrok.io/LEATest/) is responding to the request so, why don't simply use it without making a security gap in your app.
probably your actual devices are blocking http connections, so in this case you need to enable those connections, check this post
Please add this code to your AndroidManifest.xml file.
android:usesCleartextTraffic="true"
so the code can be like this :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.internettest">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I wrote that code to send data to parse.com then to receive it also but I can't even send it till now, why ?!! I don't know the main reason, I put the internet and network permission in AndroidManifest.xml the parse class in application also in AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mkadaimtwo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name="com.example.mkadaimtwo.ParseCode"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
and also put the parse class in application also in AndroidManifest.xml and that two codes of class and main Activity
ParseCode class Activity :
package com.example.mkadaimtwo;
import com.parse.Parse;
import android.app.Application;
public class ParseCode extends Application {
public void onCreate() {
Parse.initialize(this, "GIuhlGILKRd8itvCF79femTyReHM6XjVkrfLKm3X", "Fjg4tBrMgl0mY47K4kCL7hVmXhu8FmkE2on9PlXK");
}
}
the MainActivity Code :
package com.example.mkadaimtwo;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.net.ParseException;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.EditText;
import com.parse.GetCallback;
import com.parse.ParseObject;
import com.parse.ParseQuery;
public class MainActivity extends ActionBarActivity {
EditText etCompanyName,etAddress,etNumberOfEmployees,etContactNumber;
ProgressDialog pd,pd2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etCompanyName = (EditText) findViewById(R.id.etCompanyName);
etAddress = (EditText) findViewById(R.id.etAddress);
etNumberOfEmployees = (EditText) findViewById(R.id.etNumberOfEmployees);
etContactNumber = (EditText) findViewById(R.id.etContactNumber);
pd = new ProgressDialog(this);
pd.setTitle("wait");
pd.setMessage("by7aml elmafrod");
pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pd.setCancelable(true);
pd2 = new ProgressDialog(this);
pd2.setTitle("wait");
pd2.setMessage("by7aml elmafrod");
pd2.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pd2.setCancelable(true);
//here we will Load the old company data from Parse.com
ParseQuery<ParseObject> query = ParseQuery.getQuery("TestBosyApp");
query.getInBackground("ijy1qi78g8", new GetCallback<ParseObject>() {
public void done(ParseObject testBosyApp, ParseException e) {
if (e == null) {
String companyName = testBosyApp.getString("company_name");
String address = testBosyApp.getString("address");
String numberOfEmployees = testBosyApp.getString("number_of_employees");
String contactNumber = testBosyApp.getString("contact_number");
etCompanyName.setText(companyName);
etAddress.setText(address);
etNumberOfEmployees.setText(numberOfEmployees);
etContactNumber.setText(contactNumber);
pd.dismiss();
} else {
AlertDialog.Builder mDialoge = new AlertDialog.Builder(MainActivity.this);
mDialoge.setTitle("Erorr");
mDialoge.setMessage("Check el net plz :)");
mDialoge.setPositiveButton("ok", null);
mDialoge.show();
}
}
#Override
public void done(ParseObject arg0, com.parse.ParseException arg1) {
// TODO Auto-generated method stub
}
});
}
public void update (View V){
pd2.show();
//update data in Parse
ParseQuery<ParseObject> myQuery = ParseQuery.getQuery("TestBosyApp");
// Retrieve the object by id
myQuery.getInBackground("U6Gwn2tiD8", new GetCallback<ParseObject>() {
public void done(ParseObject testBosyApp, ParseException e) {
if (e == null) {
//Initials our variables
String companyName = etCompanyName.getText().toString().trim();
String address = etAddress.getText().toString().trim();
String numberOfEmployees = etNumberOfEmployees.getText().toString().trim();
String contactNumber = etContactNumber.getText().toString().trim();
//update it with new data
testBosyApp.put("company_name", companyName);
testBosyApp.put("address", address);
testBosyApp.put("number_of_employees", numberOfEmployees);
testBosyApp.put("contact_number", contactNumber);
testBosyApp.saveInBackground();
pd2.dismiss();
AlertDialog.Builder mDialoge = new AlertDialog.Builder(MainActivity.this);
mDialoge.setTitle("2shta");
mDialoge.setMessage("Keda eldata ra7t t2riban");
mDialoge.setPositiveButton("cool", null);
mDialoge.show();
}else{
pd2.dismiss();
AlertDialog.Builder mDialoge = new AlertDialog.Builder(MainActivity.this);
mDialoge.setTitle("Erorr");
mDialoge.setMessage("Check el net plz :)");
mDialoge.setPositiveButton("ok", null);
mDialoge.show();
}
}
#Override
public void done(ParseObject arg0, com.parse.ParseException arg1) {
// TODO Auto-generated method stub
}
});
}
}
so what's the problem, progress-bar is loading without end and if I give progress-bar cancellation feature then put data in fields there's nothing happen .
plus if anyone have tutorials for use android with parse.com please provide me with it.
Dude.. Sir? goto parse.com, there are tutorials.. you need to enable something i just do not remember Go to settings ->App Permissions ->Allow client class creation. Set it to ON> before you can send push from device and receive it.. also your manifest is not complete.. from what i know..
<application
android:name="com.example.mkadaimtwo.ParseCode"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
//edit started here
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
</application>
so copy and paste this manifest
I am implementing a simple application executing a background service, I am not able to start the service, following is my Manifest & Code, the service class is properly resolved ( reading resources ), inheriting from IntentService ( and implementing the req methods ) doesn't resolve the problem as-well...
Why does the Background service doesn't start?
any help will be appreciated.
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.newcomp.vagent"
android:versionCode="1"
android:versionName="1.0"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="20" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver android:name="com.newcomp.Infrastructure.BootStarter" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".CaptureService"
android:exported="true"
android:process=":captureService" >
</service>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
Service code:
package com.newcomp.vagent;
import android.app.IntentService;
import android.app.Service;
import android.content.Intent;
import android.R.*;
import android.os.IBinder;
import java.io.IOException;
import fi.iki.elonen.NanoHTTPD;
public class CaptureService extends Service {
public CaptureService() {
//super("Capture Service");
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
return Service.START_NOT_STICKY;
}
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
super.onCreate();
}
}
Activity code:
package com.newcomp.vagent;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
final String strSvcName = getResources().getString(R.string.startup_service);
//setContentView(R.layout.main);
Toast.makeText(getBaseContext(), String.format("Hello from '%s'", strSvcName), Toast.LENGTH_LONG).show();
Class cls = null;
try {
cls = getClassLoader().loadClass(strSvcName);
startService(new Intent(this, cls));// Starts the service
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
//finish();
}
}
The problem was simple, the service was actually starting but since android:process=":captureService" was specified it was starting on a separate process, one that is not connected by the debugger, either specifcally connecting to the service process, OR, omitting android:process=":captureService" resolve the problem.
I'm trying to create a global class. I want have a global variable for all my activity.
My class:
package com.example.app;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import android.app.Application;
public class Records extends Application{
private int N_livelli=30;
private int[] record = new int[N_livelli];
private String path = getApplicationContext().getFilesDir().getPath() + "/Records.txt";
public void LetturaFile()
{
File f = new File(path);
if(f.exists())
{
try
{
FileReader fileLeggi = new FileReader(path);
BufferedReader lettore = new BufferedReader(fileLeggi);
String rigaLetta;
int n=0;
while((rigaLetta=lettore.readLine())!=null)
{
record[n]=Integer.valueOf(rigaLetta);
n++;
}
lettore.close();
fileLeggi.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
{
try
{
for(int i=0;i<N_livelli;i++) record[i]=0;
f.createNewFile();
FileWriter fileScrivi = new FileWriter(path);
fileScrivi.write("");
for(int i=0;i<N_livelli;i++) fileScrivi.append(record[i]+"\n");
fileScrivi.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public int getRecord(int livello)
{
return record[livello-1];
}
}
My code on OnCreate of MainActivity:
[...]
Records records = (Records) getApplicationContext();
records.LetturaFile();
[..]
My AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app"
android:versionCode="3"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
[...]
</activity>
<activity
android:name=".SecondActivity"
[...]
</activity>
</application>
<application
android:name=".Records">
</application>
</manifest>
Eclipse error: android.app.application can not be cast to com.example.app.Records
Please help me. Thank you.
you have to specify the ful path of your class in the application tag, and not by adding another application tag with nothing else in it..
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name="com.example.app.Records" >
...
I'm developing a multiplayer game with libGDX and my problem is that the code that works on desktop. It causes a crash on android. When I start the server's thread on android, the following error occurs:
FATAL EXCEPTION: YellowServer
com.badlogic.gdx.utils.GdxRuntimeException: Cannot create a server socket at port 4444.
at com.badlogic.gdx.net.NetJavaServerSocketImpl.<init>(NetJavaServerSocketImpl.java:63)
at com.badlogic.gdx.backends.android.AndroidNet.newServerSocket(AndroidNet.java:60)
at hu.hundevelopers.yellow.net.NetServer.<init>(NetServer.java:41)
at hu.hundevelopers.yellow.YellowServer.create(YellowServer.java:32)
at hu.hundevelopers.yellow.YellowServer.run(YellowServer.java:61)
Caused by: java.net.SocketException: socket failed: EACCES (Permission denied)
at libcore.io.IoBridge.socket(IoBridge.java:583)
at java.net.PlainSocketImpl.create(PlainSocketImpl.java:201)
at java.net.PlainServerSocketImpl.create(PlainServerSocketImpl.java:38)
at java.net.ServerSocket.<init>(ServerSocket.java:59)
at com.badlogic.gdx.net.NetJavaServerSocketImpl.<init>(NetJavaServerSocketImpl.java:46)
... 4 more
Caused by: libcore.io.ErrnoException: socket failed: EACCES (Permission denied)
at libcore.io.Posix.socket(Native Method)
at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:181)
at libcore.io.IoBridge.socket(IoBridge.java:568)
... 8 more
It looks like that I forgot the permissions from the manifest xml file but they're there:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
NetServer.java:
package hu.hundevelopers.yellow.net;
import java.util.ArrayList;
import java.util.List;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Net;
import com.badlogic.gdx.net.ServerSocket;
import hu.hundevelopers.yellow.YellowServer;
import hu.hundevelopers.yellow.net.packet.Packet;
public class NetServer {
public class ListenThread extends Thread {
public NetServer net;
public ListenThread(NetServer net) {
super("ListenThread");
this.net = net;
}
#Override
public void run() {
try {
while (this.net.server.game.isHosting) {
NetServerClient client = new NetServerClient(this.net, this.net.socket.accept(this.net.server.game.socketHints));
this.net.clients.add(client);
}
} catch (Exception e) {
}
}
}
public YellowServer server;
public ServerSocket socket;
public List<NetServerClient> clients;
public NetServer(YellowServer server, int port) {
this.server = server;
this.socket = Gdx.net.newServerSocket(Net.Protocol.TCP, port, this.server.game.serverSocketHints);
this.clients = new ArrayList<NetServerClient>();
new ListenThread(this).start();
}
public void sendToAll(Packet pkt) {
for (NetServerClient client : this.clients)
client.send(pkt);
}
public void sendToAllAndDispose(Packet pkt) {
this.sendToAll(pkt);
pkt.dispose();
}
public void update() {
for (int i = 0; i < this.clients.size(); i++) {
this.clients.get(i).update();
if (!this.clients.get(i).connection) {
this.clients.get(i).dispose();
this.clients.remove(i--);
}
}
}
public void dispose() {
for(NetServerClient client : this.clients)
client.dispose();
this.socket.dispose();
}
}
Edit:
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="hu.hundevelopers.yellow.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/GdxTheme" >
<activity
android:name="hu.hundevelopers.yellow.android.AndroidLauncher"
android:label="#string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
AndroidLauncher.java:
package hu.hundevelopers.yellow.android;
import android.content.pm.PackageManager;
import android.os.Bundle;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import hu.hundevelopers.yellow.Yellow;
public class AndroidLauncher extends AndroidApplication {
#Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new Yellow(new String[]{}), config);
if(getContext().checkCallingOrSelfPermission("android.permission.INTERNET") == PackageManager.PERMISSION_GRANTED) {
Gdx.app.log("INFO", "PERMISSION GRANTED");
} else {
Gdx.app.log("ERROR", "PERMISSION DENIED");
}
}
}
I solved the problem. I changed the minimum required android version from 8 to 10 and now everything works.
The exception indicates its a permission problem. So, there may be something going amiss in your packaging or deployment steps (or the manifest isn't doing what you intend).
You can add a bit of debugging code to verify that you do not have the permission. See How permission can be checked at runtime without throwing SecurityException? That should help narrow the problem down.