-
- All Implemented Interfaces:
-
android.content.ComponentCallbacks,android.content.ComponentCallbacks2,android.view.KeyEvent.Callback,android.view.LayoutInflater.Factory,android.view.LayoutInflater.Factory2,android.view.View.OnCreateContextMenuListener,android.view.Window.Callback,androidx.activity.OnBackPressedDispatcherOwner,androidx.appcompat.app.ActionBarDrawerToggle.DelegateProvider,androidx.appcompat.app.AppCompatCallback,androidx.core.app.ActivityCompat.OnRequestPermissionsResultCallback,androidx.core.app.ActivityCompat.RequestPermissionsRequestCodeValidator,androidx.core.app.TaskStackBuilder.SupportParentable,androidx.core.view.KeyEventDispatcher.Component,androidx.lifecycle.LifecycleOwner,androidx.lifecycle.ViewModelStoreOwner,androidx.savedstate.SavedStateRegistryOwner,com.king.zxing.CameraScan.OnScanResultCallback
public class CaptureActivity extends AppCompatActivity implements CameraScan.OnScanResultCallback
相机扫描基类;CaptureActivity 内部持有CameraScan,便于快速实现扫描识别。
快速实现扫描识别主要有以下几种方式:
1、通过继承 CaptureActivity或者CaptureFragment或其子类,可快速实现扫描识别。 (适用于大多数场景,自定义布局时需覆写getLayoutId方法)
2、在你项目的Activity或者Fragment中实例化一个DefaultCameraScan。(适用于想在扫码界面写交互逻辑,又因为项目 架构或其它原因,无法直接或间接继承CaptureActivity或CaptureFragment时使用)
3、继承CameraScan自己实现一个,可参照默认实现类DefaultCameraScan,其他步骤同方式2。(高级用法,谨慎使用)
-
-
Method Summary
Modifier and Type Method Description voidinitUI()初始化 voidinitCameraScan()初始化CameraScan voidstartCamera()启动相机预览 voidonRequestPermissionsResult(int requestCode, @NonNull() Array<String> permissions, @NonNull() Array<int> grantResults)voidrequestCameraPermissionResult(@NonNull() Array<String> permissions, @NonNull() Array<int> grantResults)请求Camera权限回调结果 booleanisContentView()返回true时会自动初始化setContentView,返回为false是需自己去初始化setContentView intgetLayoutId()布局ID;通过覆写此方法可以自定义布局 intgetViewfinderViewId()viewfinderView 的 ID intgetPreviewViewId()预览界面previewView 的ID;可通过覆写此方法自定义ID intgetFlashlightId()获取 ivFlashlight 的ID CameraScangetCameraScan()获取 CameraScan booleanonScanResultCallback(Result result)接收扫码结果回调 -
Methods inherited from class androidx.appcompat.app.AppCompatActivity
addContentView, closeOptionsMenu, dispatchKeyEvent, findViewById, getDelegate, getDrawerToggleDelegate, getMenuInflater, getResources, getSupportActionBar, getSupportParentActivityIntent, invalidateOptionsMenu, onConfigurationChanged, onContentChanged, onCreateSupportNavigateUpTaskStack, onKeyDown, onMenuItemSelected, onMenuOpened, onPanelClosed, onPrepareSupportNavigateUpTaskStack, onSupportActionModeFinished, onSupportActionModeStarted, onSupportContentChanged, onSupportNavigateUp, onWindowStartingSupportActionMode, openOptionsMenu, setContentView, setSupportActionBar, setSupportProgress, setSupportProgressBarIndeterminate, setSupportProgressBarIndeterminateVisibility, setSupportProgressBarVisibility, setTheme, startSupportActionMode, supportInvalidateOptionsMenu, supportNavigateUpTo, supportRequestWindowFeature, supportShouldUpRecreateTask -
Methods inherited from class androidx.fragment.app.FragmentActivity
dump, getSupportFragmentManager, getSupportLoaderManager, onAttachFragment, onCreatePanelMenu, onCreateView, onLowMemory, onMultiWindowModeChanged, onPictureInPictureModeChanged, onPreparePanel, onRequestPermissionsResult, onStateNotSaved, setEnterSharedElementCallback, setExitSharedElementCallback, startActivityForResult, startActivityFromFragment, startIntentSenderForResult, startIntentSenderFromFragment, supportFinishAfterTransition, supportPostponeEnterTransition, supportStartPostponedEnterTransition, validateRequestPermissionsRequestCode -
Methods inherited from class androidx.activity.ComponentActivity
getLastCustomNonConfigurationInstance, getLifecycle, getOnBackPressedDispatcher, getSavedStateRegistry, getViewModelStore, onBackPressed, onRetainCustomNonConfigurationInstance, onRetainNonConfigurationInstance -
Methods inherited from class androidx.core.app.ComponentActivity
dispatchKeyShortcutEvent, getExtraData, putExtraData, superDispatchKeyEvent -
Methods inherited from class android.app.Activity
closeContextMenu, createPendingResult, dismissDialog, dismissKeyboardShortcutsHelper, dispatchGenericMotionEvent, dispatchPopulateAccessibilityEvent, dispatchTouchEvent, dispatchTrackballEvent, enterPictureInPictureMode, enterPictureInPictureMode, finish, finishActivity, finishActivityFromChild, finishAffinity, finishAfterTransition, finishAndRemoveTask, finishFromChild, getActionBar, getApplication, getCallingActivity, getCallingPackage, getChangingConfigurations, getComponentName, getContentScene, getContentTransitionManager, getCurrentFocus, getFragmentManager, getIntent, getLastNonConfigurationInstance, getLayoutInflater, getLoaderManager, getLocalClassName, getMaxNumPictureInPictureActions, getMediaController, getOnBackInvokedDispatcher, getParent, getParentActivityIntent, getPreferences, getReferrer, getRequestedOrientation, getSearchEvent, getSplashScreen, getSystemService, getTaskId, getTitle, getTitleColor, getVoiceInteractor, getVolumeControlStream, getWindow, getWindowManager, hasWindowFocus, isActivityTransitionRunning, isChangingConfigurations, isChild, isDestroyed, isFinishing, isImmersive, isInMultiWindowMode, isInPictureInPictureMode, isLaunchedFromBubble, isLocalVoiceInteractionSupported, isTaskRoot, isVoiceInteraction, isVoiceInteractionRoot, managedQuery, moveTaskToBack, navigateUpTo, navigateUpToFromChild, onActionModeFinished, onActionModeStarted, onActivityReenter, onAttachedToWindow, onContextItemSelected, onContextMenuClosed, onCreateContextMenu, onCreateDescription, onCreateNavigateUpTaskStack, onCreateOptionsMenu, onCreatePanelView, onCreateThumbnail, onDetachedFromWindow, onEnterAnimationComplete, onGenericMotionEvent, onGetDirectActions, onKeyLongPress, onKeyMultiple, onKeyShortcut, onKeyUp, onLocalVoiceInteractionStarted, onLocalVoiceInteractionStopped, onNavigateUp, onNavigateUpFromChild, onOptionsItemSelected, onOptionsMenuClosed, onPerformDirectAction, onPictureInPictureRequested, onPictureInPictureUiStateChanged, onPrepareNavigateUpTaskStack, onPrepareOptionsMenu, onProvideAssistContent, onProvideAssistData, onProvideKeyboardShortcuts, onProvideReferrer, onSearchRequested, onTopResumedActivityChanged, onTouchEvent, onTrackballEvent, onTrimMemory, onUserInteraction, onVisibleBehindCanceled, onWindowAttributesChanged, onWindowFocusChanged, onWindowStartingActionMode, openContextMenu, overridePendingTransition, postponeEnterTransition, recreate, registerActivityLifecycleCallbacks, registerComponentCallbacks, registerForContextMenu, releaseInstance, removeDialog, reportFullyDrawn, requestDragAndDropPermissions, requestPermissions, requestShowKeyboardShortcuts, requestVisibleBehind, requestWindowFeature, requireViewById, runOnUiThread, setActionBar, setContentTransitionManager, setDefaultKeyMode, setFeatureDrawable, setFeatureDrawableAlpha, setFeatureDrawableResource, setFeatureDrawableUri, setFinishOnTouchOutside, setImmersive, setInheritShowWhenLocked, setIntent, setLocusContext, setMediaController, setPictureInPictureParams, setProgress, setProgressBarIndeterminate, setProgressBarIndeterminateVisibility, setProgressBarVisibility, setRecentsScreenshotEnabled, setRequestedOrientation, setResult, setSecondaryProgress, setShouldDockBigOverlays, setShowWhenLocked, setTaskDescription, setTitle, setTitleColor, setTranslucent, setTurnScreenOn, setVisible, setVolumeControlStream, setVrModeEnabled, shouldDockBigOverlays, shouldShowRequestPermissionRationale, shouldUpRecreateTask, showAssist, showDialog, showDialog, showLockTaskEscapeMessage, startActionMode, startActivities, startActivity, startActivityFromChild, startActivityIfNeeded, startIntentSender, startIntentSenderFromChild, startLocalVoiceInteraction, startLockTask, startManagingCursor, startNextMatchingActivity, startPostponedEnterTransition, startSearch, stopLocalVoiceInteraction, stopLockTask, stopManagingCursor, takeKeyEvents, triggerSearch, unregisterActivityLifecycleCallbacks, unregisterComponentCallbacks, unregisterForContextMenu -
Methods inherited from class android.view.ContextThemeWrapper
applyOverrideConfiguration, getAssets, getTheme -
Methods inherited from class android.content.ContextWrapper
bindIsolatedService, bindService, bindServiceAsUser, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingOrSelfUriPermissions, checkCallingPermission, checkCallingUriPermission, checkCallingUriPermissions, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermissions, clearWallpaper, createAttributionContext, createConfigurationContext, createContext, createContextForSplit, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, createWindowContext, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAttributionSource, getAttributionTag, getBaseContext, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDataDir, getDatabasePath, getDir, getDisplay, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFileStreamPath, getFilesDir, getMainExecutor, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getOpPackageName, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getParams, getSharedPreferences, getSystemServiceName, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isDeviceProtectedStorage, isRestricted, isUiContext, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, peekWallpaper, registerReceiver, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeSelfPermissionsOnKill, revokeUriPermission, sendBroadcast, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setWallpaper, startForegroundService, startInstrumentation, startService, stopService, unbindService, unregisterReceiver, updateServiceGroup -
Methods inherited from class android.content.Context
getColor, getColorStateList, getDrawable, getString, getSystemService, getText, obtainStyledAttributes, revokeSelfPermissionOnKill, sendBroadcastWithMultiplePermissions -
Methods inherited from class android.view.Window.Callback
onPointerCaptureChanged -
Methods inherited from class com.king.zxing.CameraScan.OnScanResultCallback
onScanResultFailure -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
initUI
void initUI()
初始化
-
initCameraScan
void initCameraScan()
初始化CameraScan
-
startCamera
void startCamera()
启动相机预览
-
onRequestPermissionsResult
void onRequestPermissionsResult(int requestCode, @NonNull() Array<String> permissions, @NonNull() Array<int> grantResults)
-
requestCameraPermissionResult
void requestCameraPermissionResult(@NonNull() Array<String> permissions, @NonNull() Array<int> grantResults)
请求Camera权限回调结果
- Parameters:
permissions- 权限grantResults- 授权结果
-
isContentView
boolean isContentView()
返回true时会自动初始化setContentView,返回为false是需自己去初始化setContentView
-
getLayoutId
int getLayoutId()
布局ID;通过覆写此方法可以自定义布局
-
getViewfinderViewId
int getViewfinderViewId()
viewfinderView 的 ID
-
getPreviewViewId
int getPreviewViewId()
预览界面previewView 的ID;可通过覆写此方法自定义ID
-
getFlashlightId
int getFlashlightId()
获取 ivFlashlight 的ID
-
getCameraScan
CameraScan getCameraScan()
获取 CameraScan
-
onScanResultCallback
boolean onScanResultCallback(Result result)
接收扫码结果回调
- Parameters:
result- 扫码结果
-
-
-
-