Hey,
In my app for android I need to allow the user to call a number, but he or she should only be able to call an emergency number, like (911, 100,112, etc.). Is there any way to check if the number entered in an editText field is an emergency number or not. The other answeres online all use 911, as the only emergency number, but I would like my app's feature to work for all supported countries.
CODE FOR MAKING THE CALL:
Code:
String phoneNumber=String.valueOf(editText2.getText());
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("tel:" + phoneNumber));
startActivity(intent);
Thanks in advance!
Id say your gonna need to look up the emergency numbers for each country and just check manualy for each one. Because im not aware of any function that fits your description.
So id do something like this:
Code:
String phoneNumber=String.valueOf(editText2.getText());
If(emergencyCheck()==true){
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + phoneNumber));
startActivity(intent);
}
public boolean emergencyCheck(){
if(phoneNumber == "911" || phoneNumber =="000"){
Return true;
}
Else return false;
}
A switch statement would be better but im typing from my mobile so this will show my point.
scorpafied said:
Id say your gonna need to look up the emergency numbers for each country and just check manualy for each one. Because im not aware of any function that fits your description.
So id do something like this:
Code:
String phoneNumber=String.valueOf(editText2.getText());
If(emergencyCheck()==true){
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + phoneNumber));
startActivity(intent);
}
public boolean emergencyCheck(){
if(phoneNumber == "911" || phoneNumber =="000"){
Return true;
}
Else return false;
}
A switch statement would be better but im typing from my mobile so this will show my point.
Click to expand...
Click to collapse
Ummm, I actually tried that, ya see its gonna take ages to write that, because , so many countries have so many codes, is there any way I can pull up the ICE dialler programatically from my app then...
Looked into it. Theres actually an inbuilt function which does this. Checks for emergency numbers provided by both the sim card and some list. So depending on where u are in the world would depend on what the emergency numbers are.
android.telephony.PhoneNumberUtils that is the class. and the method is "isEmergencyNumber". Info can be found here
If this doesnt do what u want then my first suggestion is your best bet.
Yup seems to work, thanks!
Related
Hi there
I'm writing an PocketPC Application which also uses the Phone functions.
But how could I catch an incoming call with number?
I just need to get an event to get the number of the incoming call, to make something like an log entry
Can anyone give me some hints?
lineGetCallInfo(....)
and event LINE_CALLINFO
Thanks for your reply
And how can I catch this event in C# ?
1)init TAPI (search on this forum)
2)in cycle call lineGetMessage
in struct LINEMESSAGE check dwMessageId
3)if dwMessageId == LINE_APPNEWCALL - incoming call
4)if dwMessageId == LINE_CALLINFO - call info changed
call lineGetCallInfo
in struct LINECALLINFO check dwCallerIDFlags
5)if you work with different media modes (voice, datamodem, fax and etc) check dwMediaMode in LINECALLINFO structure
using this, how would i know if the phone is on a call already? would i be concerned with dwMessageId also here and what constant would i be comparing to?
thanks.
Thanks for your help
But because I'm new to the .NET stuff , do you have some sample code on how to implement this ?
source codes from vangelderp:
http://forum.xda-developers.com/download.php?id=3598
about geting caller number:
Code:
LPLINECALLINFO lpCallInfo = NULL;
unsigned size = sizeof(LINECALLINFO);
LPLINECALLINFO tmp;
/*lpCallInfo place right size of struct to dwNeededSize*/
while (tmp = (LPLINECALLINFO)realloc(lpCallInfo, size))
{
lpCallInfo = tmp;
lpCallInfo->dwTotalSize = size;
if (lineGetCallInfo(hCall, lpCallInfo))
{
free(lpCallInfo);
return;
}
if(lpCallInfo->dwNeededSize <= size)
break;
size=a->dwNeededSize;
}
if (!tmp)
{
free(lpCallInfo);
return;
}
/*dwCallerIDOffset is offset in bytes from top of struct*/
if (lpCallInfo->dwCallerIDFlags & LINECALLPARTYID_ADDRESS)
_tcsncpy(number, (LPTSTR)((BYTE*)lpCallInfo + lpCallInfo->dwCallerIDOffset), 256);
/*256 symbols only for example*/
using this, how would i know if the phone is on a call already? would i be concerned with dwMessageId also here and what constant would i be comparing to?
thanks.
you can't
use RIL_GetLineStatus from RIL
Has someone experience about using the TAPI Wrapper with .NET CF2.0 ?
Here it doesn'T work at all :-(
Hi.
I've been researching for many days. and i am really out of ideas.
First. I am new to all this.
Okay. my project:
I have:
- 1 Activity
- 1 Widget
So. my app is the widget itself. when you click the widget, it opens up the activity, the activity consists of a + and - button and a textview. the textview is on 0. when you click on +, you add up +1 to the textview and vica versa with the -.
So, what i want, in the activitys "onPause()", i want it to save the value and transfer it to the widget, i tried to send a broadcast, but that didnt work properly (i wanted to save the value in a hidden textview, but appwidget cant read values of TextViews -.-').
Also i tried some sql stuff.. didnt work either (appwidget doesnt support?)
Tried so save as a file on sd, didnt work (appwidget doesnt support?)
I couldnt use the broadcast thing because my app is made like this:
appwidget:
public void onUpdate(Context context,AppWidgetManager mgr,int[] appWidgetIds){
SetUp(context, mgr, appWidgetIds);
}
public void SetUp(Context c, AppWidgetManager mgr, int[] appWidgetIds){
//do stuff.....
}
public void onReceive(Context context, Intent intent) {
//If i get the number here, i cant really do anything with it, because i cant really save my value anywhere?
}
Bump. no one can help ?
I tried with the intent.putextra, but wont work.
If anyone wants to help me at msn, pm me. (eventually lightly paid)
Hi
Have you figured how to do it yet? I'm having the exact same problem and I'm unable to find any kind of solution.
Thank you!
Hi guys,
On a button click I am inflating a layout like so:
Code:
public void plusLayout(View v) {
// inflating layout here:
LinearLayout ll1 = (LinearLayout) findViewById(R.id.main_layout);
// this layout is being inflated:
View newView = getLayoutInflater().inflate(R.layout.layout_to_be_added, null);
// add layout
ll1.addView(newView);
}
But when the activity restarts, the inflated layouts are gone.
I'd like the layouts to stay there.
(The user can click a button to remove the layout by hand).
I must be missing something trivial here right?
Cheers,
Daan
Which way is it restarted?
If the complete app is restarted, a new layout will be set in the onCreate method.
nikwen said:
Which way is it restarted?
If the complete app is restarted, a new layout will be set in the onCreate method.
Click to expand...
Click to collapse
Yeah when you press back button and start the app again or completely kill it.
It also happens on orientation change as the activity get restarted then as well.
But I think you can override that in the manifest somewhere.
DaanJordaan said:
Yeah when you press back button and start the app again or completely kill it.
It also happens on orientation change as the activity get restarted then as well.
But I think you can override that in the manifest somewhere.
Click to expand...
Click to collapse
Ah ok.
The point is: If you open the app or turn your device, the onCreate method is called. There you set a completely new layout. You would need to save that the layout is inflated (you could use a SharedPreferences entry) and inflate it in the onCreate method. If you just want it to appear again after turning the device, use the onSaveInstanceState method and the onRestoreInstanceState method. That would be better practice.
Look at the activity lifecycle.
Just so I'm sure I get this right :
The user launches the app, the layouts are not inflated
He presses a button which calls your plusLayout() method, so the layouts are now inflated
The user quits the activity and restarts it, the layouts are not inflated anymore but you want them to.
Is that correct ?
If it is, 2 ways I can think of :
Overriding savedInstanceState() & onRestoreInstanceState() :
First, declare a private Boolean before the onCreate() of your activity :
Code:
private Boolean isInflated = false;
Then, set it to true in the onClick() of your button, and override savedInstanceState and onRestoreInstanceState like so :
Code:
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
// Save state changes to the savedInstanceState.
// This bundle will be passed to onCreate if th activity is
// killed and restarted.
savedInstanceState.putBoolean("inflate", isInflated);
}
Code:
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
// Restore UI state from the savedInstanceState.
// This bundle has also been passed to onCreate.
Boolean myBoolean = savedInstanceState.getBoolean("inflate");
if (myBoolean == true)
plusLayout(myView);
}
Using the sharedPreferences
Same logic, different way to save the boolean :
Before onCreate(), declare a private boolean and a private SharedPreferences :
Code:
private Boolean isInflated = false;
private SharedPreferences prefs = getSharedPreferences("MY_PREFS");
in the onClick of your button :
Code:
isInflated = true;
Editor e = prefs.edit();
e.putBoolean("inflate", isInflated);
e.commit();
Then, in your onCreate(), retrieve the stored value and if it's true, call your plusLayout() method :
Code:
Boolean doInflate = prefs.getBoolean("inflate", false // this is the default value);
if (doInflate == true)
plusLayout(myView);
nikwen said:
Ah ok.
The point is: If you open the app or turn your device, the onCreate method is called. There you set a completely new layout. You would need to save that the layout is inflated (you could use a SharedPreferences entry) and inflate it in the onCreate method. If you just want it to appear again after turning the device, use the onSaveInstanceState method and the onRestoreInstanceState method. That would be better practice.
Look at the activity lifecycle.
Click to expand...
Click to collapse
Okay I'm working on that at the moment.
Whenever a layout is created an (int) "counter" get incremented.
I will save this "counter" in the SharedPreferences.
When the app starts layouts get created "counter" times.
Is this good practice?
It seems so strange that there isn't an easier way to save layout/activity states.
Edit:
Androguide.fr said:
Just so I'm sure I get this right :
The user launches the app, the layouts are not inflated
He presses a button which calls your plusLayout() method, so the layouts are now inflated
The user quits the activity and restarts it, the layouts are not inflated anymore but you want them to.
Is that correct ?
Click to expand...
Click to collapse
That is correct. Big thanks for the examples.
DaanJordaan said:
Okay I'm working on that at the moment.
Whenever a layout is created an (int) "counter" get incremented.
I will save this "counter" in the SharedPreferences.
When the app starts layouts get created "counter" times.
Is this good practice?
It seems so strange that there isn't an easier way to save layout/activity states.
Edit:
That is correct. Big thanks for the examples.
Click to expand...
Click to collapse
I would use his snippets. They are good (as always). Decide which one to use by what I have given above:
Just for turning:
onSaveInstanceState and onRestoreSavedInstanceState
For turning and reopening:
Shared preferences
I have a TableLayout with a table. How can I set onClicklisteners for each cell of this table?
I have not found any proper solution for this problem.
kovacsakos91 said:
I have a TableLayout with a table. How can I set onClicklisteners for each cell of this table?
I have not found any proper solution for this problem.
Click to expand...
Click to collapse
You'd usually set each view in each TableRow to be clickable (via android:clickable="true" in xml oder via view.setClickable(true); in java).
In xml, you then override the androidnClick attribute with your methods name, but if yuo want to have real onClickListeners you should call view.setOnClickListener(mListener);
To seperate the clicks in the onClick method, you should get the id's like this:
Code:
public void onClick(View v){
// switch case the id's:
switch(v.getId(){
case R.id.someId:
// do something in response;
break;
}
// for getting the id of the parent TableRow, use
int rowId = ((TableRow) v.getParent()).getId();
}
Depending on what you want to display in the table, you could also use Buttons for that.
public void click(View view) {
String one = "one";
EditText et = (EditText)findViewById(R.id.editText1);
String entered_text = et.getText().toString();
if(et.getText().toString() == one){
TextView tv1 = (TextView)findViewById(R.id.textView1);
tv1.setText("Correct!");
}
else{
TextView tv = (TextView)findViewById(R.id.textView1);
tv.setText(one+entered_text); }
}
This is a code snippet extracted from my program, i didn't post the whole program because it wasn't necessary, as the program runs fine without any runtime exceptions.
So, the program when executed on eclipse doesn't show any errors and runs fine, but when run the "if" condition "et.getText().toString() == "one"" always returns false even when the "entered_text" is "one" i.e.; it never prints "correct!" and the code always prints "one+entered_text" that is the statement in the else clause. And the interesting thing is, if you enter "one" the output will be "oneone", that is the else statement.
Please help me where i went wrong.
Thanks in advance.
You're passing view argument in function so try initialize edit text with (EditText)view.findViewById(R.id.edittext);
panwrona said:
You're passing view argument in function so try initialize edit text with (EditText)view.findViewById(R.id.edittext);
Click to expand...
Click to collapse
Thanks for the reply.
I did what you said and got a runtime exception.
You're running it in fragment or activity?
panwrona said:
You're running it in fragment or activity?
Click to expand...
Click to collapse
Activity.
Are you initializing it in oncreate or somewhere else?
That's easy. Instead of == use text.equals(one)
String are not compared by mathematical signs
Sent from my XT1033 using XDA Premium 4 mobile app