telephony_kit 0.8.0
telephony_kit: ^0.8.0 copied to clipboard
Phone calls, dialer role, in-call control, SIM, network and call log APIs for Flutter on Android, using JNI bindings generated by jnigen. No method channels.
telephony_kit examples #
The full example in lib/main.dart is a working dialer with
a keypad, recent calls, contacts, device info, call blocking, messages and an
in-call screen. Run it with flutter run on an Android phone or emulator and
tap Set default to make it the phone app.
Place a call and read the device #
import 'package:telephony_kit/telephony_kit.dart';
final telephony = TelephonyKit.instance;
void callSupport() {
if (telephony.hasPermission(TelephonyPermission.callPhone)) {
telephony.placeCall('+201001234567');
} else {
telephony.openDialer('+201001234567'); // no permission needed
}
final info = telephony.getNetworkInfo();
print('${info.networkOperatorName} ${telephony.networkGeneration.label}');
}
Show your own in-call screen #
// After requestDefaultDialer() and declaring TelephonyKitInCallService.
telephony.callEvents.listen((event) {
final live = telephony.calls.where((c) => c.state.isLive).toList();
if (live.isEmpty) return closeInCallScreen();
final call = live.firstWhere(
(c) => c.state == CallState.ringing,
orElse: () => live.last,
);
showInCallScreen(call); // call.answer(), call.hangUp(), call.hold() ...
});
Block calls, even when the app is closed #
final rules = telephony.screening;
rules.blockNumber('+201001234567');
rules.blockPrefix('0900');
rules.unknownCallerAction = ScreeningAction.silence;
Search #
final missed = telephony.searchCallLog(types: {CallLogType.missed}, limit: 20);
final people = telephony.searchContacts('ahmed');
final balance = await telephony.sendUssd('*100#');
