-
-
Notifications
You must be signed in to change notification settings - Fork 222
Description
Project Overview
The objective of this project is to develop a cross-platform mobile application using Flutter that blocks or identifies spam callers on both iOS and Android devices. The app will utilize platform-specific APIs and extensions to accomplish the spam blocking feature:
- iOS: Utilize the Call Directory Extension to block or identify spam calls.
- Android: Utilize Telephony and CallScreeningService APIs to intercept and block calls.
1. Project Structure
1.1 Flutter Project Setup
- Project Name:
SpamCallerBlocker
- Folders:
lib/
: Contains Flutter Dart code.ios/
: Contains iOS native code and Call Directory Extension.android/
: Contains Android native code for call blocking.assets/
: Contains assets like icons and UI images.test/
: Contains unit and widget tests.
2. Flutter Codebase
2.1 Flutter UI
-
Main Screen:
- Display a list of blocked numbers.
- Options to add a number manually.
- Option to import numbers from a list or an external database.
- Button to update the spam number list.
-
Flutter Packages:
provider
orriverpod
for state management.http
for API calls if needed (e.g., to retrieve a list of spam numbers from a server).flutter_local_notifications
for local notifications on Android.
2.2 Communication with Native Code
- Platform Channels:
- Use platform channels to send and receive data between Flutter and the native code (iOS & Android).
- Example: Passing the list of spam numbers from the Flutter UI to the Call Directory Extension on iOS and to the appropriate APIs on Android.
// Example Flutter to Native Channel
const platform = MethodChannel('com.example.spamcallerblocker/extension');
Future<void> updateSpamList(List<String> numbers) async {
try {
await platform.invokeMethod('updateSpamList', {"numbers": numbers});
} catch (e) {
print("Failed to update spam list: $e");
}
}
3. iOS Implementation
3.1 Call Directory Extension Setup
- Create a Call Directory Extension:
- In Xcode, add a new target for a Call Directory Extension to the existing Flutter project.
- Configure the extension to manage a list of blocked and identified numbers.
3.2 Native iOS Code
- Swift/Objective-C:
- Implement the logic to receive the list of spam numbers from Flutter via platform channels.
- Store and manage these numbers within the Call Directory Extension.
// Example Swift code to handle the platform channel in iOS
@objc class CallDirectoryHandler: NSObject, CXCallDirectoryExtensionContext {
let spamNumbers = UserDefaults.standard.array(forKey: "spamNumbers") as? [String] ?? []
func updateSpamList(with numbers: [String]) {
UserDefaults.standard.set(numbers, forKey: "spamNumbers")
}
func addSpamNumbers(to context: CXCallDirectoryExtensionContext) {
for number in spamNumbers {
if let phoneNumber = Int64(number) {
context.addBlockingEntry(withNextSequentialPhoneNumber: phoneNumber)
}
}
}
}
- Update the Call Directory:
- Periodically update the spam numbers through the Call Directory Extension using the data passed from the Flutter app.
3.3 App Group (if needed)
- App Group:
- If data sharing between the main app and the extension is necessary, consider setting up an App Group.
4. Android Implementation
4.1 Permissions
- Manifest Permissions:
- Ensure the Android app has the necessary permissions to read call logs and block calls.
- Example permissions:
READ_CALL_LOG
,ANSWER_PHONE_CALLS
,READ_PHONE_STATE
.
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
4.2 CallScreeningService
- Implement CallScreeningService:
- Create a service to intercept incoming calls and block or identify spam calls based on the list received from Flutter.
public class CallBlockerService extends CallScreeningService {
@Override
public void onScreenCall(Call.Details callDetails) {
String incomingNumber = callDetails.getHandle().getSchemeSpecificPart();
// Check if the number is in the spam list
if (isSpam(incomingNumber)) {
CallResponse.Builder responseBuilder = new CallResponse.Builder();
responseBuilder.setDisallowCall(true);
respondToCall(callDetails, responseBuilder.build());
}
}
private boolean isSpam(String phoneNumber) {
// Implement logic to check if the number is spam
return spamList.contains(phoneNumber);
}
}
4.3 TelephonyManager (for older Android versions)
- For Devices on Android Below API 29:
- Use
TelephonyManager
to monitor incoming calls and block them if necessary.
- Use
5. Testing and Deployment
5.1 Testing
- Unit Tests:
- Write unit tests for the Flutter code to ensure that the list of spam numbers is handled correctly.
- Integration Tests:
- Test the communication between Flutter and the native code on both platforms.
5.2 Deployment
- App Store & Google Play Compliance:
- Ensure that the app complies with the respective app store guidelines, especially regarding permissions and access to sensitive data.
- Beta Testing:
- Use TestFlight for iOS and Google Play's beta testing tools to gather feedback before public release.
6. Additional Features (Optional)
- Crowdsourcing Spam Numbers:
- Allow users to report spam numbers, which can be added to a shared database.
- Push Notifications:
- Notify users when a known spam number is blocked.
- Periodic Updates:
- Implement a mechanism to periodically fetch the latest spam numbers from a server.
7. Conclusion
This project document outlines the architecture and development plan for a cross-platform spam caller blocker app using Flutter. By leveraging platform-specific APIs, we can effectively block or identify spam calls on both iOS and Android, ensuring user privacy and security.
Note: This project requires proficiency in both Flutter and native iOS/Android development due to the need for platform channels and native code integration.
Metadata
Metadata
Assignees
Type
Projects
Status