Android frustrating network error

2019-08-12 06:42发布

So, for the past two days straight, I get this error while trying to connect.

Tried UDP,TCP and Httprequest/Httppost.

We tried using the APK on two devices

Used WIFI while trying and we have 3 permissions added ,even though as far as I knew,I only need the internet permission.Adding the permissions and than the error.

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


05-21 06:21:28.809: E/DatabaseUtils(2347): Writing exception to parcel
05-21 06:21:28.809: E/DatabaseUtils(2347): java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
05-21 06:21:28.809: E/DatabaseUtils(2347):  at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:13140)
05-21 06:21:28.809: E/DatabaseUtils(2347):  at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2038)
05-21 06:21:28.809: E/DatabaseUtils(2347):  at com.android.providers.settings.SettingsProvider.callFromPackage(SettingsProvider.java:607)
05-21 06:21:28.809: E/DatabaseUtils(2347):  at android.content.ContentProvider$Transport.call(ContentProvider.java:279)
05-21 06:21:28.809: E/DatabaseUtils(2347):  at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:273)
05-21 06:21:28.809: E/DatabaseUtils(2347):  at android.os.Binder.execTransact(Binder.java:388)
05-21 06:21:28.809: E/DatabaseUtils(2347):  at dalvik.system.NativeStart.run(Native Method)

EDIT: I also added " android:sharedUserId="android.uid.system" "and it's exactly the same error...still...

EDIT: Adding the manifest here:

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:sharedUserId="android.uid.system">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />



    <uses-permission android:name="android.permissions.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permissions.CHANGE_WIFI_STATE" />

    <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>

EDit: Manifest after the changes:

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-permission android:name="android.permissions.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permissions.CHANGE_WIFI_STATE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:sharedUserId="android.uid.system">



    <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>

EDIT: MainActivity update:

public class MainActivity extends Activity {

LinearLayout rl;
Button btn;
private TextView ErrorHandler;
private HttpPost httppost;
StringBuffer buffer;
HttpResponse response;
HttpClient httpclient;
List<NameValuePair> nameValuePairs;
TextView et,pass;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    rl = (LinearLayout) findViewById(R.id.rl);

    et = new TextView(this);
    pass = new TextView(this);
    et.setVisibility(View.VISIBLE);
    pass.setVisibility(View.VISIBLE);

    et.setText("aici");
    pass.setText("aici");

    btn = new Button(this);
    btn.setVisibility(View.VISIBLE);
    btn.setText("Apasa!");

    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        login();

           /* try {
                OpenHttpConnection("http://78.97.183.34/srv.php");
            } catch (IOException e) {
                e.printStackTrace();
            }*/
        }
    });


    rl.addView(et);
    rl.addView(pass);
    rl.addView(btn);

}



private int login() {

    int resp = 1;

    try {

        httpclient = new DefaultHttpClient();
        httppost = new HttpPost("http://xx.xx.xx.xx/srv.php");

        nameValuePairs = new ArrayList<NameValuePair>(2);

        nameValuePairs.add(new BasicNameValuePair("username", et
                .getText().toString().trim()));
        nameValuePairs.add(new BasicNameValuePair("password", pass
                .getText().toString().trim()));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        response = httpclient.execute(httppost);

        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        final String response = httpclient.execute(httppost,
                responseHandler);

        if (response.equalsIgnoreCase("User Found")) {

            et.setText("MERGE");
            pass.setText("MERGE");


        } else if (response.equalsIgnoreCase("No Such User Found")) {

            resp = 0;

        }

    } catch (Exception e) {
        System.out.println("Exception : " + e.getMessage());
    }

    return resp;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

1条回答
Viruses.
2楼-- · 2019-08-12 07:17

Brother seems to be problem with your manifest file Put your permission above application tag and let me know if problem still persist

[EDIT]

 <uses-permission android:name="android.permissions.ACCESS_WIFI_STATE" />
 <uses-permission android:name="android.permissions.CHANGE_WIFI_STATE" />

change permissions to permission and run your code once

 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
 <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
查看更多
登录 后发表回答