INB4: How to find target sim for an incoming call in dual sim android phone? <- does not work, sadly :(
So, I have a phone (A) with to SIM cards:
SIM 1 number: 123
SIM 2 number: 456
and I call from different phone (B: number 789) to 123.
On phone A I'm able to detect incoming call and I'm able to get the incoming phone call number (789). What I can't do is detect that the call target was SIM 1 number: 123.
Can someone help me?
Ok, I've finally manage to do this, but not directly.
I'm getting all information I need from call history.
Try this:
public class MyCallReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String mySim = "";
mySim = intent.getExtras().getInt("simId", -1);
if(callingSIM == "0"){
//SIM1
}
else if(callingSIM =="1"){
//SIM2
}
}
}
Related
I am trying to do something along the lines of signal strength triangulation using cell towers, on android. I'm using android studio and java. I've found useful csv with cell tower latitude and longitude, and written some fairly trivial code to parse it, all I need now is the cell towers' mcc, mnc, lac and cell id, so I can search the csv and find the lat and long. I'm using the telephonyManager class and .getAllCellInfo(), like so:
tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
InputStream inputStream = getResources().openRawResource(R.raw.cells);
CsvFile csvFile = new CsvFile(inputStream);
List<String[]> res = csvFile.read();
List<CellInfo> cellsTemp = tel.getAllCellInfo();
for (CellInfo ci : cellsTemp) {
if (ci instanceof CellInfoLte) {
Log.d("Cells: ", ((CellInfoLte) ci).getCellIdentity().toString());
this.cellsLte.add((CellInfoLte) ci);
this.towers.add(new cellTower((CellInfoLte) ci, res));
}
}
However, when I log the cellIdentity of those cells, I get this:
CellIdentityLte:{ mCi=2147483647 mPci=313 mTac=2147483647 mEarfcn=1300 mBandwidth=2147483647 mMcc=null mMnc=null mAlphaLong= mAlphaShort=}
As you can see, the mcc and mnc are null, and the the cell id and location code are 2147483647, or Integer.MAX_VALUE, which as I understand it, is used when they are for whatever reason unavailable.
I have the ACCESS_FINE_LOCATION and READ_PHONE_STATE runtime permissions, and I've added them to the manifest file as well. I've also tried just logging the objects directly from tel.getAllCellInfo(), same exact result.
This is the declaration for tel and towers:
public class MainActivity extends AppCompatActivity {
protected RequestQueue requestQueue;
protected TelephonyManager tel;
protected List<CellInfoLte> cellsLte = new ArrayList<CellInfoLte>();
protected List<cellTower> towers = new ArrayList<cellTower>();
And cellTower is just a sort of wrapper class that contains some information I'm going to need to calculate distance later. It also contains the cellInfo of the tower.
I am also aware that there are apis that can do this whole thing automatically, but I need to do this myself, as a sort of a proof of concept.
I'm running this on a LGE LG-H870, but I've also tried it on a Xiaomi Redmi 8, and had the same issue.
I am an (almost)complete beginner with android studio, but I think I have a perfectly decent understanding of java. Is there any way at all to get around this? Any help would be greatly appreciated.
How do I test if my Bluetooth Headset is connected to my phone? I know that the Bluetooth API supports a BluetoothHeadset profile and that it outputs either 2,1,or 0 but I don't know how to use it. Thanks!
^disregard this
Edit: Can I test if Bluetooth.Headset is two?
Like-
if (Bluetooth.Headset = true){
action
}else (blah blah)
Would that let me know if my phone is connected to a Bluetooth headset?
Edit again: So the three states are connecting, connected, and disconnected. How can I test for connected?
For iOS and, if Google is correct, Android, you can look in Settings> Bluetooth> Devices. You should see your device there if it’s connected.
//to prevent repeated alerts
var h = 1
if (BluetoothHeadset == 2 && h == 1) {
alert("You have been connected to your Bluetooth headset.");
h = 0;
} else if (h == 0) {
alert("You have been disconnected from your Bluetooth headset.");
h = 1
}
I'm trying to assert two elements are in the same class, image attached. So i want to assert the data-qa-card-id="id number" and data-qa-available-card are in the same class. But then i want to check that the data-qa-card-id="id number" and data-qa-active-card are now in the same class after the data qa-card-id-changes state? Could i just use an if statement??
The main issue i have is that I cant figure out how to check when the card id changes from available to active as there are other "card" that have available card and active card elements also so i need to zone in on the exact class of the card id
Ive tried:
public void assert_available_status () {
GameId gameid = GameId.getInstance();
String card_id = gameid.currentGameId;
String available_card_id = game_card_id.getText();
Assert.assertEquals(card_id, this_card_id);
if (game_card_id.getClass() == available_card_status.getClass()) {
System.out.println(card_id + " is an available card");
}
I'm trying to assert the gameid i have matches the game id on the card then i am trying to assert they are in the same class. Not working though
Game id and available card status are type of strings. you can't use == operator to compare, instead compare it using equals method as given below.
if (game_card_id.getClass().trim().equals(available_card_status.getClass().trim()) {
System.out.println(card_id + " is an available card");
}
String firstElementClass = driver.findElement(By.xpath("//div[#data-qa-card-id='first id value']")).getAttribute("class");
String secondElementClass = driver.findElement(By.xpath("//div[#data-qa-card-id='second id value']")).getAttribute("class");
Assert.assertEquals(firstElementClass, secondElementClass);
Hope it helps you.
I am creating an app where people report whether or not they have the flu that week. I already have the code that allows me to be able to add to the number of people who do have the flu and the number of people who don't have the flu by pressing buttons. It then creates a percentage of people who have the flu based on that data. But whenever I close out of the app, all of the data goes away. The same data also won't be able to be accessed by the other people with the app.
Here is the code for the app.
public void fluButton()
{
Button hasFluButton = (Button)findViewById(R.id.fluButton);
hasFluButton.setOnClickListener(
new View.OnClickListener()
{
#Override
public void onClick(View v)
{
TextView t1 = (TextView)findViewById(R.id.influenzaPercent);
NumberFormat defaultFormat = NumberFormat.getPercentInstance();
defaultFormat.setMinimumFractionDigits(2);
numPeopleWFlu += 1;
percentFlu = ((double)numPeopleWFlu) / (numPeopleWOFlu + numPeopleWFlu);
String percent = defaultFormat.format(percentFlu);
t1.setText(percent + " of people have had the flu this week.");
}
}
);
}
public void noFluButton()
{
Button hasNoFluButton = (Button)findViewById(R.id.noFluButton);
hasNoFluButton.setOnClickListener(
new View.OnClickListener()
{
#Override
public void onClick(View v)
{
TextView t1 = (TextView)findViewById(R.id.influenzaPercent);
NumberFormat defaultFormat = NumberFormat.getPercentInstance();
defaultFormat.setMinimumFractionDigits(2);
numPeopleWOFlu += 1;
percentFlu = ((double)numPeopleWFlu) / (numPeopleWOFlu + numPeopleWFlu);
String percent = defaultFormat.format(percentFlu);
t1.setText(percent + " of people have had the flu in missouri this year.");
}
}
);
}`.
This answer will only provide you with a very vague solution as your question is broad.
Here's what you need to do, you need to rent a server and put all the data to that server.
Why do you need a server? Because you want lots of people to access the data as the same time. If you save the data to your app's SharedPreferences or something local, other people won't be able to get it.
So now you have a server, in your app, you retrieve the data from the server at the start of your app. There are lots of external libraries out there that can help you fetch something from the internet.
After you retrieved the data, you display it in some views and BOOM! You did the first part. The second part is to save the data to the server. When the user taps on a button or something, you save the data.
Sounds easy, huh?
Hello guys can someone share with me on how am i going to code my viewvideo.java class such that it allow auto-play video function which automatically sequence the task of playing the selected video in a listview (from current position to the latest video recorded in sequence until the latest video in line has finished playing) which is something similar to the youtube auto-play function if you know what i mean?
Can someone help me pertaining to this problem i'm facing now i'm rather quite new to android/java programming and have been stuck on this problem for days... Sorry for my bad English above..
I think that all you need to do is call videoView.setVideoPath(next_file_path) and then call videoView.start(). If there are no more videos, then call videoView.stopPlayback().
Here's something that might work:
#Override
public void onClick(DialogInterface dialog, int which) {
if (arg1 == 0) {
Intent intentInfo = new Intent(ListViewActivity.this, DialogBox.class);
// Retrieve the path names of all videos from the top to the
// selected item (inclusive).
arrayPath = new String[selectedPosition+1];
for (int i = 0; i <= selectedPosition; ++i) {
arrayPath[i] = videoItems.get(i).absolutePath;
}
VideoInfo info = videoItems.get(selectedPosition);
intentInfo.putExtra("fileName", info.name);
intentInfo.putExtra("fileSize", info.size);
intentInfo.putExtra("absolutePath", info.absolutePath);
intentInfo.putExtra("arrayPath", arrayPath);
startActivity(intentInfo);
}
else
{
deleteFile();
}
}
This passes the array of path names to your DialogBox activity (which you haven't posted). You should then be able to retrieve arrayPath and pass it on to the VideoView activity if the user selects to play all videos.