2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Tizen.PhonenumberUtils
22 /// The PhonenumberUtils class provides methods for parsing, formatting and normalizing phone numbers.
24 public class PhonenumberUtils : IDisposable
26 private bool disposed = false;
28 public PhonenumberUtils()
32 ret = Interop.PhonenumberUtils.Connect();
33 if (ret != (int)PhonenumberUtilsError.None)
35 Log.Error(Globals.LogTag, "Failed to connect, Error - " + (PhonenumberUtilsError)ret);
36 PhonenumberUtilsErrorFactory.ThrowPhonenumberUtilsException(ret);
46 /// Releases all resources used by the PhonenumberUtils.
47 /// It should be called after finished using of the object.
52 GC.SuppressFinalize(this);
55 private void Dispose(bool disposing)
60 // Free unmanaged objects
63 ret = Interop.PhonenumberUtils.Disconnect();
64 if (ret != (int)PhonenumberUtilsError.None)
65 Log.Error(Globals.LogTag, "Failed to disconnect, Error - " + (PhonenumberUtilsError)ret);
71 /// Gets the location string from number, region, and language.
73 /// <param name="number">The number</param>
74 /// <param name="region">The region of number</param>
75 /// <param name="language">The language of location</param>
76 /// <returns>The location string</returns>
77 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
78 /// <exception cref="NotSupportedException">Thrown when phonenumber-utils is not supported</exception>
79 /// <exception cref="ArgumentException">Thrown when input coordinates are invalid</exception>
80 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
81 public string GetLocationFromNumber(string number, Region region, Language language)
86 ret = Interop.PhonenumberUtils.GetLocationFromNumber(number, (int)region, (int)language, out result);
87 if (ret != (int)PhonenumberUtilsError.None)
89 Log.Error(Globals.LogTag, "Failed to get location, Error - " + (PhonenumberUtilsError)ret);
90 PhonenumberUtilsErrorFactory.ThrowPhonenumberUtilsException(ret);
97 /// Gets the formatted number.
99 /// <param name="number">The number</param>
100 /// <param name="region">The region of number</param>
101 /// <returns>The formatted number string</returns>
102 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
103 /// <exception cref="NotSupportedException">Thrown when phonenumber-utils is not supported</exception>
104 /// <exception cref="ArgumentException">Thrown when input coordinates are invalid</exception>
105 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
106 public string GetFormattedNumber(string number, Region region)
111 ret = Interop.PhonenumberUtils.GetFormmatedNumber(number, (int)region, out result);
112 if (ret != (int)PhonenumberUtilsError.None)
114 Log.Error(Globals.LogTag, "Failed to get formatted number, Error - " + (PhonenumberUtilsError)ret);
115 PhonenumberUtilsErrorFactory.ThrowPhonenumberUtilsException(ret);
122 /// Gets the normalized number.
124 /// <param name="number">The number</param>
125 /// <returns>The normalized number</returns>
126 /// <privilege>http://tizen.org/privilege/telephony</privilege>
127 /// <feature>http://tizen.org/feature/network.telephony</feature>
128 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
129 /// <exception cref="NotSupportedException">Thrown when phonenumber-utils is not supported</exception>
130 /// <exception cref="ArgumentException">Thrown when input coordinates are invalid</exception>
131 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
132 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
134 /// Normalized number starts with plus('+') and country code, and excludes the separators such as dash or space.
135 /// It is a format of E.164 standard including the country code based on current network.
137 public string GetNormalizedNumber(string number)
142 ret = Interop.PhonenumberUtils.GetNormailizedNumber(number, out result);
143 if (ret != (int)PhonenumberUtilsError.None)
145 Log.Error(Globals.LogTag, "Failed to get normalized number, Error - " + (PhonenumberUtilsError)ret);
146 PhonenumberUtilsErrorFactory.ThrowPhonenumberUtilsException(ret);