Hold and Unhold call using pjsua2 Android - android

I'm using pjsua2 with Android build version 2.2.1.
I can put a call on hold using:
CallOpParam prm = new CallOpParam();
prm.setOptions(pjsua_call_flag.PJSUA_CALL_UPDATE_CONTACT.swigValue());
try {
currentCall.setHold(prm)
} catch(Exception e) {
e.printStackTrace();
}
To unhold call I tried this, but does not work:
CallOpParam prm = new CallOpParam();
prm.setOptions(pjsua_call_flag.PJSUA_CALL_UNHOLD.swigValue());
try {
currentCall.reinvite(prm);
} catch(Exception e) {
e.printStackTrace();
}
Is that a bug of pjsua? How should I call the reinvite method?

Look my code:
public void holdCall() {
CallOpParam prm = new CallOpParam(true);
try {
currentCall.setHold(prm);
} catch (Exception e) {
e.printStackTrace();
}
}
public void unHoldCall() {
CallOpParam prm = new CallOpParam(true);
prm.getOpt().setFlag(1);
try {
currentCall.reinvite(prm);
} catch (Exception e) {
e.printStackTrace();
}
}
According to this issue, it's necessary to set flag on CallOpParam.
The constant PJSUA_CALL_UNHOLD == 1, but I couldn't use PJSUA_CALL_UNHOLD directly.
I'm using Asterisk and it's working.

To unhold the call I need this in version 2.4.5:
CallOpParam prm = new CallOpParam();
CallSetting opt = prm.getOpt();
opt.setAudioCount(1);
opt.setVideoCount(0);
opt.setFlag(pjsua_call_flag.PJSUA_CALL_UNHOLD.swigValue());
call.reinvite(prm);

Here is another example:
public void setHold(boolean hold) {
CallOpParam param = new CallOpParam();
try {
if (hold) {
setHold(param);
} else {
CallSetting opt = param.getOpt();
opt.setAudioCount(1);
opt.setVideoCount(0);
opt.setFlag(pjsua_call_flag.PJSUA_CALL_UNHOLD.swigValue());
reinvite(param);
}
} catch (Exception exc) {
String operation = hold ? "hold" : "unhold";
Logger.error(LOG_TAG, "Error : ", exc);
}
}
You can find here the full implementation.

Related

Watson Speech to Text Android

I am using the example code from IBM's github for Speech To Text but this line is giving me problems. android studio throws an error saying that i don't need the "capture" argument but when i remove it, i get an error when i run it that the audio cannot be null.
speechService.recognizeUsingWebSocket(capture, getRecognizeOptions(), new MicrophoneRecognizeDelegate());
it is used in this part
private void recordMessage() {
//mic.setEnabled(false);
speechService = new SpeechToText();
speechService.setUsernameAndPassword(STT_username, STT_password);
speechService.setEndPoint("https://stream.watsonplatform.net/speech-to-text/api");
if(listening != true) {
capture = microphoneHelper.getInputStream(true);
InputStream myInputStream = new MicrophoneInputStream(true);
new Thread(new Runnable() {
#Override public void run() {
try {
speechService.recognizeUsingWebSocket(capture, getRecognizeOptions(), new MicrophoneRecognizeDelegate());
} catch (Exception e) {
showError(e);
}
}
}).start();
listening = true;
Toast.makeText(MainActivity.this,"Listening....Click to Stop", Toast.LENGTH_LONG).show();
} else {
try {
microphoneHelper.closeInputStream();
listening = false;
Toast.makeText(MainActivity.this,"Stopped Listening....Click to Start", Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
}
This is a very late answer but just in case anyone needs this ..
update your call to :
speechService.recognizeUsingWebSocket(getRecognizeOptions(capture),new MicrophoneRecognizeDelegate());

How to get Advertising id in android?

I used this code it's working when i called from activity and fragment
import com.google.android.gms.ads.identifier.AdvertisingIdClient.Info;
Info adInfo = null;
try {
adInfo = AdvertisingIdClient.getAdvertisingIdInfo(mContext);
} catch (IOException e) {
e.printStackTrace();
} catch (GooglePlayServicesAvailabilityException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
String AdId = adInfo.getId();
But when i called from pending intent like Package Removed then i want to call the web service at that time i need advertising id but i got null.if you people had done previously please suggest me.thanks in advance.
try use app context
as receivers could use activity context or app context - depends who&how started the receiver
AdvertisingIdClient.getAdvertisingIdInfo(context.getApplicationContext());
You can try this code and call the bellow method on onCreate
public void getAAID()
{
AsyncTask.execute(new Runnable() {
#Override
public void run() {
try {
AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(MyActivity.this);
String myId = adInfo != null ? adInfo.getId() : null;
Log.i("UIDMY",myId);
} catch (Exception e) {
Log.e("error", e);
}
}
});
}
Check complete post: how to get AAID programmatically

android how to send and receive image and location (using map ) in group chat using xmpp-smack

i developing group chat app using android-xmpp, in that i don't know how to send and recive pics-image or location (using map).
So any one one can please give me way to do these.
currently , i got text message and add to list view , like following ,
Message msg = new Message(to, Message.Type.groupchat);
msg.setBody(text);
if (Constants.connection != null) {
try {
Constants.connection.sendPacket(msg);
Log.d("Send to room : Name : ", to);
Log.d("store", "store data to db");
//DBAdapter.addUserData(new UserData(text, "", "1" ,beam_id));
} catch (Exception e) {
Log.d("ooo", "msg exception" + e.getMessage());
}
messages.add(text);
runOnUiThread(new Runnable() {
public void run() {
// set to listview
setMyChatAdapter();
}
});
}
and receive using StanzaTypeFilter. So how for image and location sharing ?
I try following code for image using FileTransferManager , using smack-extensions-4.1.3-sources.jar .
private void sendImage()
{
FileTransferManager mg=new FileTransferManager(Constants.connection);
OutgoingFileTransfer transfer = mg.createOutgoingFileTransfer(beam_id+"#"+Constants.conference_name + "/" + Constants.resources);
File file = new File(selectedImagePath);
try {
transfer.sendFile(file, "test_file");
} catch (Exception e) {
e.printStackTrace();
}
while(!transfer.isDone()) {
if(transfer.getStatus().equals(FileTransfer.Status.error)) {
System.out.println("ERROR!!! " + transfer.getError());
} else if (transfer.getStatus().equals(FileTransfer.Status.cancelled)
|| transfer.getStatus().equals(FileTransfer.Status.refused)) {
System.out.println("Cancelled!!! "+ transfer.getError());
}
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if(transfer.getStatus().equals(FileTransfer.Status.refused) || transfer.getStatus().equals(FileTransfer.Status.error)
|| transfer.getStatus().equals(FileTransfer.Status.cancelled)){
System.out.println("refused cancelled error"+ transfer.getError());
} else {
System.out.println("Success");
}
}
But when i access that file using following ,
FileTransferManager mg=new FileTransferManager(Constants.connection);
it give me error ... has a private access of ... So , i find constructor of that file is private , this is jar file so i can not change it to public .
So, how can i access that file-class into my class ?
So, how can i share(send-receive) image and location message in chat ?
Please help me as soon as possible.
Thanks in advance.
try this link: reference
For File send
FileTransferManager manager = new FileTransferManager(connection);
OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer('usre2#myHost/Smack');
File file = new File(filenameWithPath);
try {
transfer.sendFile(file, 'test_file');
} catch (XMPPException e) {
e.printStackTrace();
}
while(!transfer.isDone()) {
if(transfer.getStatus().equals(Status.error)) {
System.out.println('ERROR!!! ' + transfer.getError());
} else if (transfer.getStatus().equals(Status.cancelled)
|| transfer.getStatus().equals(Status.refused)) {
System.out.println('Cancelled!!! ' + transfer.getError());
}
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if(transfer.getStatus().equals(Status.refused) || transfer.getStatus().equals(Status.error)
|| transfer.getStatus().equals(Status.cancelled)){
System.out.println('refused cancelled error ' + transfer.getError());
} else {
System.out.println('Success');
}
File Receive:
FileTransferManager manager = new FileTransferManager(connection);
manager.addFileTransferListener(new FileTransferListener() {
public void fileTransferRequest(final FileTransferRequest request) {
new Thread(){
#Override
public void run() {
IncomingFileTransfer transfer = request.accept();
File mf = Environment.getExternalStorageDirectory();
File file = new File(mf.getAbsoluteFile()+'/DCIM/Camera/' + transfer.getFileName());
try{
transfer.recieveFile(file);
while(!transfer.isDone()) {
try{
Thread.sleep(1000L);
}catch (Exception e) {
Log.e('', e.getMessage());
}
if(transfer.getStatus().equals(Status.error)) {
Log.e('ERROR!!! ', transfer.getError() + '');
}
if(transfer.getException() != null) {
transfer.getException().printStackTrace();
}
}
}catch (Exception e) {
Log.e('', e.getMessage());
}
};
}.start();
}
});
The FileTransferManager class have getInstanceFor(XMPPConnection connection) to get the instance of the FileTransferManager. Just provide a valid XMPPConnecton. e.g.
FileTransferManager ftm = FileTransferManager.getInstanceFor(connection)
See this link FileTransferManager too.
Hope this helps you.

Hold and Unhold sip call using the PJSIP

I developing VOIP android application that make and receive the sip call.I Build the pjsip lilbrary as described in "http://trac.pjsip.org/repos/wiki/Getting-Started/Android".
1. Hold
MainActivity.prm.setOptions(pjsua_call_flag.PJSUA_CALL_UPDATE_CONTACT
.swigValue());
try {
MainActivity.currentCall.setHold(MainActivity.prm);
} catch (Exception e) {
e.printStackTrace();
}
I found this code on pjsip documentation,but this code does not work for put a call on Hold.There is no error message return.
2.Unhold
MainActivity.prm = new CallOpParam(true);
MainActivity.prm.getOpt().setFlag(1);
try {
MainActivity.currentCall.reinvite(MainActivity.prm);
} catch (Exception e) {
e.printStackTrace();
}
Thanks.
Here is my code for hold and unHold:
public void setHold(boolean hold) {
if ((localHold && hold) || (!localHold && !hold)) return;
if(currentCall == null) return;
CallOpParam param = new CallOpParam(true);
try {
if (hold) {
currentCall.setHold(param);
localHold = true;
} else {
CallSetting opt = param.getOpt();
opt.setAudioCount(1);
opt.setVideoCount(0);
opt.setFlag(pjsua_call_flag.PJSUA_CALL_UNHOLD.swigValue());
currentCall.reinvite(param);
localHold = false;
}
} catch (Exception e) {}
}
I hope it's helpful.

How to retrieve the 'last sync' time for an account?

Is it possible to retrieve the time an account was last synchronized, like the system Settings->Accounts&Sync app does? I'm using Android 2.2.
Looking at the 2.2 source for AccountSyncSettings.java, I see the status is retrieved using:
SyncStatusInfo status = ContentResolver.getSyncStatus(account, authority);
but SyncStatusInfo and getSyncStatus don't seem to be part of the public API (marked with #hide). Is there some other way to get at this info?
You can use reflection to achieve this purpose.Here is my code to implement this
private long getLasySyncTime() {
long result = 0;
try {
Method getSyncStatus = ContentResolver.class.getMethod(
"getSyncStatus", Account.class, String.class);
if (mAccount != null && mSyncAdapter != null) {
Object status = getSyncStatus.invoke(null, mAccount,
mSyncAdapter.authority);
Class<?> statusClass = Class
.forName("android.content.SyncStatusInfo");
boolean isStatusObject = statusClass.isInstance(status);
if (isStatusObject) {
Field successTime = statusClass.getField("lastSuccessTime");
result = successTime.getLong(status);
TLog.d(WeixinSetting.class, "get last sync time %d", result);
}
}
} catch (NoSuchMethodException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
TLog.d(WeixinSetting.class, e.getMessage() + e.getCause().getMessage());
} catch (IllegalArgumentException e) {
} catch (ClassNotFoundException e) {
} catch (NoSuchFieldException e) {
} catch (NullPointerException e) {
}
return result;
}
The Settings app uses ContentResolver.getSyncStatus(account, authority). However, this is not part of the public API. You can use it, but it could break with any future release.

Categories

Resources