CreateTransportFailure with PortSip - android

I am trying to create a basic calling app on Android with PortSip but get an error from the setUser method (error -60098: CreateTransportFailure). I think I've followed all the steps as their sample app, and I've used the same credentials that work with the sample app. I've tried using a different local port (as suggested in another post), but haven't had any success. These are my steps:
context = this.getApplicationContext();
callingSDK = new PortSipSdk();
callingSDK.setOnPortSIPEvent(this);
callingSDK.CreateCallManager(context);
int initStatus = callingSDK.initialize(PortSipEnumDefine.ENUM_TRANSPORT_UDP,
"0.0.0.0", 5771, PortSipEnumDefine.ENUM_LOG_LEVEL_DEBUG, LogPath, 200,
"PortSIP VoIP Calling App", 0, 0, "", "", false);
// initialize returns ECoreErrorNone
callingSDK.setSrtpPolicy(PortSipEnumDefine.ENUM_SRTPPOLICY_NONE);
int licenseStatus = callingSDK.setLicenseKey("PORTSIP_TEST_LICENSE");
// setLicenseKey return ECoreTrialVersionLicenseKey, as expected
int userStatus = callingSDK.setUser(accountName, displayName, authName, password,
domain, server, 5060, "", 0, null, 5060);

Apparently, another factor in this error condition is assuring the app that the appropriate permissions. Adding these to the manifest gets past the issue with setUser.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />

Related

.net Maui - basic web request

Ive been playing with .net Maui and had some success doing Bluetooth LE but for reasons I've gone ahead and changed my implementation to use wifi and a restful API. I am building for both android and IoS. I am testing with a real device, running android 12.
I am trying to make a basic http(s) (tried both http and https) request to a local server (an esp32). My url is:
const string url = "https://192.168.4.1/api";
My manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="28" android:targetSdkVersion="31" />
<application android:allowBackup="true" android:icon="#mipmap/appicon" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
My initialisation function, which gets called when my page is loaded - MainPage()
private void init_network()
{
client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
}
and finally, my send function which gets called by a button pressed event
private bool SendCommand(string command)
{
try
{
var msg = new HttpRequestMessage(HttpMethod.Post, url);
msg.Content = JsonContent.Create(command);
HttpResponseMessage response = client.Send(msg); // line where the code throws exception
if (response.IsSuccessStatusCode)
{
return true;
}
}
catch (Exception err)
{
Console.WriteLine(err.Message);
}
return false;
}
I also have a runtime permissions section which asks for location_fine_access, which I've given access for.
When running through the request function, I get an exception thrown with the message:
[DOTNET] Operation is not supported on this platform.
I thought this was a permissions issue, and so android isn't letting me make the request but now I'm not so sure. Anyone else had and resolved this issue?
Looks as though .net maui doesnt hook into the android http client properly and is an issue on github. https://github.com/dotnet/maui/issues/1260
the suggested work around, which I have tested and works for me, is to instantiate your HttpClient with the native android handler like this as a workaround:
new HttpClient(new Xamarin.Android.Net.AndroidMessageHandler()).

Android-9 CallLog: CACHED_NAME and CACHED_PHOTO_URI always return NULL from CallLog

I had an app where I fetched Call Log and Contact List and showed them in a RecyclerView. Everything was going fine up to android-8. Suddenly I found that Names are not showing on an Android-9 Device. Then a debug shows that CACHED_NAME and CACHED_PHOTO_URI are always returning null on andorid-9.
I get NUMBER, DURATION and every other thing very well, only the CACHED_NAME and CACHED_PHOTO_URI are missing.
I have checked the changelog of android-9, handled the calllog permission properly, I'm attaching my permissions from manifest with this question. My app is properly taking runtime permissions too. I also checked it on device's Settings. In addition, my app is also set to Default Phone app.
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
String number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));
String name = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME));
Log.d("tag", "name: " + (name == null ? "null": name));
String date = cursor.getString(cursor.getColumnIndex(CallLog.Calls.DATE));
String duration = cursor.getString(cursor.getColumnIndex(CallLog.Calls.DURATION));
String photoUri = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_PHOTO_URI));
Log.d("tag", "photoUri: " + (photoUri == null ? "null": photoUri));
String subscription_id = cursor.getString(cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID));
String subscription_component_name = cursor.getString(cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_COMPONENT_NAME));
Its working fine on android 8 and below, can anyone tell me where is the problem with android-9?
Please check that if needs RuntimePermission for CALL_LOG GROUP. Because they made some changes on Android-9
first, get contacts from Contacts.Contract and then get name, photo by phone number, or contact Id from the database.

Android M 6.0: cannot remove accounts : java.lang.SecurityException

On Marshmallow, i fell on this Exception when I add a google account type:
" java.lang.SecurityException: uid 10121 cannot remove accounts of
type: com.google at "
I add the accound using
mAccountManager.addAccount("com.google", null, null, null, activity.this, null, null);
And sometime i need to delete all accounts using
mAccountManager.removeAccount(account, this, null, null);
the app has Admin role, and all permissions is think about:
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
i asked the user for :
Manifest.permission.GET_ACCOUNTS,Manifest.permission.READ_PHONE_STATE,Manifest.permission.WRITE_EXTERNAL_STORAGE
How to delete account managed by google authenticator ...?
all is working well on Lollipop, of course
thanks !

HTML5 getCurrentPosition on PhoneGap going to error handler with weird null error, on Android only

I have a PhoneGap application which immediately sets window.location to be my on-internet site and carries on working from there. The app works great except for the following very strange behaviour.
I'm trying to get a geolocation by calling:
function geoErrorHandler(error) {
console.log("getCurrentPosition failed with error message: " + error.message);
}
function showPosition(position) {
// blah
}
var options = {maximumAge:60000, timeout:5000, enableHighAccuracy:true};
navigator.geolocation.getCurrentPosition(showPosition, geoErrorHander, options);
On iOS it works fine in my PhoneGap app. It also works fine when the page is just loaded in a desktop browser. On my Android PhoneGap app, however, it calls my geoErrorHandler. Which is fine - surely I can find out then what the problem was! Except it calls it with an error which has error.message = "" and error.code = null. Hrhum.
It's doing this on two separate devices and a fair amount of internet searching doesn't seem to reveal anyone else with this behaviour. What am I doing wrong?!
Maybe a permission problem?
Try adding to your manifest ACCESS_COARSE_LOCATION, ACCESS_LOCATION_EXTRA_COMMANDS and ACCESS_FINE_LOCATION permissions
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
http://developer.android.com/reference/android/Manifest.permission.html

PhoneGap check Internet connection on device vs mobile browser

I am new to Phonegap and JqueryMobile. I need to check the internet connection on device. After seeing some solution on net I got confused about approaches. some solutions is suggesting to use PG API like network manager and connection while some using JQMobile method to check connection.
My question is which to prefer ? or what are the target areas for both the implementation ?
PhoneGap have own function to check Internet connection available or not.Here is that official document.
Check Internet is Online document.addEventListener("online", onOnline, false);
Check Internet is Offline document.addEventListener("offline", onOffline, false);
You need to set
<plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager" /> permission in config.xml for android.
You have to add some permission in manifest as below,
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"> </uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"> </uses-permission>
<uses-permission android:name="android.permission.INTERNET" />
Try this
Working example: http://jsfiddle.net/Gajotres/d5XYR/
In this case timer will check internet connection every 100 ms and set final result into a javascript global variable.
Everything depends on this line:
window.navigator.onLine -- it will be false if the user is offline.
Final solution:
var connectionStatus = false;
$(document).on('pagebeforeshow', '#index', function () {
setInterval(function () {
connectionStatus = navigator.onLine ? 'online' : 'offline';
}, 100);
$(document).on('click', '#check-connection', function () {
alert(connectionStatus);
});
});

Categories

Resources