android DTmf tone - android

I am sending dtmf tone via this code.
String number="tel:+962791212121,2,3,3";
Intent c1= new Intent(android.content.Intent.ACTION_CALL, Uri.parse(number));
startActivity(c1);
It send perfect dtmf as this. 2+(2 sec delay)+3+(2 sec delay)+3.
but I want to remove that 2 sec delay or I want to control that delay.
How can I control (2 sec delay)?
Or any other method to send dtmf tone during call?

To remove the delay remove the comma.

Try this method().
private void call(int profileid) {//call procedure logic
ProfileDo profile = adapter.getProfile(profileid);
if (profile.getStepCount() == 0) {
Toast.makeText(getApplicationContext(), "Please edit the profile and add atleast one value to make a call", 10000).show();
return;}
String call = "tel:";
for (StepDO step : profile.getSteps()) {
String value = URLEncoder.encode(step.getValue());
int delay = step.getDelay();
String pausesStr = "";
for (int i = 0; i < delay / 2; i++) {
pausesStr += PhoneNumberUtils.PAUSE;
}
call += value + pausesStr;
}
startActivity(new Intent("android.intent.action.CALL", Uri.parse(call)));
}
Hope this helps you .

Try this:
Intent signalIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:12334566778"+","+","+"1"));
startActivity(signalIntent);

Related

android wear phone call

I have 2 questions
Can we make phone calls programatically from Android wear app?
I have created a custom notifcation on Android wear app. Is it possible to open the mobile dialer app, when user tap on the action on custom notification?
Any help woud be appreciated.
Thanks.
yes i thing it is possible. try to use:
yes thing it is possible. try to use:
/*start a direct call, make sure you have call permission declared on your manifest
*<uses-permission android:name="android.permission.CALL_PHONE" />
*/
public static void phoneCall(String n, Activity currentActivity) {
char ench[] = n.toCharArray();
String tel = "";
for (int i = 0; i < ench.length; i++) {
if (ench[i] == '#')
tel = tel + Uri.encode("#");
else
tel = tel + ench[i];
}
String toDial = "tel:" + tel;// msgbox(Intent.ACTION_ALL_APPS);
currentActivity.startActivityForResult(
new Intent(hasPermission(currentActivity,
permission.CALL_PHONE) ? Intent.ACTION_CALL
: Intent.ACTION_DIAL, Uri.parse(toDial)), 1024);
}
//open phonne compositor with phone number as n
public static void phoneDial(String n, Activity currentActivity) {
char ench[] = n.toCharArray();
String tel = "";
for (int i = 0; i < ench.length; i++) {
if (ench[i] == '#')
tel = tel + Uri.encode("#");
else
tel = tel + ench[i];
}
String toDial = "tel:" + tel;// msgbox(Intent.ACTION_ALL_APPS);
Intent intent=new Intent(Intent.ACTION_DIAL,
Uri.parse(toDial));
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
currentActivity.startActivityForResult(intent, 1024);
}
//control if your application have some permission
public static boolean hasPermission(Context context, String permission) {
int res = context.checkCallingOrSelfPermission(permission);
return (res == PackageManager.PERMISSION_GRANTED);
}

Problems when sending a continuous stream of data over BLE

I'm wondering if anybody can help me figure out what is causing the data I am sending to become corrupt.
My setup is currently an Arduino pro mini with a HM-10 bluetooth module connected (I have also tried HM-11 Module too) and an Android application to receive the bluetooth data.
Module setup: http://letsmakerobots.com/node/38009
If I send data with big enough intervals then the data is fine, but if I send the data continuously I see messages getting mixed up and lost. To test this I send "$0.1,0.2,0.3,0.4,0.5" to the Android application from the Arduino, sometimes the stream of data appears to send fine but other times it is really quite scrambled. Please see the below graphs that demonstrate this:
Good case:
Bad case:
Arduino code:
String inputString = ""; //Hold the incoming data.
boolean stringComplete = false; //Determines if the string is complete.
boolean realtime = false;
void setup()
{
Serial.begin(9600);
delay(500);
Serial.print("AT+START");
delay(500);
}
void loop()
{
if(stringComplete)
{
if(inputString.equals("rStart"))
{
Serial.println("$startACK");
realtime = true;
}
else if(inputString.equals("stop"))
{
Serial.println("$stopACK");
realtime = false;
}
else{
Serial.print(inputString);
}
inputString = "";
stringComplete = false;
}
if(realtime)
{
Serial.println("$0.1,0.2,0.3,0.4,0.5,0.6");
delay(10);
}
}
void serialEvent() {
while (Serial.available())
{
// get the new byte:
char inChar = (char)Serial.read();
if (inChar == '\n')
{
stringComplete = true;
}
else
{
inputString += inChar;
}
}
}
The Android side just receives the data and then parses it in an IntentService:
#Override
protected void onHandleIntent(Intent intent) {
//Incoming command.
String rawData = intent.getStringExtra(DataProcessingIntentService.REQUEST);
//Append our new data to our data helper.
Log.i(this.getClass().getName(), "Previous Raw: (" + DataProcessingHelper.getInstance().getData() + ")");
DataProcessingHelper.getInstance().appendData(rawData);
Log.i(this.getClass().getName(), "New Raw: (" + DataProcessingHelper.getInstance().getData() + ")");
commandStartIndex = DataProcessingHelper.getInstance().getData().indexOf("$");
commandEndIndex = DataProcessingHelper.getInstance().getData().indexOf("\n");
//Set this as the data starting point.
if(commandStartIndex != -1){
DataProcessingHelper.getInstance().offsetData(commandStartIndex);
}
//Ensure that a command has been found and that the end index is after the starting index.
if(commandStartIndex != -1 && commandEndIndex > commandStartIndex){
//Remove the command structure from the command.
command = DataProcessingHelper.getInstance().getData().substring(commandStartIndex+1, commandEndIndex-1); //Remove the \r\n end command.
DataProcessingHelper.getInstance().offsetData(commandEndIndex+1);
if(command.length() > 1){
//Split the data out of the comand.
splitData = command.split(",");
Log.i(this.getClass().getName(), "Broadcasting the processed data. (" + command + ")");
//Broadcast data.
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(DataProcessingIntentService.RESPONSE);
broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
broadcastIntent.putExtra(DataProcessingIntentService.RESPONSE, splitData);
sendBroadcast(broadcastIntent);
}else{
Log.e(this.getClass().getName(), "Command is less than 1 character long!");
}
}
}
Thank you for any help!
I have now figured out what was causing this problem. It appears that BLE only supports a maximum of 20 bytes per a transaction. The time between these transactions is different depending on what you are using. I'm currently using notifications which means that I can send 20 bytes every 7.5 milliseconds maximum. I have opted for 10 milliseconds to be safe. I will now need to look into breaking up packets into 20 bytes maximum to ensure no data corruption.

Android - Measuring the time between opening an activity via intent and when results are received

I have a simple application that opens the Barcode Scanner App by ZXing.
Now, I want to know how much time it takes for a scan to accomplish. Basically, the time when the intent was started up to the time that the result is obtained. Now, I know this is simple, just put a nanoTime object when the intent is executed and another nanoTime when I get the result, subtract the two and multiply to get it in seconds/milliseconds.
However, I have the intent on loop, because I want to scan a sequence of QR Codes and I figured that a for loop is the best way to go about it.
So I have several global time variables
long start, end, time;
Here is the code for the intent:
//Multi Scan Button
public Button.OnClickListener onMultiScan = new Button.OnClickListener() {
public void onClick(View v) {
//start = System.nanoTime();
for(int i = 0 ; i < 5 ; i++){
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
//start = System.nanoTime();
startActivityForResult(intent, multiScan);
}
}
};
And here is the code to get the input.
public void onActivityResult(int requestCode, int resultCode, Intent data) {
//ordinary scan
if (requestCode == ordinaryScan) {
if (resultCode == RESULT_OK) {
end = System.nanoTime();
time = (end - start) / 1000000;
System.out.println("Time" + " " + /*i + +*/ time);
String contents = data.getStringExtra("SCAN_RESULT");
Toast.makeText(getApplicationContext(), contents, Toast.LENGTH_SHORT).show();
}
else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
//multiple scan
if (requestCode == multiScan) {
end = System.nanoTime();
time = (end - start) / 1000000;
System.out.println("Time" + " " + /*i + +*/ time);
if (resultCode == RESULT_OK) {
String content = data.getStringExtra("SCAN_RESULT");
//codes = codes + contents + " ";
inputs[counter] = content;
counter += 1;
if(counter == 5){
//output();
verify();
}
}
else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
I commented out the part where I start the timer since I'm not sure where to put them. What happens is if I call it before the loop, I get one result only, if I put it inside the loop, I get multiple results which aren't so far from one another.
Obtaining the time it takes for an intent to finish is easy if it's only called once, but if it's called more than once on loop, it gets tricky.
So, is there a way to properly take the time needed for an intent to open and get the result? I'm open to suggestions even if it means rewriting how I call the activity more than once (I'm currently using a loop).
I also prefer to be able to get the time right after a code is scanned right away, so I know the time between the activity call and the activity result. I don't want to wait for each call to finish before I get the time it took for each call to finish. I want real time update. Thanks.
If you still want to use the loop, a possible approach would be not to use a single multiscan requestcode but one for each run of the loop.
Something like startActivityForResult(intent, MULTISCAN_BASE + i);
In this way you will be able to track all the runs separately, because you will be able to recognize which run the result refers to :
i = requestCode - MULTISCAN_BASE
The final step is putting your start time in an array, one for each cycle of the loop.
int[] start = new int[5];
Checking when you are done and get the sum of the times is then trivial.
Okay, found a way to make it work. It's a bit unrefined to be honest but it works and updates real time. The basic concept is to have a multiScan requestCode that is incremented every time that it gives a result as handled in onActivityResult method. Then there's an if statement that checks if the multiScan requestCode has reached the maximum number of iterations desired.
So here are the global variables:
int multiScan = 1;
int multiScanBase = 1;
long start, end, time;
And then the multiScanButton would look something like:
//Multi Scan Button
public Button.OnClickListener onMultiScan = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
start = System.nanoTime();
startActivityForResult(intent, multiScan);
}
};
Then the onActivityResult method would look something like this:
//multiple scan
if (requestCode < multiScanBase + 5 ) {
end = System.nanoTime();
time = (end - start) / 1000000;
System.out.println("Request Code = " + multiScan);
System.out.println("Time" + " " + /*i + +*/ time);
if (resultCode == RESULT_OK) {
String content = data.getStringExtra("SCAN_RESULT");
//codes = codes + contents + " ";
inputs[counter] = content;
counter += 1;
if(counter == 5){
//output();
verify();
}
}
else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
//This is the part where I check for the requestCode
//In this example, I wanted to iterate the activity 5 times
//So if the request code is still less than the base + number of iterations
//Increment the multiScan requestCode and run the method again
//In this way, the time for each scan is given in real time
if(requestCode < multiScanBase + 5){
multiScan += 1;
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, multiScan);
}
}
So there. The code works for me and updates are given in real time. Thanks for the ideas on how to do this.
Merry Christmas everyone.

How to send DTMF tones in active call in android?

Is it possible to send DTMF tones in active call in android ? I tried it with proxyphone.sendDtmf() but it was useless.
How can i achieve it ?
In VOIP only it is possible,Android applications have no access to the in-call audio stream. You can fake a it a bit in speakerphone mode.
Try this method() .It is getting the number and delay from user.
private void call(int profileid) {//call procedure logic
ProfileDo profile = adapter.getProfile(profileid);
if (profile.getStepCount() == 0) {
Toast.makeText(getApplicationContext(), "Please edit the profile and add atleast one value to make a call", 10000).show();
return;}
String call = "tel:";
for (StepDO step : profile.getSteps()) {
String value = URLEncoder.encode(step.getValue());
int delay = step.getDelay();
String pausesStr = "";
for (int i = 0; i < delay / 2; i++) {
pausesStr += PhoneNumberUtils.PAUSE;
}
call += value + pausesStr;
}
startActivity(new Intent("android.intent.action.CALL", Uri.parse(call)));
}

DTMF Tone Android [duplicate]

Is it possible to send DTMF tones in active call in android ? I tried it with proxyphone.sendDtmf() but it was useless.
How can i achieve it ?
In VOIP only it is possible,Android applications have no access to the in-call audio stream. You can fake a it a bit in speakerphone mode.
Try this method() .It is getting the number and delay from user.
private void call(int profileid) {//call procedure logic
ProfileDo profile = adapter.getProfile(profileid);
if (profile.getStepCount() == 0) {
Toast.makeText(getApplicationContext(), "Please edit the profile and add atleast one value to make a call", 10000).show();
return;}
String call = "tel:";
for (StepDO step : profile.getSteps()) {
String value = URLEncoder.encode(step.getValue());
int delay = step.getDelay();
String pausesStr = "";
for (int i = 0; i < delay / 2; i++) {
pausesStr += PhoneNumberUtils.PAUSE;
}
call += value + pausesStr;
}
startActivity(new Intent("android.intent.action.CALL", Uri.parse(call)));
}

Categories

Resources