I'm trying to send a USSD code through my cellphone, so I used an intent as many here suggested is the way to send the code. Unfortunately, every time I send the code it sends the same number *4355696753
the code I'm using to send the USSD is:
sendCode.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
String cUssd = ussdCodeEdTxt.getText().toString();
String cToSend = "tel:*" + cUssd + Uri.encode("#");
startActivityForResult(new Intent("android.intent.action.CALL",
Uri.parse(cToSend)), 1);
}
});
any ideas would be greatly appreciated
I think you may need to use Uri.encode("*") for the star as well
sendCode.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
String cUssd = ussdCodeEdTxt.getText().toString();
String cToSend = "tel:" + Uri.encode("*") + cUssd + Uri.encode("#");
startActivityForResult(new Intent("android.intent.action.CALL",
Uri.parse(cToSend)), 1);
}
});
though this is an old post but, for those facing the same issue try this Uri.fromParts("tel", number eg = *222# , "#");
Related
How do I call a number ending with '#' sign using android dialer?
My code is as follows,
EditText firstNumber;
Button btnAdd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main23);
Toast.makeText(Main23Activity.this,
"Type in your Pin Number", Toast.LENGTH_LONG).show();
btnAdd = (Button)findViewById(R.id.button12);
btnAdd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
numberSign = "#";
EditText et = (EditText) findViewById(R.id.editText6);
String text= et.getEditableText().toString();
Toast.makeText(Main23Activity.this,
"Adding Money to your account has never been this easy", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:*221*" + text + numberSign ));
startActivity(intent);
} catch (Exception e) {
}
}
});
}
}
This is how you call a number ending with '#' using android dialer. You need to encode and then parse.
Try the below code,
String text = et.getText().toString();
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + Uri.encode("*221*" + text + "#")));
startActivity(intent);
Using this link you can get unicode and hex values
for example 36 can be stored in strings.xml as
<string name="abcd">36</string>
I'm making an Android app which need to monitor when the call is disconnected and get the disconnect cause to do some more things. I'm using a broadcast receiver to know when the call is disconnected but I'm stuck at getting the disconnect cause.
Below is my brief code:
final BroadcastReceiver phoneStateReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
String state = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
String cause = null;
if (intent.hasExtra(TelecomManager.EXTRA_CALL_DISCONNECT_CAUSE)) {
cause = intent.getExtras().getString(TelecomManager.EXTRA_CALL_DISCONNECT_CAUSE);
}
TextView callState = (TextView) findViewById(R.id.callState);
callState.setText("Call State is: " + state + " " + number + " " + cause);
}
};
btnStart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
registerReceiver(phoneStateReceiver, new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED));
btnStop.setEnabled(true);
btnStart.setEnabled(false);
}
});
btnStop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
unregisterReceiver(phoneStateReceiver);
btnStart.setEnabled(true);
btnStop.setEnabled(false);
}
});
Please, somebody helps me at this point?
Many thanks.!!!
From API-21 documentation, EXTRA_CALL_DISCONNECT_CAUSE & EXTRA_CALL_DISCONNECT_MESSAGE are optional extras for TelecomManager.ACTION_PHONE_STATE_CHANGED. Looks like they do not have any data in them in AOSP code and as observed on Nexus 5 (L & M releases). It has been left for OEMs to implement and report any data in those extras. I am looking for any devices that use these extras. It would be great to know of any devices which do report call disconnect cause / message.
I have a problem with inviting firend by facebook api to my app. This is my method:
private void inviteFromFacebook(Activity activity, List<GraphUser> list) {
for(int i=0; i<list.size(); i++) {
//TODO post invite to friends wall
// Log.v("MainActivity", "user id: " + user.getId());
if(list == null || list.size() == 0)
return;
Bundle parameters = new Bundle();
String friendsIdsInFormat = "";
friendsIdsInFormat = friendsIdsInFormat + list.get(i).getId();
parameters.putString("to", friendsIdsInFormat);
parameters.putString( "message", "Use my app!");
Facebook mFacebook = new Facebook( getResources().getString(R.string.facebook_app_id));
// Show dialog for invitation
mFacebook.dialog(activity, "apprequests", parameters, new Facebook.DialogListener() {
#Override
public void onComplete(Bundle values) {
// TODO Auto-generated method stub
}
#Override
public void onCancel() {
// TODO Auto-generated method stub
}
#Override
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
}
#Override
public void onError(DialogError e) {
// TODO Auto-generated method stub
}
});
}
}
Everyting is ok, but I want to send invitation to many frieds, so in this codes I show one dialog for every person. How can I show only one dialog, but with many friends? This is possible or I must for every friend show dialog?
You can send a comma delimited list in the "to" field, like "123,456,789".
Be careful about sending too many requests though, you don't want to be identified as a spam app.
How do I make a phone call when I get number from edittext? I try this but it does not work. I have a problem with passing variable number to Uri.parse() must be inside void the gettext?
public String string;
public String number;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText txtcallnumber;
txtcallnumber = (EditText)findViewById(R.id.callnumber);
string = txtcallnumber.getText().toString().trim();//There no work call
number = "tel:" + string;
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
call();
}
});
}
public void call() {
try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
//callIntent.setData(Uri.parse("tel:xxxxxxx")); //This work
string = txtcallnumber.getText().toString().trim();
number = "tel:" + string;//There work call
callIntent.setData(Uri.parse(number));
startActivity(callIntent);
} catch (ActivityNotFoundException activityException) {
Log.e("helloandroid dialing example", "Call failed");
}
You need to add Permission inside in your manifest file ::
<uses-permission android:name="android.permission.CALL_PHONE">
Inside your call() method try to use these Intent::
number=edittext.getText().trim();
no="tel:"+number;
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(no)));
in onCreate method there is no need for :
string = txtcallnumber.getText().toString().trim();
number = "tel:" + string;
because onCreate is pretty much used for setting up the display and there will be no input by the user before the screen is set up but in onCall method after entering the text and pressing the button then it wouldd...you know.
Plus you should have this to check for nothing entered:
if(string!=null){
try{try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
string = txtcallnumber.getText().toString().trim();
number = "tel:" + string;
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(number)));
} catch (ActivityNotFoundException activityException) {
Log.e("helloandroid dialing example", "Call failed");
}}else{
Log.d("helloandroid dialing example","nothing entered");}
i am using google transalate api in my application,i have done in text conversion is ok
but translate-text to speech is pending
http://android-developers.blogspot.com/2009/09/introduction-to-text-to-speech-in.html
this code i am using how can implement translate text voice in android.
http://www.freeimagehosting.net/uploads/c382dd10f8.png
this above screenshot display text conversion is ok,click audiobutton image listen translate text in audioplayer how can implemented
my code
//audio button click event..........
submit = (ImageView) findViewById(R.id.ImageView01);
submit.setOnClickListener(new View.OnClickListener()
{ public void onClick(View v)
{
//speech code how can implemented
}
});
/////////////////// translate button code//////////////////////
((Button)findViewById(R.id.Button01)).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
String fromLan=spineFrom.getSelectedItem().toString();
String toLan=spineTo.getSelectedItem().toString();
Log.v("check",fromLan+" :"+toLan);
translatedText = Translate.execute(((EditText)findViewById(R.id.EditText01)).getText().toString(),converStrtoLan(fromLan),converStrtoLan(toLan));
((TextView)findViewById(R.id.TextView02)).setText(translatedText);
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent,1);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
private TextToSpeech mTts;
protected void onActivityResult(
int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// success, create the TTS instance
mTts = new TextToSpeech(this, null);
} else {
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction(
TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
mTts.setLanguage(Locale.US);
String myText1 = "Did you sleep well?";
String myText2 = "I hope so, because it's time to wake up.";
mTts.speak(myText1, TextToSpeech.QUEUE_FLUSH, null);
mTts.speak(myText2, TextToSpeech.QUEUE_ADD, null);
}
private Language converStrtoLan(String lan){
if(lan.equals("ENGLISH") || lan=="ENGLISH"){
return Language.ENGLISH;
}else if (lan.equals("SPANISH") || lan=="SPANISH"){
return Language.SPANISH;
}
return null;
}
}
how can add this audio code in audio click event ,
please forward some valuable response of this code this issue i am struggle for more number of days thanks in advance ..
In order to do Text To Speech with Android you can use eyes-free library