Search in sources :

Example 6 with RequiresPermission

use of android.support.annotation.RequiresPermission in project android-vision by googlesamples.

the class CameraSourcePreview method startIfReady.

@RequiresPermission(Manifest.permission.CAMERA)
private void startIfReady() throws IOException, SecurityException {
    if (mStartRequested && mSurfaceAvailable) {
        mCameraSource.start(mSurfaceView.getHolder());
        if (mOverlay != null) {
            Size size = mCameraSource.getPreviewSize();
            int min = Math.min(size.getWidth(), size.getHeight());
            int max = Math.max(size.getWidth(), size.getHeight());
            if (isPortraitMode()) {
                // Swap width and height sizes when in portrait, since it will be rotated by
                // 90 degrees
                mOverlay.setCameraInfo(min, max, mCameraSource.getCameraFacing());
            } else {
                mOverlay.setCameraInfo(max, min, mCameraSource.getCameraFacing());
            }
            mOverlay.clear();
        }
        mStartRequested = false;
    }
}
Also used : Size(com.google.android.gms.common.images.Size) RequiresPermission(android.support.annotation.RequiresPermission)

Example 7 with RequiresPermission

use of android.support.annotation.RequiresPermission in project LshUtils by SenhLinsh.

the class LshAppUtils method isAppOnForeground.

/**
     * 判断App是否在前台运行
     * 注意: 该方法是判断APP是否处于栈顶, 处于栈顶但是是关闭屏幕的情况下依然返回true
     */
@RequiresPermission(Manifest.permission.GET_TASKS)
public boolean isAppOnForeground() {
    ActivityManager activityManager = (ActivityManager) LshApplicationUtils.getContext().getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
    if (tasksInfo.size() > 0) {
        // 应用程序位于堆栈的顶层
        if (getPackageName().equals(tasksInfo.get(0).topActivity.getPackageName())) {
            return true;
        }
    }
    return false;
}
Also used : ActivityManager(android.app.ActivityManager) RequiresPermission(android.support.annotation.RequiresPermission)

Aggregations

RequiresPermission (android.support.annotation.RequiresPermission)7 SurfaceTexture (android.graphics.SurfaceTexture)2 SurfaceView (android.view.SurfaceView)2 Size (com.google.android.gms.common.images.Size)2 ActivityManager (android.app.ActivityManager)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 ContentValues (android.content.ContentValues)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 BitmapFactory (android.graphics.BitmapFactory)1 Uri (android.net.Uri)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1