本文整理汇总了C#中Java.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# Java.GetBytes方法的具体用法?C# Java.GetBytes怎么用?C# Java.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Java
的用法示例。
在下文中一共展示了Java.GetBytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMD5
public static string GetMD5 (Java.Lang.String s)
{
try {
// Create MD5 Hash
var digest = Java.Security.MessageDigest.GetInstance ("MD5");
digest.Update (s.GetBytes ());
var messageDigest = digest.Digest ();
// Create Hex String
var hexString = new Java.Lang.StringBuffer ();
for (int i = 0; i < messageDigest.Length; i++) {
var h = Java.Lang.Integer.ToHexString (0xFF & messageDigest [i]);
while (h.Length < 2) {
h = "0" + h;
}
hexString.Append (h);
}
return hexString.ToString ();
} catch (Java.Security.NoSuchAlgorithmException ex) {
Log.Debug (TAG, ex.StackTrace);
}
return "";
}
示例2: FetchImage
/**
* Only call this method from the main (UI) thread. The {@link OnFetchCompleteListener} callback
* be invoked on the UI thread, but image fetching will be done in an {@link AsyncTask}.
*
* @param cookie An arbitrary object that will be passed to the callback.
*/
public static void FetchImage(Context context, Java.Lang.String url, BitmapFactory.Options decodeOptions, Java.Lang.Object cookie, Action<Bitmap> callback)
{
Task.Factory.StartNew(() => {
if(TextUtils.IsEmpty(url))
{
result = null;
return;
}
File cacheFile = null;
try
{
MessageDigest mDigest = MessageDigest.GetInstance("SHA-1");
mDigest.Update(url.GetBytes());
string cacheKey = BytesToHexString(mDigest.Digest());
if(Environment.MediaMounted.Equals(Environment.ExternalStorageState))
{
cacheFile = new File(Environment.ExternalStorageDirectory +
File.Separator + "Android " +
File.Separator + "data" +
File.Separator + context.PackageName +
File.Separator + "cache" +
File.Separator + "bitmap_" + cacheKey + ".tmp");
}
}
catch (Exception e)
{
// NoSuchAlgorithmException
// Oh well, SHA-1 not available (weird), don't cache bitmaps.
}
if (cacheFile != null && cacheFile.Exists())
{
Bitmap cachedBitmap = BitmapFactory.DecodeFile(cacheFile.ToString(), decodeOptions);
if (cachedBitmap != null) {
result = cachedBitmap;
return;
}
}
try
{
// TODO: check for HTTP caching headers
var client = new System.Net.WebClient();
var image = client.DownloadData(new Uri(url.ToString()));
if (image != null)
{
result = null;
return;
}
// Write response bytes to cache.
if (cacheFile != null) {
try {
cacheFile.ParentFile.Mkdirs();
cacheFile.CreateNewFile();
FileOutputStream fos = new FileOutputStream(cacheFile);
fos.Write(image);
fos.Close();
} catch (FileNotFoundException e) {
Log.Warn(TAG, "Error writing to bitmap cache: " + cacheFile.ToString(), e);
} catch (IOException e) {
Log.Warn(TAG, "Error writing to bitmap cache: " + cacheFile.ToString(), e);
}
}
// Decode the bytes and return the bitmap.
result = (BitmapFactory.DecodeByteArray(image, 0, image.Length, decodeOptions));
return;
} catch (Exception e) {
Log.Warn(TAG, "Problem while loading image: " + e.ToString(), e);
}
result = null;
})
.ContinueWith(task =>
callback(result)
);
}
示例3: SendMessage
/// <summary>
/// Sends a message.
/// </summary>
/// <param name='message'>
/// A string of text to send.
/// </param>
private void SendMessage (Java.Lang.String message)
{
// Check that we're actually connected before trying anything
if (chatService.GetState () != BluetoothChatService.STATE_CONNECTED) {
Toast.MakeText (this, Resource.String.not_connected, ToastLength.Short).Show ();
return;
}
// Check that there's actually something to send
if (message.Length () > 0) {
// Get the message bytes and tell the BluetoothChatService to write
byte[] send = message.GetBytes ();
chatService.Write (send);
// Reset out string buffer to zero and clear the edit text field
outStringBuffer.SetLength (0);
outEditText.Text = string.Empty;
}
}