Baseflow / flutter-permission-handler

Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.
https://baseflow.com
MIT License
2.05k stars 857 forks source link

Not Asking for Permissions even after app uninstalls and Flutter Clean. #141

Closed Sheharyar566 closed 3 years ago

Sheharyar566 commented 5 years ago

🔙 Regression

I am trying to make use of the Permission Handler plugin to develop an application which asks for location permissions. And I am testing my app on a physical device. Oh, and I am focusing mostly on android side of flutter.

Old (and correct) behavior

At the very first try (I mean, when I installed plugin and implemented it), it asked for a permission about making use of WiFi and GPS to get an accurate estimate of the location, which I agreed. Oh, and this permission dialog showed up when I made use of check permission status function (and not the request permission function). But still, I agreed.

Current behavior

And now that I added the request permission function, it isn't showing any dialog. To get rid of the problem, I uninstalled the app, cleared cache, cleared data and used Flutter clean, but to no avail.

Reproduction steps

Here's the code:

import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

var textColor = Color.fromRGBO(19, 14, 83, 1);
var lightColor = Color.fromRGBO(195, 195, 195, 1);
var mainColor = Color.fromRGBO(255, 197, 36, 1);

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  PermissionStatus _status;
  bool checked = false;

  @override
  void initState() {
    super.initState();

    if(checked == false) {
      PermissionHandler().checkPermissionStatus(PermissionGroup.location).then((status) {
        if(status != _status) {
          setState(() {
            _status = status;
            checked = true;
          });
        }
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          children: <Widget>[
            Text(
              _status.toString(),
            ),
            OutlineButton(onPressed: () {
              PermissionHandler().requestPermissions([PermissionGroup.location]).then(
                  (Map<PermissionGroup, PermissionStatus> statuses) {
                    PermissionStatus status = statuses[PermissionStatus];
                    if(status != _status) {
                      setState(() {
                        _status = status;
                      });
                    }
                  }
              );
            }),
          ],
        ),
      ),
    );
  }
}

Configuration

And here's my "MAIN" Android Manifest file:

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

    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->

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

    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="weatherly"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

and the Debug Manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.technoscans.weatherly">
    <!-- Flutter needs it to communicate with the running application
         to allow setting breakpoints, to provide hot reload, etc.
    -->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

</manifest>

and the build.gradle (inside src folder):

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.technoscans.weatherly"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
aksappy commented 5 years ago

+1

saravananmnm commented 4 years ago

Same issue here.

D:\MyProjects\iex_driver>flutter doctor -v [√] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 10.0.18362.778], locale en-IN) • Flutter version 1.12.13+hotfix.9 at C:\Saravanan\Flutter_Sdk\flutter • Framework revision f139b11009 (4 weeks ago), 2020-03-30 13:57:30 -0700 • Engine revision af51afceb8 • Dart version 2.7.2

smasinde commented 4 years ago

Has anyone resolved this?

omkartralsawala commented 4 years ago

Facing a similar issue The app wont ask the user for permissions it works fine in debug mode

pohpas commented 4 years ago

I have the same issue. When running the app in debug mode (via flutter run in console) everything works fine and the requests pop up. However in release mode, nothing shows. Any solution yet?

danielroek commented 4 years ago

Does the app already have permissions?

Check "Settings -> Privacy -> " on iOS, or "Settings -> Apps & Notifications -> Permission Manager -> Location" on Android 10.

If not, please update your Flutter version and use the latest version of permission_handler and provide us with flutter doctor -v and a sample of the code that is triggering the issue

gagan722 commented 3 years ago

same issue

thecaptainXgod commented 3 years ago

The same issue, is there any solution yet? The permission handler asks for permissions in debug mode but in release mode, it just says the permission was denied.

rsommerard commented 3 years ago

Same issue on my side, app has no permissions granted and doesn't ask for it. Even if I add manually permissions, the app doesn't work for all that

Sheharyar566 commented 3 years ago

Does the app already have permissions?

Check "Settings -> Privacy -> " on iOS, or "Settings -> Apps & Notifications -> Permission Manager -> Location" on Android 10.

If not, please update your Flutter version and use the latest version of permission_handler and provide us with flutter doctor -v and a sample of the code that is triggering the issue

Sorry @danielroek , I haven't used the flutter-permission-handler for a while (and still am not using it, since my job required me to switch to ReactJS :) ).

@gagan722 @thecaptainXgod @rsommerard if possible, can you please provide the details to @danielroek

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

thecaptainXgod commented 3 years ago

Hi guys, so I don't know if you made the dumbest mistake like me. I fixed the issue by adding these lines to AndroidManifest.xml in the main folder.

<uses-permission android:name="android.permission.READ_CONTACTS"/>
 <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
 <uses-permission android:name="android.permission.GET_ACCOUNTS"/>

The problem was I added these in debug & profile folders in the AndroidManifest.xml file but not in the main that is why can't use it when the app was build in release mode.

Also, I have attached the screenshot for the same.

Screenshot 2021-03-15 at 6 26 07 PM

Steps:

  1. Go to : android > app > src > main > AndroidManifest.xml
  2. Add these lines to your file.

Hope this helps you too :)

no-response[bot] commented 3 years ago

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

joleth08 commented 3 years ago

Hi, I have the same issue. when this line is running PermissionStatus permission = await Permission.contacts.status; this error appear and exit my app. image my AndroidManifest.xml have this line: image

DiriectorDoc commented 2 years ago

The <uses-permission> worked for me.

Press and hold the app icon and open its setting. Then manually allow the permission. After I added the <uses-permission> tag, that's what I had to do.