I have try a sinch video calling example in my project but , I can't understand what is CALL_ID in sinchservice class in sinch video calling example.
That is just custom field name which will be sent when you receive call. It stores unique call id received from Sinch for calling. You can check it in SinchService.java
public static final String CALL_ID = "CALL_ID";
and when you receive call, unique call id will be passed as extra in Intent.
#Override
public void onIncomingCall(CallClient callClient, Call call) {
Log.d(TAG, "Incoming call");
Intent intent = new Intent(SinchService.this, IncomingCallScreenActivity.class);
intent.putExtra(CALL_ID, call.getCallId());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
SinchService.this.startActivity(intent);
}
Related
I'm developing a program in Android Studio to connect to a specific BLE device. I'm using setresult() to return the BLE device name etc once the BLE device is discovered. Unfortunately, setresult() is giving an error:
Error:(201, 25) error: method setResult in class BroadcastReceiver cannot be applied to given types;
required: int,String,Bundle,found: int,Intent, reason: actual and formal argument lists differ in length
Why is there an error and how do I resolve it?
private final BroadcastReceiver bleServiceReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent sintent) {
final String action = sintent.getAction();
if (MldpBluetoothService.ACTION_BLE_SCAN_RESULT.equals(action)) { //Service has sent a scan result
Log.d(TAG, "Scan scan result received");
final BleDevice device = new BleDevice(sintent.getStringExtra(MldpBluetoothService.INTENT_EXTRA_SERVICE_ADDRESS), sintent.getStringExtra(MldpBluetoothService.INTENT_EXTRA_SERVICE_NAME)); //Create new item to hold name and address
if(device.getName() != null) {
if (device.getName().contains("Prodigy")) { //+++++ Added by Chris
bleDeviceListAdapter.addDevice(device); //+++++ if Prodigy add to the device to list adapter that displays a list on the screen
bleDeviceListAdapter.notifyDataSetChanged(); //+++++ Refresh the list on the screen
scanStopHandler.removeCallbacks(stopScan); //Stop the scan timeout handler from calling the runnable to stop the scan
scanStop();
final Intent intent = new Intent(); //Create Intent to return information to the MldpTerminalActivity that started this activity
intent.putExtra(INTENT_EXTRA_SCAN_AUTO_CONNECT, alwaysConnectCheckBox.isChecked()); //Add to the Intent whether to automatically connect next time
intent.putExtra(INTENT_EXTRA_SCAN_NAME, device.getName()); //Add BLE device name to the intent
intent.putExtra(INTENT_EXTRA_SCAN_ADDRESS, device.getAddress()); //Add BLE device address to the intent
setResult(Activity.RESULT_OK, intent); //Return an intent to the calling activity with the selected BLE name and address
finish();
}
}
}
}
};
As your code is placed in broadcastReceiver, you are using the setResult() for BroadcastReceiver.
If this broadcastReceiver is in your activity, please try
YourActivity.this.setResult();
If it is outside your activity, you may need to keep the activity reference in broadcastReceiver for calling
yourActivityReference.setResult();
I have IOS and Android app using sinch video and Audio (App to App ) calling integrated.
isVideoOffered() Bool always gives video irrespective of incoming call.I want to receive audio screen when audio call is called from another app(Android/IOS) and video if video call is initiated from another app(Android/IOS).
Code for Android to differentiate incoming call(video or audio)
public void onIncomingCall(CallClient callClient, Call call) {
if( call.getDetails().isVideoOffered()){
Log.d(TAG, "Incoming call");
Intent intent = new Intent(SinchService.this, IncomingCallScreenActivityVideo.class);
intent.putExtra(CALL_ID, call.getCallId());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
SinchService.this.startActivity(intent);
}
else
{
Log.d(TAG, "Incoming audio call");
Intent intent = new Intent(SinchService.this, IncomingCallScreenActivity.class);
intent.putExtra(CALL_ID, call.getCallId());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
SinchService.this.startActivity(intent);
}
}
Code for IOS to differentiate incoming call(video or audio)
#pragma mark - SINCallClientDelegate
- (void)client:(id<SINCallClientDelegate>)client didReceiveIncomingCall:(id<SINCall>)call {
if (call.details.applicationStateWhenReceived == UIApplicationStateActive) {
if([call.details isVideoOffered]) {
[self performSegueWithIdentifier:#"callView" sender:call];
}
else
{
[self performSegueWithIdentifier:#"audioCallView" sender:call];
}
}
else {
[call answer];
}
}
I can confirm that this is a bug and we will fix it for a future beta release.
I suggest using your VideoActivity layouts and classes for handling both the calls because when an audio call is received, the video portions remain hidden in your layout..
Additionally, you can set an icon that can tell you whether you're on Video Call or not.. I mean you can do somethink like.
#Override
public void onVideoTrackAdded(Call call) {
// Display some kind of icon showing it's a video call
isVideo=true;
}
I am starting the service , and I put a message in extra,
Intent mServiceIntent = new Intent(this, TextToSpeechService.class);
mServiceIntent.putExtra(Intent.EXTRA_TEXT, "a message");
mServiceIntent.setType(HTTP.PLAIN_TEXT_TYPE);
this.startService(mServiceIntent);
but running , the service starts and the log shows a message = null...
public class MyService extends IntentService {
static final String TAG = "MyService";
public MyService() {
super("My Service");
}
#Override
protected void onHandleIntent(Intent intent) {
String message = intent.getStringExtra("message");
Log.d(TAG, "received message, should say: " + message);
}
could it be related to the MIME TYPE, when I state mServiceIntent.setType(HTTP.PLAIN_TEXT_TYPE);
( using import org.apache.http.protocol.HTTP;)
As #Squonk already mentioned your code doesn't really go together. To start your Service you have to use an Intent like this:
// The class you set here determines where the Intent will go.
// You want it to start MyService so we write MyService.class here.
Intent intent = new Intent(this, MyService.class);
intent.putExtra(Intent.EXTRA_TEXT, "a message");
startService(intent);
You can very well use the Intent.EXTRA_TEXT constant as key for your extra, but you have to use the same key to retrieve the message in your Service:
#Override
protected void onHandleIntent(Intent intent) {
String message = intent.getStringExtra(Intent.EXTRA_TEXT);
Log.d(TAG, "received message, should say: " + message);
}
The code in your MyService doesn't really show if you actually use the mime type in your MyService so I removed it from my example above.
I use Retrofit to connect my app to a webbackend. We use the asynchronous callback methods to do requests at different points in the app.
How would I add a listener that is notified every time a http-request fails.
My current idea is to create a custom callback class that all callbacks in my app must extend. This callback will inform my listener on every failure.
If I change all Interface to only except subtypes of this class and make the failure and success method final - with a callback to an abstract method - it should not be possible to miss a call in the whole application.
Is there a simpler way then this?
The easy approach to do this is using a callback, but you can also send an event to your activity using any event framework or using a local event broadcast such as:
to send the event you have to use something like:
private void sendMessage() {
Intent intent = new Intent("event-networkerror");
intent.putExtra("message", "data");
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}
To subscribe to the event:
public void onResume() {
super.onResume();
// Register mMessageReceiver to receive messages.
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
new IntentFilter("event-networkerror"));
}
// handler for received Intents for the "my-event" event
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
// Extract data included in the Intent
String message = intent.getStringExtra("message");
Log.d("receiver", "Got message: " + message);
}
};
protected void onPause() {
// Unregister since the activity is not visible
LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
super.onPause();
}
You can use the ErrorHandler to send the broadcast:
class MyErrorHandler implements ErrorHandler {
public Throwable handleError(RetrofitError cause) {
Response r = cause.getResponse();
// process error r.getStatus()
Intent intent = new Intent("event-networkerror");
intent.putExtra("status",r.getStatus());
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
return cause;
}
}
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("...")
.setErrorHandler(new MyErrorHandler())
.build();
Im developing an application,which blocks all outgoing calls and then after blocking that call ,another new call is initiated to a predefined number...
My problem is that,when i block the call using a broadcastreceiver,the second call which i programmatically initiate is also getting blocked...
Is any method to unregister the broadcast after blocking the first call,or any other method or technique???
This is my broadcastreceiver which i implemented for my app...
public class CallListenerActivity extends BroadcastReceiver {
Uri uri;
#Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if(bundle == null)
return;
String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.i("###OutgoingCallReceiver",phonenumber);
Log.i("###OutgoingCallReceiver",bundle.toString());
String info = "Detect Calls sample application\nOutgoing number: " + phonenumber;
Toast.makeText(context, info, Toast.LENGTH_LONG).show();
String phoneNumber = "5556";
Uri uri = Uri.fromParts("tel", phoneNumber, null);
Intent callIntent = new Intent(Intent.ACTION_CALL, uri);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callIntent);
}
You could try starting your original (CallListenerActivity? The one which registered the broadcast receiver) activity again using a flag stored as extra in the intent.
Evaluate the intent in your activity and unregister the broadcast receiver if you see the flag in the extras. Then start the the call activity as shown in your example code.
You can use store a check when you are initiating a call and after the completion of the call mark it. For this this check you can use SharedPreference.