Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PERMISSIONS NOT WORK #30

Closed
AhmedHussein22 opened this issue Nov 20, 2021 · 5 comments
Closed

PERMISSIONS NOT WORK #30

AhmedHussein22 opened this issue Nov 20, 2021 · 5 comments
Milestone

Comments

@AhmedHussein22
Copy link

AhmedHussein22 commented Nov 20, 2021

I faced me many problems with this package in my project, so I created new project and very time when running the app new problem appears

First Time
not aske me for PERMISSIONS and not get any data

Second Time
debug console print

D/flutter/CALL_LOG(22934): onMethodCall
E/flutter (22934): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: PlatformException(MISSING_PERMISSIONS, Permission READ_CALL_LOG or READ_PHONE_STATE is required for plugin. Hovewer, plugin is unable to request permission because of background execution., null, null)
E/flutter (22934): #0 StandardMethodCodec.decodeEnvelope
package:flutter/…/services/message_codecs.dart:597
E/flutter (22934): #1 MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:158
E/flutter (22934):
E/flutter (22934): #2 CallLog.get
package:call_log/call_log.dart:12
E/flutter (22934):
E/flutter (22934): #3 _MyAppState.build.
package:crmapp/main.dart:53
E/flutter (22934):
E/flutter (22934):

Third time
debug console print

D/flutter/CALL_LOG(22934): onMethodCall
E/flutter (22934): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: PlatformException(ALREADY_RUNNING, Method call was cancelled. One method call is already running, null, null)
E/flutter (22934): #0 StandardMethodCodec.decodeEnvelope
package:flutter/…/services/message_codecs.dart:597
E/flutter (22934): #1 MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:158
E/flutter (22934):
E/flutter (22934): #2 CallLog.get
package:call_log/call_log.dart:12
E/flutter (22934):
E/flutter (22934): #3 _MyAppState.build.
package:crmapp/main.dart:53
E/flutter (22934):
E/flutter (22934):
E/MethodChannel#sk.fourq.call_log(22934): Failed to handle method call
E/MethodChannel#sk.fourq.call_log(22934): java.lang.IllegalStateException: Reply already submitted
E/MethodChannel#sk.fourq.call_log(22934): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:155)
E/MethodChannel#sk.fourq.call_log(22934): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.error(MethodChannel.java:243)

My Code
`import 'package:call_log/call_log.dart';
import 'package:flutter/material.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatefulWidget {
@OverRide
_MyAppState createState() => _MyAppState();
}

class _MyAppState extends State {
Iterable _callLogEntries = [];

@OverRide
Widget build(BuildContext context) {
const TextStyle mono = TextStyle(fontSize: 20);
final List children = [];
for (CallLogEntry entry in _callLogEntries) {
children.add(
Column(
children: [
const Divider(),
Text('F. NUMBER : ${entry.formattedNumber}', style: mono),
Text('C.M. NUMBER: ${entry.cachedMatchedNumber}', style: mono),
Text('NUMBER : ${entry.number}', style: mono),
Text('NAME : ${entry.name}', style: mono),
Text('TYPE : ${entry.callType}', style: mono),
// Text('DATE : ${DateTime.fromMillisecondsSinceEpoch(entry.timestamp)}',
// style: mono),
Text('DURATION : ${entry.duration}', style: mono),
Text('ACCOUNT ID : ${entry.phoneAccountId}', style: mono),
Text('SIM NAME : ${entry.simDisplayName}', style: mono),
],
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
),
);
}

return MaterialApp(
  home: Scaffold(
    appBar: AppBar(title: const Text('call_log example')),
    body: SingleChildScrollView(
      child: Column(
        children: <Widget>[
          Center(
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: ElevatedButton(
                onPressed: () async {
                  final Iterable<CallLogEntry> result = await CallLog.query();
                  setState(() {
                    _callLogEntries = result;
                  });
                },
                child: const Text('Get all'),
              ),
            ),
          ),
         
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Column(children: children),
          ),
        ],
      ),
    ),
  ),
);

}
}`

AndroidManifest.xml



<application

**Flutter doctor **
C:\Users\ENG_Ahmed>flutter doctor -v
[√] Flutter (Channel stable, 2.2.1, on Microsoft Windows [Version 10.0.19042.1348], locale en-US)
• Flutter version 2.2.1 at C:\src\flutter
• Framework revision 02c026b03c (6 months ago), 2021-05-27 12:24:44 -0700
• Engine revision 0fdb562ac8
• Dart version 2.13.1

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at C:\Users\ENG_Ahmed\AppData\Local\Android\sdk
• Platform android-30, build-tools 30.0.3
• ANDROID_HOME = C:\Users\ENG_Ahmed\AppData\Local\Android\sdk
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.

[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 4.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 49.0.2
• Dart plugin version 193.7547
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.62.3)
• VS Code at C:\Users\ENG_Ahmed\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.28.0

[√] Connected device (3 available)
• CPH1803 (mobile) • 192.168.1.202:5555 • android-arm64 • Android 8.1.0 (API 27)
• Chrome (web) • chrome • web-javascript • Google Chrome 96.0.4664.45
• Edge (web) • edge • web-javascript • Microsoft Edge 95.0.1020.53

• No issues found!

@MartinHlavna
Copy link
Member

Hello,
thanks for the report. Can you try running example? At first glance I am not seeing issue with your code and it runs fine for my tests. We are using plugin in production also.

Can you possibly attach that demo project? It would speed up fix.

@MartinHlavna MartinHlavna added the waiting-for-response Further information is requested label Nov 22, 2021
@re-ynd
Copy link
Contributor

re-ynd commented Nov 29, 2021

I am having the same problem. It seems like in the following line, the code is checking if activity is null.
https://github.com/4Q-s-r-o/call_log/blob/master/android/src/main/java/sk/fourq/calllog/CallLogPlugin.java#L134

If so, it prints the error that permission cannot be requested by a background app. But the only place activity is set is in the deprecated code in the following line
https://github.com/4Q-s-r-o/call_log/blob/master/android/src/main/java/sk/fourq/calllog/CallLogPlugin.java#L116

I was able to resolve the issue by adding activity = activityPluginBinding.getActivity(); in https://github.com/4Q-s-r-o/call_log/blob/master/android/src/main/java/sk/fourq/calllog/CallLogPlugin.java#L89

and by adding activity = null; in https://github.com/4Q-s-r-o/call_log/blob/master/android/src/main/java/sk/fourq/calllog/CallLogPlugin.java#L107

Not sure if that is the intended use of activity by the author.

@MartinHlavna
Copy link
Member

@re-ynd

Hi, yes that may be the problem, thanks. Are you planning to open PR?

@MartinHlavna MartinHlavna removed the waiting-for-response Further information is requested label Dec 1, 2021
@re-ynd
Copy link
Contributor

re-ynd commented Dec 1, 2021

Hi @MartinHlavna , I have never done a PR but I will give it a try

@MartinHlavna
Copy link
Member

Fixed in 3.2.2

@MartinHlavna MartinHlavna added this to the 3.2.2 milestone Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants