0

I've added the internet permission code to my manifest but still i am getting No Network Security Config specified, using platform default in my logcat. Through my code i am trying to fetch html code from url on pressing a button, but unfortunately my app is crashing. here i am pasting my manifest code:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rekhahindwar.linksaver" >
    <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=".UrlFetcher" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

and my java class is here-

public class UrlFetcher extends AppCompatActivity implements View.OnClickListener {

EditText url;
Button fetch;
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initialize();
}

private void initialize() {
    url = (EditText) findViewById(R.id.url);
    fetch = (Button) findViewById(R.id.fetch);
    fetch.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    String baseurl = url.getText().toString();
    Document doc = null;
    try {
        doc = Jsoup.connect(baseurl).get();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
}

2 Answers2

0

Maybe your firewall is blocking the connection, disable it and try again, I also think you may need to add this to your manifest xml file since you are using jsoup to parse some html

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
DevRj
  • 448
  • 8
  • 19
  • didn't work for me.... i disabled my firewall and also added the permissions you mentioned but still getting same problem.... :( – Sia Hindwar Jul 13 '17 at 09:34
  • the permissions I recommended were just for a future use not to solve your problem. Can you please display your error log? – DevRj Jul 13 '17 at 09:43
  • D/NetworkSecurityConfig: No Network Security Config specified, using platform default 07-13 15:01:55.421 2543-2550/com.example.rekhahindwar.linksaver W/art: Suspending all threads took: 19.453ms 07-13 15:01:55.422 2543-2543/com.example.rekhahindwar.linksaver D/AndroidRuntime: Shutting down VM--------- beginning of crash 07-13 15:01:55.491 2543-2543/com.example.rekhahindwar.linksaver E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.rekhahindwar.linksaver, PID: 2543 android.os.NetworkOnMainThreadException – Sia Hindwar Jul 13 '17 at 09:52
  • hey please see my answer comment for clear view of logcat – Sia Hindwar Jul 13 '17 at 10:37
  • First of all there's no problem with the message D/NetworkSecurityConfig: No Network Security Config specified, using platform default because D/ indicates that this is a debugging message. I think you don't have any. You should call your methods in OnCreate() method. This what I think, I may be wrong – DevRj Jul 13 '17 at 11:13
0

Make a seperate asynctask class like below. and call your async class from activity using this.

new FetchURLAsyncTask().execute();



public class FetchURLAsyncTask extends AsyncTask<Void, Void, Void> {
    @Override
    protected Void doInBackground(Void... params) {
        StringBuffer buffer = new StringBuffer();
        try {
            Document doc = Jsoup.connect("https://www.google.co.in").get();
            String title = doc.title();
            System.out.println("Url !!!! " + title);
        }
        catch(Throwable t) {
            t.printStackTrace();
        }
        return null;
    }
}
rohitraj
  • 46
  • 4