用户 10063 和当前进程都没有 android.permission.ACCESS_NETWORK_STATE

Neither user 10063 nor current process has android.permission.ACCESS_NETWORK_STATE

我正在开发一个地震报告应用程序,我已经为 INTERNET 和 ACCESS_NETWORK_STATE 添加了对清单文件的权限。我进入了模拟器的设置和开发人员的设置,并确保所有网络设置都已正确设置。我在这里研究了这个问题并尝试了那些对我不起作用的建议。由于防火墙,我还看到其他人在哪里遇到这个问题。我是 运行 Norton,但是他们的修复说明让我头疼。关于在 Android Studio 中设置代理 - 从命令行或从“设置”>“HTTP 代理”对话框。在那里,我选择了 "Auto-detect proxy settings"。如果我手动配置代理设置,我将不知道输入什么信息。如果有人对我如何解决这个问题有任何建议(我做了清理和重建,这是这个问题的第二天)请分享!

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

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

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

    <activity android:name=".EarthquakeActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
 App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information. -->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
</application>

public class EarthquakeActivity extends AppCompatActivity
    implements LoaderManager.LoaderCallbacks<List<Earthquake>> {

private static final String LOG_TAG = EarthquakeActivity.class.getName();

/** URL for earthquake data from the USGS dataset */
private static final String USGS_REQUEST_URL =
        "http://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&orderby=time&minmag=6&limit=10";

private static final int EARTHQUAKE_LOADER_ID = 1;

/** Adapter for the list of earthquakes */
private EarthquakeAdapter mAdapter;

/** TextView that is displayed when the list is empty */
private TextView mEmptyStateTextView;

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

    // Find a reference to the {@link ListView} in the layout
    ListView earthquakeListView = (ListView) findViewById(R.id.list);

    mEmptyStateTextView = (TextView) findViewById(R.id.empty_view);
    earthquakeListView.setEmptyView(mEmptyStateTextView);

    // Create a new adapter that takes an empty list of earthquakes as input
    mAdapter = new EarthquakeAdapter(this, new ArrayList<Earthquake>());

    // Set the adapter on the {@link ListView}
    // so the list can be populated in the user interface
    earthquakeListView.setAdapter(mAdapter);

    // Set an item click listener on the ListView, which sends an intent to a web browser
    // to open a website with more information about the selected earthquake.
    earthquakeListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // Find the current earthquake that was clicked on
            Earthquake currentEarthquake = mAdapter.getItem(position);

            // Convert the String URL into a URI object (to pass into the Intent constructor)
            Uri earthquakeUri = Uri.parse(currentEarthquake.getUrl());

            // Create a new intent to view the earthquake URI
            Intent websiteIntent = new Intent(Intent.ACTION_VIEW, earthquakeUri);

            // Send the intent to launch a new activity
            startActivity(websiteIntent);
        }
    });



    // Get a reference to the ConnectivityManager to check state of network connectivity
    ConnectivityManager connMgr = (ConnectivityManager)
            getSystemService(Context.CONNECTIVITY_SERVICE);

    // Get details on the currently active default data network
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

    // If there is a network connection, fetch data
    if (networkInfo != null && networkInfo.isConnected()) {
        // Get a reference to the LoaderManager, in order to interact with loaders.
        LoaderManager loaderManager = getLoaderManager();

        // Initialize the loader. Pass in the int ID constant defined above and pass in null for
        // the bundle. Pass in this activity for the LoaderCallbacks parameter (which is valid
        // because this activity implements the LoaderCallbacks interface).
        loaderManager.initLoader(EARTHQUAKE_LOADER_ID, null, this);
    } else {
        // Otherwise, display error
        // First, hide loading indicator so error message will be visible
        View loadingIndicator = findViewById(R.id.loading_indicator);
        loadingIndicator.setVisibility(View.GONE);

        // Update empty state with no connection error message
        mEmptyStateTextView.setText(R.string.no_internet_connection);
    }
}

@Override
public Loader<List<Earthquake>> onCreateLoader(int i, Bundle bundle) {
    // Create a new loader for the given URL
    return new EarthquakeLoader(this, USGS_REQUEST_URL);
}

@Override
public void onLoadFinished(Loader<List<Earthquake>> loader, List<Earthquake> earthquakes) {
    // Hide loading indicator because the data has been loaded
    View loadingIndicator = findViewById(R.id.loading_indicator);
    loadingIndicator.setVisibility(View.GONE);

    // Set empty state text to display "No earthquakes found."
    mEmptyStateTextView.setText(R.string.no_earthquakes);

    // Clear the adapter of previous earthquake data
    mAdapter.clear();

    // If there is a valid list of {@link Earthquake}s, then add them to the adapter's
    // data set. This will trigger the ListView to update.
    if (earthquakes != null && !earthquakes.isEmpty()) {
        mAdapter.addAll(earthquakes);
    }
}

@Override
public void onLoaderReset(Loader<List<Earthquake>> loader) {
    // Loader reset, so we can clear out our existing data.
    mAdapter.clear();
}

}

这意味着您的清单文件中有一些错误信息或格式错误的信息,这就是您的 none 权限未被您的应用识别的原因。只需确保您已清除包含任何格式错误数据的 ANDROIDMANIFEST 文件。

它会起作用,所有权限都应该在应用程序标签之外

将 uses-permission outside application 移动到 manifest 标签下方

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

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

同上