listen_call 0.0.2+2 listen_call: ^0.0.2+2 copied to clipboard
support background listen call phone event in android
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:listen_call/listen_call.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
/// callback function
int a = 0;
Future onPhoneCall(e) async {
print(["onPhoneCall", e, a++]);
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
/// requestPhonePermission
ListenCall.requestPhonePermission;
/// init
ListenCall.initBackgroundCall(onPhoneCall);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: const Center(
child: Text('Hello World'),
),
),
);
}
}