Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
这需要android.permission.interaction\u跨\u用户\u无理由完全交互_Android_Http_Permissions - Fatal编程技术网

这需要android.permission.interaction\u跨\u用户\u无理由完全交互

这需要android.permission.interaction\u跨\u用户\u无理由完全交互,android,http,permissions,Android,Http,Permissions,好的,我得到这个错误是没有原因的。因为我的应用程序启动了,一切正常。 但是当它想要发送HTTP请求时,它会崩溃,logcat会显示这个错误 我只在真实的设备上得到这个错误,它在模拟器中工作得很好 我的应用程序实际上不需要这样的权限。很简单。 我知道我在代码中做错了什么,这与这些权限无关。 但我不知道我哪里做错了 这是我的舱单: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schem

好的,我得到这个错误是没有原因的。因为我的应用程序启动了,一切正常。 但是当它想要发送HTTP请求时,它会崩溃,logcat会显示这个错误

我只在真实的设备上得到这个错误,它在模拟器中工作得很好

我的应用程序实际上不需要这样的权限。很简单。 我知道我在代码中做错了什么,这与这些权限无关。 但我不知道我哪里做错了

这是我的舱单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ir.Ava.android"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="5"
        android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.READ_CONTACTS"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>


    <application
        android:allowBackup="false"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.Avatheme" 
        android:uiOptions="splitActionBarWhenNarrow" android:supportsRtl="true">
        <!-- Splash screen -->
        <activity
            android:name="ir.Ava.android.SplashScreen"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Black.NoTitleBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <!-- Main activity -->
        <activity
            android:name="ir.Ava.android.MainActivity"
            android:label="@string/app_name" >
        </activity>
        <activity android:name="ir.Ava.android.Bubble"></activity>
    </application>

</manifest>

这是导致问题的片段:

inside MainActivity.java

public static class profileSectionFragment extends Fragment {

    TextView testText;
    // flag for Internet connection status
    Boolean isInternetPresent = false;
    Button editPFButton;
    // Connection detector class
    ConnectionDetector cd;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.profile, container, false);
        ((TextView) rootView.findViewById(R.id.pf_username)).setText("Name of the user");
        testText = (TextView) rootView.findViewById(R.id.testText);

        // Buttons
        editPFButton = (Button) rootView.findViewById(R.id.edit_profile);

        editPFButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {

                Context appContext = getActivity().getApplicationContext();

                // creating connection detector class instance
                cd = new ConnectionDetector(appContext);

                // get Internet status
                isInternetPresent = cd.isConnectingToInternet();



                // check for Internet status
                if (isInternetPresent) {
                    testText.setText("successfully connected to the internet");
                } else {
                    testText.setText("there is no internet connection");
                }


                // Creating HTTP client
                HttpClient httpClient = new DefaultHttpClient();
                // Creating HTTP Post
                HttpPost httpPost = new HttpPost(
                        "http://192.168.1.2/android/");

                // Building post parameters
                // key and value pair
                List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
                nameValuePair.add(new BasicNameValuePair("email", "user@gmail.com"));
                nameValuePair.add(new BasicNameValuePair("message",
                        "Hi, trying Android HTTP post!"));

                // Url Encoding the POST parameters
                try {
                    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
                } catch (UnsupportedEncodingException e) {
                    // writing error to Log
                    e.printStackTrace();
                }

                // Making HTTP Request
                try {
                    HttpResponse response = httpClient.execute(httpPost);
                    Log.d("HTTP Response:", response.toString());

                     if (response.getStatusLine().getStatusCode() == 200)
                     {
                         HttpEntity entity = response.getEntity();
                         testText.setText(EntityUtils.toString(entity));
                     }
                     else
                     {
                         testText.setText("Error: "+response.getStatusLine().getStatusCode());
                     }

                } catch (ClientProtocolException e) {
                    // writing exception to log
                    e.printStackTrace();
                } catch (IOException e) {
                    // writing exception to log
                    e.printStackTrace();

                }

            }
        });


        return rootView;
    }

}
MainActivity.java内部的

公共静态类profileSectionFragment扩展了片段{
文本视图测试文本;
//Internet连接状态的标志
布尔值isInternetPresent=false;
按钮编辑按钮;
//连接检测器类
连接检测器cd;
@凌驾
CreateView上的公共视图(布局、充气机、视图组容器、捆绑包保存状态){
视图根视图=充气机充气(R.layout.profile,容器,假);
((TextView)rootView.findviewbyd(R.id.pf_username)).setText(“用户名称”);
testText=(TextView)rootView.findviewbyd(R.id.testText);
//钮扣
editPFButton=(按钮)rootView.findviewbyd(R.id.edit_profile);
editPFButton.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
上下文appContext=getActivity().getApplicationContext();
//创建连接检测器类实例
cd=新连接检测器(appContext);
//获取Internet状态
isInternetPresent=cd.isConnectingToInternet();
//检查互联网状态
如果(isInternetPresent){
setText(“成功连接到internet”);
}否则{
setText(“没有互联网连接”);
}
//创建HTTP客户端
HttpClient HttpClient=新的DefaultHttpClient();
//创建HTTP Post
HttpPost HttpPost=新的HttpPost(
"http://192.168.1.2/android/");
//建筑柱参数
//键和值对
List nameValuePair=新的ArrayList(2);
添加(新的BasicNameValuePair(“电子邮件”)user@gmail.com"));
添加(新的BasicNameValuePair(“消息”),
“嗨,正在尝试Android HTTP post!”);
//对POST参数进行Url编码
试一试{
setEntity(新的UrlEncodedFormEntity(nameValuePair));
}捕获(不支持的编码异常e){
//将错误写入日志
e、 printStackTrace();
}
//发出HTTP请求
试一试{
HttpResponse response=httpClient.execute(httpPost);
Log.d(“HTTP响应:,Response.toString());
if(response.getStatusLine().getStatusCode()==200)
{
HttpEntity=response.getEntity();
setText(EntityUtils.toString(entity));
}
其他的
{
setText(“错误:+response.getStatusLine().getStatusCode());
}
}捕获(客户端协议例外e){
//将异常写入日志
e、 printStackTrace();
}捕获(IOE异常){
//将异常写入日志
e、 printStackTrace();
}
}
});
返回rootView;
}
}

不允许在主(UI)线程上执行网络I/O。您应该使用
AsyncTask
。例如:

final TextView testText = ...

AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>()
{
    @Override
    protected String doInBackground(Void... params)
    {
        ... Create HTTP client, and everything as before ...

        // Making HTTP Request
        HttpResponse response = httpClient.execute(httpPost);
        Log.d("HTTP Response:", response.toString());

        if (response.getStatusLine().getStatusCode() == 200)
        {
            HttpEntity entity = response.getEntity();
            return EntityUtils.toString(entity);
        }
        else
        {
            return "Error: "+response.getStatusLine().getStatusCode();
        }
    }

    @Override
    protected void onPostExecute(String result)
    {
        testText.setText(result);
    }
};

task.execute();
final TextView testText=。。。
AsyncTask任务=新建AsyncTask()
{
@凌驾
受保护字符串doInBackground(无效…参数)
{
…创建HTTP客户端,一切照旧。。。
//发出HTTP请求
HttpResponse response=httpClient.execute(httpPost);
Log.d(“HTTP响应:,Response.toString());
if(response.getStatusLine().getStatusCode()==200)
{
HttpEntity=response.getEntity();
返回EntityUtils.toString(实体);
}
其他的
{
return“Error:+response.getStatusLine().getStatusCode();
}
}
@凌驾
受保护的void onPostExecute(字符串结果)
{
setText(结果);
}
};
task.execute();

您能发布准确的错误消息吗?非常感谢!最后知道某事的人