public void OnError(string message) { if (callbackInterface != null) { callbackInterface.OnError(message); return; } }
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); }
private static void RegisterCurrentApplication(Context context, Android.Net.Uri serviceIdentifier, IDIResultCallbacks callbackInterface) { var profileName = "AccessMgr-1"; var profileData = ""; try { var packageInfo = context.PackageManager.GetPackageInfo(context.PackageName, PackageInfoFlags.SigningCertificates); var path = context.ApplicationInfo.SourceDir; var strName = packageInfo.ApplicationInfo.LoadLabel(context.PackageManager).ToString(); var strVendor = packageInfo.PackageName; var sig = DIHelper.apkCertificate; // Let's check if we have a custom certificate if (sig == null) { // Nope, we will get the first apk signing certificate that we find // You can copy/paste this snippet if you want to provide your own // certificate // TODO: use the following code snippet to extract your custom certificate if necessary var arrSignatures = packageInfo.SigningInfo.GetApkContentsSigners(); if (arrSignatures == null || arrSignatures.Length == 0) { if (callbackInterface != null) { callbackInterface.OnError("Error : Package has no signing certificates... how's that possible ?"); return; } } sig = arrSignatures[0]; } /* * Get the X.509 certificate. */ var rawCert = sig.ToByteArray(); // Get the certificate as a base64 string var encoded = Base64.EncodeToString(rawCert, Base64Flags.Default); profileData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<characteristic type=\"Profile\">" + "<parm name=\"ProfileName\" value=\"" + profileName + "\"/>" + "<characteristic type=\"AccessMgr\" version=\"9.2\">" + "<parm name=\"OperationMode\" value=\"1\" />" + "<parm name=\"ServiceAccessAction\" value=\"4\" />" + "<parm name=\"ServiceIdentifier\" value=\"" + serviceIdentifier + "\" />" + "<parm name=\"CallerPackageName\" value=\"" + context.PackageName.ToString() + "\" />" + "<parm name=\"CallerSignature\" value=\"" + encoded + "\" />" + "</characteristic>" + "</characteristic>"; DIProfileManagerCommand profileManagerCommand = new DIProfileManagerCommand(context); profileManagerCommand.execute(profileData, profileName, callbackInterface); } catch (Exception e) { if (callbackInterface != null) { callbackInterface.OnError("Error on profile: " + profileName + "\nError:" + e.Message + "\nProfileData:" + profileData); } } }