How to Figure Out Which Sim Received Sms in Dual Sim Android Device

Detect which SIM card has received message

It seems that info might be in an Intent extra with the key "simSlot".

public void onReceive(Context context, Intent intent) {
...
int simSlot = intent.getIntExtra("simSlot", -1);
...
}

I couldn't find any info on this, either, in my admittedly brief search, so I'm not sure how universal this is, or in which Android version this might have been introduced. I found it by dumping all the extras on the delivered Intent in a Receiver on my device.

How to fetch SMS of only one SIM in dual SIM phone?

well this are all the Columns for Threads
I couldn't find anything related to sim though .
But there is RECIPIENT_IDS:

A string encoding of the recipient IDs of the recipients of the message, in numerical order and separated by spaces.

Which you can check it by the sim number for received messages.
also you have SMS wich contains PERSON ,ADRESS , CREATOR which you can also check them by sim number.

Get the list of user SIM cards and select it - flutter

you can try https://pub.dev/packages/mobile_number this package,

Add dependency

dependencies:
mobile_number: ^1.0.4

Code snippet

import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mobile_number/mobile_number.dart';

void main() => runApp(MyApp());

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

class _MyAppState extends State<MyApp> {
String _mobileNumber = '';
List<SimCard> _simCard = <SimCard>[];

@override
void initState() {
super.initState();
MobileNumber.listenPhonePermission((isPermissionGranted) {
if (isPermissionGranted) {
initMobileNumberState();
} else {}
});

initMobileNumberState();
}

// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initMobileNumberState() async {
if (!await MobileNumber.hasPhonePermission) {
await MobileNumber.requestPhonePermission;
return;
}
String mobileNumber = '';
// Platform messages may fail, so we use a try/catch PlatformException.
try {
mobileNumber = (await MobileNumber.mobileNumber)!;
_simCard = (await MobileNumber.getSimCards)!;
} on PlatformException catch (e) {
debugPrint("Failed to get mobile number because of '${e.message}'");
}

// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;

setState(() {
_mobileNumber = mobileNumber;
});
}

Widget fillCards() {
List<Widget> widgets = _simCard
.map((SimCard sim) => Text(
'Sim Card Number: (${sim.countryPhonePrefix}) - ${sim.number}\nCarrier Name: ${sim.carrierName}\nCountry Iso: ${sim.countryIso}\nDisplay Name: ${sim.displayName}\nSim Slot Index: ${sim.slotIndex}\n\n'))
.toList();
return Column(children: widgets);
}

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: <Widget>[
Text('Running on: $_mobileNumber\n'),
fillCards()
],
),
),
),
);
}
}

How to know SIM card or mobile number for when an outgoing SMS was sent?

There is no guaranteed solution to this problem because the phone number is not physically stored on all SIM-cards, or broadcasted from the network to the phone. This is especially true in some countries which requires physical address verification, with number assignment only happening afterwards. Phone number assignment happens on the network - and can be changed without changing the SIM card or device (e.g. this is how porting is supported). I know it is pain, but most likely the best solution is just to ask the user to enter his/her phone number once and store it.



Related Topics



Leave a reply



Submit