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

error, Attempt to invoke virtual method 'int android.app.Activity.checkSelfPermission(java.lang.String)' on a null object reference, null #11

Closed
santoshakil opened this issue Jul 23, 2020 · 5 comments
Labels
bug Something isn't working

Comments

@santoshakil
Copy link

I'm able to get CallLog in Foreground with the call_log pub package. But I need to get Call Log in Background.

Here is some neccesery part of my code:

void main() {
  runApp(MaterialApp(
    home: Home(),
  ));

  Workmanager.initialize(callbackDispatcher, isInDebugMode: true);
  Workmanager.registerPeriodicTask("1", "simplePeriodicTask",
      existingWorkPolicy: ExistingWorkPolicy.replace,
      frequency: Duration(minutes: 15),
      initialDelay:
          Duration(seconds: 5),
      constraints: Constraints(
        networkType: NetworkType.connected,
      ));
}

void callbackDispatcher() {
  Workmanager.executeTask((task, inputData) async{
    await _HomeState().callLogDbManager();
    print('Background Services are Working!');
    return Future.value(true);
  });
}

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

class _HomeState extends State<Home> {
  Future<void> callLogDbManager() async {
    Iterable<CallLogEntry> cLog = await CallLog.get();
    int rowCount = await DatabaseHelper.instance.queryRowCount();
    int clLength = cLog.length;
    if (rowCount >= clLength) {
      callLogDbUpdate();
    } else {
      await callLogDbInsert();
      callLogDbUpdate();
    }
  }
  .......
  .......
}

And this is the Error during getting call log in Background:

Screenshot_20200722_233905

error, Attempt to invoke virtual method 'int android.app.Activity.checkSelfPermission(java.lang.String)' on a null object reference, null

@l0rd0fsecrets
Copy link

I still have the same problem

@hesty
Copy link

hesty commented Jan 29, 2021

I have the same problem

@adsizmusa
Copy link

I still have the this problem. I want to run on background

@hesty
Copy link

hesty commented Jan 31, 2021

I still have the this problem. I want to run on background

I found the solution.

first step - delete call_log and work manager

second step
install https://pub.dev/packages/flutter_background_service
install https://pub.dev/packages/pit_sms_call_log

enjoy 💯

@MartinHlavna MartinHlavna added the bug Something isn't working label Feb 4, 2021
@MartinHlavna
Copy link
Member

Background execution support added in 2.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants