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 /// <since_tizen> 4 </since_tizen>
25 public class PhonenumberUtils : IDisposable
27 private bool disposed = false;
30 /// Creates a PhonenumberUtils.
32 /// <feature>http://tizen.org/feature/network.telephony</feature>
33 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
34 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
35 /// <since_tizen> 4 </since_tizen>
36 public PhonenumberUtils()
40 ret = Interop.PhonenumberUtils.Connect();
41 if (ret != (int)PhonenumberUtilsError.None)
43 Log.Error(Globals.LogTag, "Failed to connect, Error - " + (PhonenumberUtilsError)ret);
44 PhonenumberUtilsErrorFactory.ThrowPhonenumberUtilsException(ret);
54 /// Releases all resources used by the PhonenumberUtils.
55 /// It should be called after finished using of the object.
57 /// <since_tizen> 4 </since_tizen>
61 GC.SuppressFinalize(this);
64 private void Dispose(bool disposing)
69 // Free unmanaged objects
72 ret = Interop.PhonenumberUtils.Disconnect();
73 if (ret != (int)PhonenumberUtilsError.None)
74 Log.Error(Globals.LogTag, "Failed to disconnect, Error - " + (PhonenumberUtilsError)ret);
80 /// Gets the location string from number, region, and language.
82 /// <param name="number">The number</param>
83 /// <param name="region">The region of number</param>
84 /// <param name="language">The language of location</param>
85 /// <returns>The location string</returns>
86 /// <feature>http://tizen.org/feature/network.telephony</feature>
87 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
88 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
89 /// <exception cref="ArgumentException">Thrown when input coordinates are invalid</exception>
90 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
91 /// <since_tizen> 4 </since_tizen>
92 public string GetLocationFromNumber(string number, Region region, Language language)
97 ret = Interop.PhonenumberUtils.GetLocationFromNumber(number, (int)region, (int)language, out result);
98 if (ret != (int)PhonenumberUtilsError.None)
100 Log.Error(Globals.LogTag, "Failed to get location, Error - " + (PhonenumberUtilsError)ret);
101 PhonenumberUtilsErrorFactory.ThrowPhonenumberUtilsException(ret);
108 /// Gets the formatted number.
110 /// <param name="number">The number</param>
111 /// <param name="region">The region of number</param>
112 /// <returns>The formatted number string</returns>
113 /// <feature>http://tizen.org/feature/network.telephony</feature>
114 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
115 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
116 /// <exception cref="ArgumentException">Thrown when input coordinates are invalid</exception>
117 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
118 /// <since_tizen> 4 </since_tizen>
119 public string GetFormattedNumber(string number, Region region)
124 ret = Interop.PhonenumberUtils.GetFormmatedNumber(number, (int)region, out result);
125 if (ret != (int)PhonenumberUtilsError.None)
127 Log.Error(Globals.LogTag, "Failed to get formatted number, Error - " + (PhonenumberUtilsError)ret);
128 PhonenumberUtilsErrorFactory.ThrowPhonenumberUtilsException(ret);
135 /// Gets the normalized number.
137 /// <param name="number">The number</param>
138 /// <returns>The normalized number</returns>
139 /// <privilege>http://tizen.org/privilege/telephony</privilege>
140 /// <feature>http://tizen.org/feature/network.telephony</feature>
141 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
142 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
143 /// <exception cref="ArgumentException">Thrown when input coordinates are invalid</exception>
144 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
145 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
147 /// Normalized number starts with plus('+') and country code, and excludes the separators such as dash or space.
148 /// It is a format of E.164 standard including the country code based on current network.
150 /// <since_tizen> 4 </since_tizen>
151 public string GetNormalizedNumber(string number)
156 ret = Interop.PhonenumberUtils.GetNormailizedNumber(number, out result);
157 if (ret != (int)PhonenumberUtilsError.None)
159 Log.Error(Globals.LogTag, "Failed to get normalized number, Error - " + (PhonenumberUtilsError)ret);
160 PhonenumberUtilsErrorFactory.ThrowPhonenumberUtilsException(ret);