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);
51 /// <since_tizen> 4 </since_tizen>
58 /// Releases all resources used by the PhonenumberUtils.
59 /// It should be called after finished using of the object.
61 /// <since_tizen> 4 </since_tizen>
65 GC.SuppressFinalize(this);
68 private void Dispose(bool disposing)
73 // Free unmanaged objects
76 ret = Interop.PhonenumberUtils.Disconnect();
77 if (ret != (int)PhonenumberUtilsError.None)
78 Log.Error(Globals.LogTag, "Failed to disconnect, Error - " + (PhonenumberUtilsError)ret);
84 /// Gets the location string from number, region, and language.
86 /// <param name="number">The number</param>
87 /// <param name="region">The region of number</param>
88 /// <param name="language">The language of location</param>
89 /// <returns>The location string</returns>
90 /// <feature>http://tizen.org/feature/network.telephony</feature>
91 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
92 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
93 /// <exception cref="ArgumentException">Thrown when input coordinates are invalid</exception>
94 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
95 /// <since_tizen> 4 </since_tizen>
96 public string GetLocationFromNumber(string number, Region region, Language language)
101 ret = Interop.PhonenumberUtils.GetLocationFromNumber(number, (int)region, (int)language, out result);
102 if (ret != (int)PhonenumberUtilsError.None)
104 Log.Error(Globals.LogTag, "Failed to get location, Error - " + (PhonenumberUtilsError)ret);
105 PhonenumberUtilsErrorFactory.ThrowPhonenumberUtilsException(ret);
112 /// Gets the formatted number.
114 /// <param name="number">The number</param>
115 /// <param name="region">The region of number</param>
116 /// <returns>The formatted number string</returns>
117 /// <feature>http://tizen.org/feature/network.telephony</feature>
118 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
119 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
120 /// <exception cref="ArgumentException">Thrown when input coordinates are invalid</exception>
121 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
122 /// <since_tizen> 4 </since_tizen>
123 public string GetFormattedNumber(string number, Region region)
128 ret = Interop.PhonenumberUtils.GetFormmatedNumber(number, (int)region, out result);
129 if (ret != (int)PhonenumberUtilsError.None)
131 Log.Error(Globals.LogTag, "Failed to get formatted number, Error - " + (PhonenumberUtilsError)ret);
132 PhonenumberUtilsErrorFactory.ThrowPhonenumberUtilsException(ret);
139 /// Gets the normalized number.
141 /// <param name="number">The number</param>
142 /// <returns>The normalized number</returns>
143 /// <privilege>http://tizen.org/privilege/telephony</privilege>
144 /// <feature>http://tizen.org/feature/network.telephony</feature>
145 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
146 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
147 /// <exception cref="ArgumentException">Thrown when input coordinates are invalid</exception>
148 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
149 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
151 /// Normalized number starts with plus('+') and country code, and excludes the separators such as dash or space.
152 /// It is a format of E.164 standard including the country code based on current network.
154 /// <since_tizen> 4 </since_tizen>
155 public string GetNormalizedNumber(string number)
160 ret = Interop.PhonenumberUtils.GetNormailizedNumber(number, out result);
161 if (ret != (int)PhonenumberUtilsError.None)
163 Log.Error(Globals.LogTag, "Failed to get normalized number, Error - " + (PhonenumberUtilsError)ret);
164 PhonenumberUtilsErrorFactory.ThrowPhonenumberUtilsException(ret);