简体   繁体   English

Android App Permission Internet 在 Manifest 中设置但不起作用

[英]Android App Permission Internet set in Manifest but not work

i need the permission Internet in my Android App.我需要在我的 Android 应用程序中获得 Internet 许可。

Here my Manifest-File:这是我的清单文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="de.medshoppro">

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

    <application
        android:name=".application.GlobalDataStore"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:networkSecurityConfig="@xml/network_security_config"
        android:theme="@style/AppTheme">

        <activity android:name=".activities.Test"></activity>

        <activity
            android:name=".activities.MedShopPro"
            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>
</manifest>

But if i start my App on my Phone (Pixel 4 XL) i can´t use the Internet.但是,如果我在手机(Pixel 4 XL)上启动我的应用程序,我就无法使用互联网。 And i can´t give my App the permission over App-Details->Permissions.而且我无法通过 App-Details->Permissions 授予我的应用程序权限。

What is missing or wrong?有什么遗漏或错误?

Your question is not clear.你的问题不清楚。 Maybe this is what you are asking.也许这就是你要问的。

If your phone using an api greater than 23 or 23, then you need to check for permission at runtime.如果您的手机使用大于 23 或 23 的 api,则需要在运行时检查权限。

Android-M ie, API 23 introduced Runtime Permissions for reducing security flaws in android device, where users can now directly manage app permissions at runtime.so if the user denies a particular permission of your application you have to obtain it by asking the permission dialog that you mentioned in your query. Android-M 即 API 23 引入了运行时权限以减少 android 设备中的安全漏洞,用户现在可以在运行时直接管理应用程序权限。所以如果用户拒绝您的应用程序的特定权限,您必须通过询问权限对话框来获取它您在查询中提到的。

So check before action ie, check you have permission to access the resource link and if your application doesn't have that particular permission you can request the permission link and handle the the permissions request response like below.因此,在操作之前检查,即检查您是否有权访问资源链接,如果您的应用程序没有该特定权限,您可以请求权限链接并处理权限请求响应,如下所示。

@Override
public void onRequestPermissionsResult(int requestCode,
        String permissions[], int[] grantResults) {
    switch (requestCode) {
        case MY_PERMISSIONS_REQUEST_READ_CONTACTS: {
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0
                && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                // permission was granted, yay! Do the
                // contacts-related task you need to do.

               } else {

                // permission denied, boo! Disable the
                // functionality that depends on this permission.
            }
            return;
        }

        // other 'case' lines to check for other
        // permissions this app might request
    }
}

Another sample code is here.另一个示例代码在这里。

if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
    if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) context, Manifest.permission.WRITE_CALENDAR)) {
        AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context);
        alertBuilder.setCancelable(true);
        alertBuilder.setMessage("Write calendar permission is necessary to write event!!!");
        alertBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
            @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
            public void onClick(DialogInterface dialog, int which) {
                ActivityCompat.requestPermissions((Activity)context, new String[]{Manifest.permission.WRITE_CALENDAR}, MY_PERMISSIONS_REQUEST_WRITE_CALENDAR);
            }
        });
    } else {
        ActivityCompat.requestPermissions((Activity)context, new String[]{Manifest.permission.WRITE_CALENDAR}, MY_PERMISSIONS_REQUEST_WRITE_CALENDAR);
    }
}

So finally, It's a good practice to go through behavior changes if you are planning to work with new versions to avoid force closes:)所以最后,如果您打算使用新版本以避免强制关闭,那么通过行为更改对 go 是一个很好的做法:)

Permissions Best Practices . 权限最佳实践

You can go through the official sample app here .您可以通过此处的官方示例应用程序 go 。

I have found my mistake.我发现了我的错误。 I used httpclient but in version O and P i have to use HttpsURLConnection .我使用了httpclient但在版本 O 和 P 中我必须使用HttpsURLConnection

Internet permission not working in oreo and pie 互联网许可在奥利奥和派中不起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 正确清单时,Android Internet权限无法正常工作 - Android Internet Permission not working while correct manifest 未授予Android应用中的互联网权限 - Internet permission in Android app not granted Android App中的互联网权限问题? - Internet Permission issue in Android App? 清单中的权限在 Android 6 中不起作用 - Permission from manifest doesn't work in Android 6 Android Studio权限例外,尽管在清单中设置 - Android studio permission exception although set in manifest java.lang.SecurityException:权限被拒绝(缺少INTERNET权限?),即使在android清单中添加了此权限 - java.lang.SecurityException: Permission denied (missing INTERNET permission?) even with adding this permission in android manifest 包含 <uses-permission android:name=“android.permission.INTERNET” /> 在清单中导致错误 - including <uses-permission android:name=“android.permission.INTERNET” /> in manifest causes error 行动网站上的android.permission.INTERNET(非应用程式) - android.permission.INTERNET on mobile site (not app) 权限被拒绝,但权限已在清单中设置 - Permission Denied but permission is set in manifest 如何在清单中未经许可但在应用中询问的情况下在android应用中获取位置 - how to get location in android app without permission in manifest but with asking in app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM