public static bool GetURIValue(ICursor cursor, Android.Net.Uri uri, IDIResultCallbacks resultCallbacks) { while (cursor.MoveToNext()) { if (cursor.ColumnCount == 0) { // No data in the cursor. I have seen this happen on non-WAN devices String errorMsg = "Error: " + uri + " does not exist on this device"; resultCallbacks.OnDebugStatus(errorMsg); } else { for (int i = 0; i < cursor.ColumnCount; i++) { try { String data = cursor.GetString(cursor.GetColumnIndex(cursor.GetColumnName(i))); resultCallbacks.OnSuccess(data); cursor.Close(); return(true); } catch (Exception e) { resultCallbacks.OnDebugStatus(e.Message); } } } } cursor.Close(); resultCallbacks.OnError("Data not found in Uri:" + uri); return(true); }
public void OnDebugStatus(string message) { if (callbackInterface != null) { callbackInterface.OnDebugStatus(message); } }
private static void RetrieveOEMInfo(Context context, Android.Net.Uri uri, IDIResultCallbacks callbackInterface) { // For clarity, this code calls ContentResolver.query() on the UI thread but production code should perform queries asynchronously. // See https://developer.android.com/guide/topics/providers/content-provider-basics.html for more information var cursor = context.ContentResolver.Query(uri, null, null, null, null); if (cursor == null || cursor.Count < 1) { if (callbackInterface != null) { callbackInterface.OnDebugStatus("App not registered to call OEM Service:" + uri.ToString() + "\nRegistering current application using profile manger, this may take a couple of seconds..."); } // Let's register the application RegisterCurrentApplication(context, uri, new ResultCallbacks(callbackInterface, context, uri, (cursor, uri, callbacks) => { GetURIValue(cursor, uri, callbacks); })); } else { // We have the right to call this service, and we obtained some data to parse... GetURIValue(cursor, uri, callbackInterface); } }