本文整理汇总了Java中android.os.Build类的典型用法代码示例。如果您正苦于以下问题:Java Build类的具体用法?Java Build怎么用?Java Build使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Build类属于android.os包,在下文中一共展示了Build类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1:
import android.os.Build; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public void onChildViewAdded(View parent, View child) {
if (parent == RelativeRadioGroup.this && child instanceof RadioButton) {
int id = child.getId();
// generates an id if it's missing
if (id == View.NO_ID) {
id = View.generateViewId();
child.setId(id);
}
((RadioButton) child).setOnCheckedChangeListener(mChildOnCheckedChangeListener);
}
if (mOnHierarchyChangeListener != null) {
mOnHierarchyChangeListener.onChildViewAdded(parent, child);
}
}
示例2: postOnAnimation
import android.os.Build; //导入依赖的package包/类
private void postOnAnimation(View view, Runnable runnable) {
if (Build.VERSION.SDK_INT >= 16) {
view.postOnAnimation(runnable);
} else {
view.postDelayed(runnable, 16L);
}
}
示例3: finishActivitySync
import android.os.Build; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
static public void finishActivitySync(Activity activity, Instrumentation instrumentation, boolean doFinish)
{
if (doFinish)
activity.finish();
//give activity one minute to finish
long currentTime = System.currentTimeMillis();
boolean finishTimeout = false;
int activityHash = activity.hashCode();
boolean isDestroyed = false;
while (!isDestroyed && !finishTimeout) {
instrumentation.waitForIdleSync();
finishTimeout = (System.currentTimeMillis() - currentTime) > 140000;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
isDestroyed = activity.isDestroyed();
}else {
isDestroyed = (Boolean)callMethod(null, activity.getWindow(), "isDestroyed", null);
}
}
if (finishTimeout) {
WebtrekkLogging.log("finishActivitySync: finished by timeout. Hash:" + activityHash);
}
}
示例4: init
import android.os.Build; //导入依赖的package包/类
private void init(Context context) {
if (notification_panel_width == 0) {
Context systemUi = null;
try {
systemUi = context.createPackageContext("com.android.systemui", Context.CONTEXT_IGNORE_SECURITY);
} catch (PackageManager.NameNotFoundException e) {
}
if (Build.VERSION.SDK_INT <= 19) {
notification_side_padding = 0;
} else {
notification_side_padding = getDimem(context, systemUi, "notification_side_padding",
R.dimen.notification_side_padding);
}
notification_panel_width = getDimem(context, systemUi, "notification_panel_width",
R.dimen.notification_panel_width);
if (notification_panel_width <= 0) {
notification_panel_width = context.getResources().getDisplayMetrics().widthPixels;
}
notification_min_height = getDimem(context, systemUi, "notification_min_height",
R.dimen.notification_min_height);
// getDimem(context, systemUi, "notification_row_min_height", 0);
// if (notification_min_height == 0) {
// notification_min_height =
// }
notification_max_height = getDimem(context, systemUi, "notification_max_height",
R.dimen.notification_max_height);
notification_mid_height = getDimem(context, systemUi, "notification_mid_height",
R.dimen.notification_mid_height);
notification_padding = getDimem(context, systemUi, "notification_padding", R.dimen.notification_padding);
// notification_collapse_second_card_padding
}
}
示例5: newInstance
import android.os.Build; //导入依赖的package包/类
public static GestureDetector newInstance(Context context,
OnGestureListener listener) {
final int sdkVersion = Build.VERSION.SDK_INT;
GestureDetector detector;
if (sdkVersion < Build.VERSION_CODES.ECLAIR) {
detector = new CupcakeGestureDetector(context);
} else if (sdkVersion < Build.VERSION_CODES.FROYO) {
detector = new EclairGestureDetector(context);
} else {
detector = new FroyoGestureDetector(context);
}
detector.setOnGestureListener(listener);
return detector;
}
示例6:
import android.os.Build; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults) {
if (grantResults.length != 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (requestCode == RC_HANDLE_WRITE_PERM) {
callPickPhoto();
} else if (requestCode == RC_CAMERA_PERM) {
int rc = ActivityCompat.checkSelfPermission(mContext, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (rc == PackageManager.PERMISSION_GRANTED) {
callCamera();
} else {
requestWriteExternalStoragePermission(RC_CAMERA_PERM);
}
}
}
}
示例7: getSDCardSize
import android.os.Build; //导入依赖的package包/类
/**
* 获取SD卡全部内存空间大小
*
* @return
*/
public static long getSDCardSize() {
long blockCount;
long blockSize;
if (isSDCardMounted()) {
String dir = getSDCardBaseDir();
//StatFs是从C语言引过来的
StatFs statFs = new StatFs(dir);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
blockCount = statFs.getBlockCountLong();//有多少块
blockSize = statFs.getBlockSizeLong();//每块有多大
} else {
blockCount = statFs.getBlockCount();//有多少块
blockSize = statFs.getBlockSize();//每块有多大
}
return blockCount * blockSize / 1024 / 1024; //总大小
}
return 0;
}
示例8: queryIntentActivities
import android.os.Build; //导入依赖的package包/类
@Override
public List<ResolveInfo> queryIntentActivities(Intent intent, String resolvedType, int flags, int userId) {
checkUserId(userId);
flags = updateFlagsNought(flags);
ComponentName comp = intent.getComponent();
if (comp == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
if (intent.getSelector() != null) {
intent = intent.getSelector();
comp = intent.getComponent();
}
}
}
if (comp != null) {
final List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
final ActivityInfo ai = getActivityInfo(comp, flags, userId);
if (ai != null) {
final ResolveInfo ri = new ResolveInfo();
ri.activityInfo = ai;
list.add(ri);
}
return list;
}
// reader
synchronized (mPackages) {
final String pkgName = intent.getPackage();
if (pkgName == null) {
return mActivities.queryIntent(intent, resolvedType, flags, userId);
}
final VPackage pkg = mPackages.get(pkgName);
if (pkg != null) {
return mActivities.queryIntentForPackage(intent, resolvedType, flags, pkg.activities, userId);
}
return Collections.emptyList();
}
}
示例9: onRequestPermissionsResult
import android.os.Build; //导入依赖的package包/类
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == AUDIO_PERMISSION_REQUEST && permissions[0]
.equals(android.Manifest.permission.RECORD_AUDIO)) {
if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
boolean showAgain =
shouldShowRequestPermissionRationale
(android.Manifest.permission.RECORD_AUDIO);
if (showAgain) {
}
}
finish(); // can't use audio
}
} else
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
示例10: getExternalFilesDirs
import android.os.Build; //导入依赖的package包/类
public static File[] getExternalFilesDirs(Context context, String type) {
final int version = Build.VERSION.SDK_INT;
if (version >= 19) {
//返回结果可能存在null值
return context.getExternalFilesDirs(type);
} else {
return new File[] { context.getExternalFilesDir(type) };
}
}
示例11:
import android.os.Build; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
void dispatchOnCancelled(LoadTask task, D data) {
onCanceled(data);
if (mCancellingTask == task) {
if (DEBUG) Log.v(TAG, "Cancelled task is now canceled!");
if(Utils.hasJellyBeanMR2()){
rollbackContentChanged();
}
mLastLoadCompleteTime = SystemClock.uptimeMillis();
mCancellingTask = null;
if (DEBUG) Log.v(TAG, "Delivering cancellation");
if(Utils.hasJellyBeanMR2()){
deliverCancellation();
}
executePendingTask();
}
}
示例12: animateIn
import android.os.Build; //导入依赖的package包/类
private void animateIn(FloatingActionButton button) {
button.setVisibility(View.VISIBLE);
if (Build.VERSION.SDK_INT >= 14) {
ViewCompat.animate(button)
.scaleX(1.0F)
.scaleY(1.0F)
.alpha(1.0F)
.setInterpolator(INTERPOLATOR)
.withLayer()
.setListener(null)
.start();
} else {
Animation anim = AnimationUtils.loadAnimation(button.getContext(),
android.support.design.R.anim.design_fab_in);
anim.setDuration(200L);
anim.setInterpolator(INTERPOLATOR);
button.startAnimation(anim);
}
}
示例13: build
import android.os.Build; //导入依赖的package包/类
public final T build() {
for (Integer minVersion : implementations.keySet()) {
if (Build.VERSION.SDK_INT >= minVersion) {
String className = implementations.get(minVersion);
try {
Class<? extends T> clazz = Class.forName(className).asSubclass(managedInterface);
Log.i(TAG, "Using implementation " + clazz + " of " + managedInterface + " for SDK " + minVersion);
return clazz.getConstructor().newInstance();
} catch (ClassNotFoundException cnfe) {
Log.w(TAG, cnfe);
} catch (IllegalAccessException iae) {
Log.w(TAG, iae);
} catch (InstantiationException ie) {
Log.w(TAG, ie);
} catch (NoSuchMethodException nsme) {
Log.w(TAG, nsme);
} catch (InvocationTargetException ite) {
Log.w(TAG, ite);
}
}
}
Log.i(TAG, "Using default implementation " + defaultImplementation.getClass() + " of " + managedInterface);
return defaultImplementation;
}
示例14: collectCrashDeviceInfo
import android.os.Build; //导入依赖的package包/类
public void collectCrashDeviceInfo(Context ctx) {
try {
PackageInfo pi = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 1);
if (pi != null) {
this.mDeviceCrashInfo.put(VERSION_NAME, pi.versionName == null ? "not set" : pi.versionName);
this.mDeviceCrashInfo.put(VERSION_CODE, pi.versionCode + "");
}
} catch (NameNotFoundException e) {
LogInfo.log(TAG, "Error while collect package info" + e);
}
for (Field field : Build.class.getDeclaredFields()) {
try {
field.setAccessible(true);
this.mDeviceCrashInfo.put(field.getName(), field.get(null).toString());
LogInfo.log(TAG, field.getName() + " : " + field.get(null));
} catch (Exception e2) {
LogInfo.log(TAG, "Error while collect crash info" + e2);
}
}
}
示例15: getApplicationInfo
import android.os.Build; //导入依赖的package包/类
private ApplicationInfo getApplicationInfo(Notification notification) {
ApplicationInfo ai = getApplicationInfo(notification.tickerView);
if (ai != null) {
return ai;
}
ai = getApplicationInfo(notification.contentView);
if (ai != null) {
return ai;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
ai = getApplicationInfo(notification.bigContentView);
if (ai != null) {
return ai;
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ai = getApplicationInfo(notification.headsUpContentView);
if (ai != null) {
return ai;
}
}
return null;
}