Commit 9288a2ad authored by Sergey Galin's avatar Sergey Galin

Merge branch 'feature/add_isvoicetelephonyavailable' into 'master'

Add QAndroidDesktopUtils::isVoiceTephonyAvailable()

See merge request !74
parents 91fba3d7 de5b6fa1
......@@ -241,13 +241,22 @@ bool dialPhoneNumber(const QString & number)
}
bool isVoiceTelephonyAvailable()
{
return QJniClass(c_full_class_name_).callStaticParamBoolean(
"isVoiceTelephonyAvailable"
, "Landroid/content/Context;"
, QAndroidQPAPluginGap::Context().jObject());
}
bool callPhoneNumber(const QString & number)
{
if (checkSelfPermission("android.permission.CALL_PHONE"))
{
if (!callNumber(number, QLatin1String("android.intent.action.CALL")))
{
qWarning() << "callPhoneNumber failed, falling back to dialPhoneNumber.";
qWarning() << "callPhoneNumber: failed, falling back to dialPhoneNumber.";
return dialPhoneNumber(number);
}
return true;
......
......@@ -87,6 +87,9 @@ bool callNumber(const QString & number, const QString & action = QString());
// Does the same as callNumber(number).
bool showPhoneNumber(const QString & number);
// Check if the device has a telephony capable of making voice calls.
bool isVoiceTelephonyAvailable();
// Opens the number with DIAL action, which usually does the same as showPhoneNumber() but may
// have a different effect if non-standard handler for tel: is used. Does not require any special
// permissions. In case of an error it falls back to showPhoneNumber().
......
......@@ -84,7 +84,7 @@ public class DesktopUtils
}
catch (final Throwable e)
{
Log.e(TAG, "IsInternetActive exception: "+e);
Log.e(TAG, "IsInternetActive exception: ", e);
}
return -1;
}
......@@ -107,7 +107,7 @@ public class DesktopUtils
}
catch (final Throwable e)
{
Log.e(TAG, "GetNetworkType exception: "+e);
Log.e(TAG, "GetNetworkType exception: ", e);
}
return -1;
}
......@@ -146,7 +146,7 @@ public class DesktopUtils
}
catch (final Throwable e)
{
Log.e(TAG, "sendTo exception: "+e);
Log.e(TAG, "sendTo exception: ", e);
return false;
}
}
......@@ -169,7 +169,7 @@ public class DesktopUtils
}
catch (final Throwable e)
{
Log.e(TAG, "sendSMS exception: "+e);
Log.e(TAG, "sendSMS exception: ", e);
return false;
}
}
......@@ -286,7 +286,7 @@ public class DesktopUtils
}
catch (final Throwable e)
{
Log.e(TAG, "sendEmail exception: "+e);
Log.e(TAG, "sendEmail exception: ", e);
return false;
}
}
......@@ -416,7 +416,7 @@ public class DesktopUtils
}
catch (final Throwable e)
{
Log.e(TAG, "openURL exception: "+e);
Log.e(TAG, "openURL exception: ", e);
return false;
}
}
......@@ -436,7 +436,7 @@ public class DesktopUtils
}
catch (final Throwable e)
{
Log.e(TAG, "Exception while opening a file: "+e);
Log.e(TAG, "Exception while opening a file: ", e);
return false;
}
}
......@@ -456,7 +456,7 @@ public class DesktopUtils
}
catch (final Throwable e)
{
Log.e(TAG, "Exception while installing apk: "+e);
Log.e(TAG, "Exception while installing apk: ", e);
return false;
}
}
......@@ -475,10 +475,46 @@ public class DesktopUtils
}
catch (final Throwable e)
{
Log.e(TAG, "Exception while uninstalling package: "+e);
Log.e(TAG, "Exception while uninstalling package: ", e);
}
}
// See: https://stackoverflow.com/questions/5196833/android-device-phone-call-ability
public static boolean isVoiceTelephonyAvailable(final Context ctx)
{
try
{
if (!ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY))
{
return false;
}
final TelephonyManager manager = (TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE);
if (manager == null)
{
return false;
}
if (manager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE)
{
return false;
}
if (Build.VERSION.SDK_INT >= 22) // Android 5.1+
{
if (!manager.isVoiceCapable())
{
return false;
}
}
return true;
}
catch (final Throwable e)
{
Log.e(TAG, "isVoiceTelephonyAvailable exception (will return 'false'): ", e);
return false;
}
}
// 'number' is an RFC-3966 URI without 'tel:'.
// If 'action' is null or empty string it defaults to Intent.ACTION_VIEW.
// See: http://tools.ietf.org/html/rfc3966
......@@ -497,7 +533,7 @@ public class DesktopUtils
}
catch (final Throwable e)
{
Log.e(TAG, "callNumber exception: "+e);
Log.e(TAG, "callNumber exception: ", e);
return false;
}
}
......@@ -515,7 +551,7 @@ public class DesktopUtils
}
catch (final Throwable e)
{
Log.e(TAG, "getTelephonyDeviceId exception: "+e);
Log.e(TAG, "getTelephonyDeviceId exception: ", e);
return "";
}
}
......@@ -560,7 +596,7 @@ public class DesktopUtils
}
catch (final Throwable e)
{
Log.e(TAG, "getAndroidId exception: "+e);
Log.e(TAG, "getAndroidId exception: ", e);
}
return "";
}
......@@ -577,7 +613,7 @@ public class DesktopUtils
}
catch (final Throwable e)
{
Log.e(TAG, "getBuildSerial exception: "+e);
Log.e(TAG, "getBuildSerial exception: ", e);
}
return "";
}
......@@ -597,7 +633,7 @@ public class DesktopUtils
}
catch (final Throwable e)
{
Log.e(TAG, "getInstalledAppsList exception: "+e);
Log.e(TAG, "getInstalledAppsList exception: ", e);
}
return "";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment