Skip to content

Instantly share code, notes, and snippets.

@richard1122
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richard1122/ba71d2577b1e606a4bc9 to your computer and use it in GitHub Desktop.
Save richard1122/ba71d2577b1e606a4bc9 to your computer and use it in GitHub Desktop.
Android snippet
/**
* get device id, if not available get Build.SERIAL.
* http://stackoverflow.com/questions/16078269/android-unique-serial-number
* @param context
* @return a string indicate a unique device
*/
public static String getDeviceID(final Context context) {
final String deviceID = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
if (deviceID != null)
return deviceID;
else
return Build.SERIAL;
}
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, mContext.getResources().getDisplayMetrics());
public class BitmapUtils {
public static Bitmap drawableToBitmap(final Drawable d) {
if (d instanceof BitmapDrawable)
return ((BitmapDrawable) d).getBitmap();
if (d instanceof ColorDrawable) //TODO: working to support color drawable
return null;
final Bitmap bitmap = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
d.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
d.draw(canvas);
return bitmap;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment