所以,在过去的两天里,我在尝试连接时遇到了这个错误。
尝试UDP,TCP和Httprequest / Httppost。
我们尝试在两台设备上使用APK
尝试时使用WIFI,我们添加了3个权限,即使据我所知,我只需要互联网权限。添加权限而不是错误。
<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)
编辑:我还添加了“android:sharedUserId =”android.uid.system“”,这是完全相同的错误......仍然......
编辑:在此处添加清单:
<?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>
编辑:更改后的清单:
<?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>
编辑:MainActivity更新:
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);
}
}
答案 0 :(得分:0)
兄弟似乎对您的清单文件有疑问 将您的许可放在应用程序标记之上,如果问题仍然存在,请告诉我
[编辑]
<uses-permission android:name="android.permissions.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permissions.CHANGE_WIFI_STATE" />
更改权限权限并运行代码
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />