我创建了一个相机活动,它将从后置和前置摄像头拍摄照片.但我一直得到上​​面提到的错误可以任何人帮助我:

似乎我在Menifest文件中在调用intent时犯了一些错误,但无法弄清楚我在做什么错误.

这是我的CameraActivity.java

public class CameraActivity extends Activity {

        private static CameraActivity inst;

        private Camera mCamera;
        private CameraPreview mPreview;
        private MediaRecorder mMediaRecorder;
        private FrameLayout preview;
        private boolean isRecording = false;

        private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
        private static final int CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE = 200;
        public static final int MEDIA_TYPE_IMAGE = 1;
        public static final int MEDIA_TYPE_VIDEO = 2;
        private static boolean isPictureTaken = false;
        private static int cameraCount = 0;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_camera);

            Log.d("TestCase","in camera activity on create");

            inst = this;

            Intent localIntent = getIntent();
            //Intent localIntent = new Intent("com.test.TestCase.core.util.CameraActivity");
            //localIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
            String cameraMode = localIntent.getExtras().getString("Camera");
            Log.d("TestCase","CameraMode" + cameraMode);
            if (cameraMode.equals("FrontCamera"))
                inst.mCamera = openFrontFacingCamera();
            else
                inst.mCamera = openRearFacingCamera();

            setCameraview();

        }

        private void setCameraview() {

            if (inst.mCamera != null) {
                Log.d("TestCase","Got the Camera Instance");
            } else {
                Log.d("TestCase","Camera Instance obtained is null");
            }

            // Create our Preview view and set it as the content of our activity.
            inst.mPreview = new CameraPreview(this,mCamera);
            inst.preview = (FrameLayout) findViewById(R.id.camera_preview);
            inst.preview.addView(mPreview);

        }

        private Camera openRearFacingCamera() {
            Camera cam = null;
            Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
            cameraCount = Camera.getNumberOfCameras();
            Log.d("Camera","Camera COunt : " + cameraCount);

            for (int camIdx = 0; camIdx < cameraCount; camIdx++) {

                Log.d("Camera"," CamIdx : " + camIdx);

                Camera.getCameraInfo(camIdx,cameraInfo);

                if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
                    try {
                        cam = Camera.open(camIdx);
                        break;
                    } catch (RuntimeException e) {
                        for (StackTraceElement st : e.getStackTrace())
                            Log.d("Camera",st.toString());
                        // Log.e("Camera Failed to open: " +
                        // e.getLocalizedMessage());
                    }
                }
            }

            return cam;
        }

        @Override
        protected void onActivityResult(int requestCode,int resultCode,Intent data) {
            if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
                if (resultCode == RESULT_OK) {
                    // Image captured and saved to fileUri specified in the Intent
                    Toast.makeText(this,"Image saved to:\n" + data.getData(),Toast.LENGTH_LONG).show();
                } else if (resultCode == RESULT_CANCELED) {
                    // User cancelled the image capture
                } else {
                    // Image capture Failed,advise user
                }
            }

            if (requestCode == CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) {
                if (resultCode == RESULT_OK) {
                    // Video captured and saved to fileUri specified in the Intent
                    Toast.makeText(this,"Video saved to:\n" + data.getData(),Toast.LENGTH_LONG).show();
                } else if (resultCode == RESULT_CANCELED) {
                    // User cancelled the video capture
                } else {
                    // Video capture Failed,advise user
                }
            }
        }

        /** A safe way to get an instance of the Camera object. */
        private Camera openFrontFacingCamera() {
            // int cameraCount = 0;
            Camera cam = null;
            Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
            cameraCount = Camera.getNumberOfCameras();
            Log.d("Camera",cameraInfo);

                if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                    try {
                        cam = Camera.open(camIdx);
                        break;
                    } catch (RuntimeException e) {
                        for (StackTraceElement st : e.getStackTrace())
                            Log.d("Camera",st.toString());
                        // Log.e("Camera Failed to open: " +
                        // e.getLocalizedMessage());
                    }
                }
            }

            return cam;
        }

        @Override
        public void onStart() {
            try {
                super.onStart();

            } catch (Exception localException) {
                Log.d("TestCase",localException.getMessage());
            }
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.camera,menu);
            return true;
        }

        @Override
        public boolean onoptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button,so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
            if (id == R.id.action_settings) {
                return true;
            }
            return super.onoptionsItemSelected(item);
        }

        private PictureCallback mPicture = new PictureCallback() {

            @Override
            public void onPictureTaken(byte[] data,Camera camera) {

                File pictureFile = getoutputMediaFile(MEDIA_TYPE_IMAGE);
                if (pictureFile == null) {
                    Log.d("TestCase","Error creating media file,check storage permissions: ");
                    return;
                }

                try {
                    Log.d("TestCase","Picture taken");
                    FileOutputStream fos = new FileOutputStream(pictureFile);
                    fos.write(data);
                    fos.close();

                    Log.d("TestCase","Picture saved");
                    CameraActivity.isPictureTaken = true;

                } catch (FileNotFoundException e) {
                    Log.d("TestCase","File not found: " + e.getMessage());
                } catch (IOException e) {
                    Log.d("TestCase","Error accessing file: " + e.getMessage());
                }

                try {
                    inst.mCamera.stopPreview();

                } catch (Exception e) {
                    // ignore: tried to stop a non-existent preview
                }

                // inst.mCamera.release();

                // set preview size and make any resize,rotate or
                // reformatting changes here

                // start preview with new settings
                try {
                    inst.mCamera.setPreviewdisplay(mPreview.getHolder());
                    inst.mCamera.startPreview();

                } catch (Exception e) {
                    Log.d("TestCase","Error starting camera preview: " + e.getMessage());
                }
            }
        };

        public void onCameraClick(View view) {
            try {

                takePicture();

            } catch (Exception localException) {
                Log.d("TestCase",localException.getMessage());
            }
        }

        private void takePicture() {

            inst.mCamera.takePicture(null,null,mPicture);
        }

        /** Create a File for saving an image or video */
        private static File getoutputMediaFile(int type) {
            // To be safe,you should check that the SDCard is mounted
            // using Environment.getExternalStorageState() before doing this.

            File mediaStorageDir = new File(
                    Environment
                            .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"TestCase_CamMedia");
            // This location works best if you want the created images to be shared
            // between applications and persist after your app has been uninstalled.

            // Create the storage directory if it does not exist
            if (!mediaStorageDir.exists()) {
                if (!mediaStorageDir.mkdirs()) {
                    Log.d("TestCase","Failed to create directory");
                    return null;
                }
            }

            // Create a media file name
            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",Locale.getDefault()).format(new Date());
            File mediaFile;
            if (type == MEDIA_TYPE_IMAGE) {
                mediaFile = new File(mediaStorageDir.getPath() + File.separator
                        + "IMG_" + timeStamp + ".jpg");
            } else if (type == MEDIA_TYPE_VIDEO) {
                mediaFile = new File(mediaStorageDir.getPath() + File.separator
                        + "VID_" + timeStamp + ".mp4");
            } else {
                return null;
            }

            return mediaFile;
        }

        private boolean prepareVideoRecorder() {

            // mCamera = getCameraInstance();
            inst.mMediaRecorder = new MediaRecorder();
            // Step 1: Unlock and set camera to MediaRecorder
            inst.mCamera.unlock();

            inst.mMediaRecorder.setCamera(mCamera);

            // Step 2: Set sources
            inst.mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
            inst.mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

            // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
            inst.mMediaRecorder.setProfile(CamcorderProfile
                    .get(CamcorderProfile.QUALITY_HIGH));

            // Step 4: Set output file
            inst.mMediaRecorder.setoutputFile(getoutputMediaFile(MEDIA_TYPE_VIDEO)
                    .toString());

            // Step 5: Set the preview output
            inst.mMediaRecorder
                    .setPreviewdisplay(mPreview.getHolder().getSurface());

            // Step 6: Prepare configured MediaRecorder
            try {

                mMediaRecorder.prepare();
            } catch (IllegalStateException e) {
                Log.d("TestCase","IllegalStateException preparing MediaRecorder: "
                                + e.getMessage());
                inst.releaseMediaRecorder();
                return false;
            } catch (IOException e) {
                Log.d("TestCase","IOException preparing MediaRecorder: " + e.getMessage());
                inst.releaseMediaRecorder();
                return false;
            }
            return true;

        }

        @Override
        protected void onPause() {
            super.onPause();
            inst.releaseMediaRecorder(); // if you are using MediaRecorder,release
                                            // it first
            inst.releaseCamera(); // release the camera immediately on pause event
        }

        private void releaseMediaRecorder() {
            if (inst.mMediaRecorder != null) {
                inst.mMediaRecorder.reset(); // clear recorder configuration
                inst.mMediaRecorder.release(); // release the recorder object
                inst.mMediaRecorder = null;
                inst.mCamera.lock(); // lock camera for later use
            }
        }

        private void releaseCamera() {
            if (inst.mCamera != null) {
                inst.mCamera.release(); // release the camera for other applications
                inst.mCamera = null;
            }
        }

        public void recordVideo() {
            if (!inst.isRecording) {
                if (inst.prepareVideoRecorder()) {
                    // Camera is available and unlocked,MediaRecorder is prepared,// Now you can start recording
                    inst.mMediaRecorder.start();
                    Log.d("TestCase","started video recording");
                    // inform the user that recording has started

                    inst.isRecording = true;
                } else
                    inst.releaseMediaRecorder();
            }
        }

        public void stopRecording() {
            if (inst.isRecording) {
                // stop recording and release camera
                inst.mMediaRecorder.stop(); // stop the recording
                Log.d("TestCase","stopped video recording");
                inst.releaseMediaRecorder(); // release the MediaRecorder object
                inst.mCamera.lock(); // take camera access back from MediaRecorder

                // inform the user that recording has stopped
                inst.isRecording = false;
            }
        }

        public void onRecordVideo(View view) {
            try {
                inst.recordVideo();
            } catch (Exception localException) {
                Log.d("TestCase",localException.getMessage());
            }
        }

        public void onStopRecording(View view) {
            try {
                inst.stopRecording();
            } catch (Exception localException) {
                Log.d("TestCase",localException.getMessage());
            }
        }

        public static boolean TakePicture() {
            inst.takePicture();
            return CameraActivity.isPictureTaken;
        }

        public static boolean RecordVideo() {
            inst.recordVideo();
            return inst.isRecording;
        }

        public static boolean StopVideo() {
            inst.stopRecording();
            return !inst.isRecording;
        }

        public static void CloseCamera() {
            inst.finish();
        }

        public static boolean ToggleCamera() throws Exception {

            for(int i=1; i<=3 ; i++) {
                if(i%2==0)
                    inst.mCamera = inst.openRearFacingCamera();
                else
                    inst.mCamera = inst.openFrontFacingCamera();

                if (inst.mCamera != null) {
                    Log.d("TestCase","Got the Camera Instance");
                } else {
                    Log.d("TestCase","Camera Instance obtained is null");
                }
                inst.setCameraview();
                Thread.sleep(10000L);
            }
            return true;

        }
    }



**Here is ManifestFile :**

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.TestCase.TestCase"
        android:versionCode="1"
        android:versionName="1.0" >

        <uses-sdk
            android:maxsdkVersion="21"
            android:minSdkVersion="14"
            android:targetSdkVersion="21" />

        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.INteraCT_ACROSS_USERS_FULL" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.NFC" />
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /
        <uses-feature android:name="android.hardware.camera" />
        <uses-feature android:name="android.hardware.camera.flash" />

        <uses-permission android:name="android.permission.RECORD_AUdio" />

        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name=".main_activities.TestCaseActivity"
                android:label="@style/AppTheme" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:name="com.TestCase.TestCase.core.util.CameraActivity"
                android:label="@string/title_activity_camera" >
            </activity>

            <activity android:name=".main_activities.SetPreferenceActivity" />
            <activity
                android:name=".main_activities.SummaryActivity"
                android:label="@string/title_activity_summary" >
            </activity>

            <activity
                android:name="com.TestCase.TestCase.main_activities.AboutActivity"
                android:label="@string/title_activity_about" >
            </activity>

            <service android:name=".services.MasterService" />
            <service android:name=".services.TestCaseBootService" />
            <service android:name=".services.ActivityLauncherService" />

            <receiver android:name=".recievers.BootReciever" >
                <intent-filter>
                    <action android:name="android.intent.action.BOOT_COMPLETED" />
                </intent-filter>
            </receiver>
            <receiver android:name="com.TestCase.TestCase.framework.TestActionEndbroadcastReceiver" >
            </receiver>
            <receiver android:name="com.TestCase.TestCase.system.TestProgressUpdater$Updatebroadcast" >
            </receiver>
        </application>

    </manifest>

Logcat : 

 11-03 19:31:21.782: D/TestCase(11635): [11.03.14_19:31:021]    came back from thread starting itest action 
    11-03 19:31:21.782: D/TestCase(11635): [11.03.14_19:31:021] Came back after starting action thread
    11-03 19:31:21.804: D/TestCase(11635): [11.03.14_19:31:021] from thread starting itest action 
    11-03 19:31:21.806: D/TestCase(11635): [11.03.14_19:31:021] Recieved onFinishPrepare
    11-03 19:31:21.834: D/TestCase(11635): [11.03.14_19:31:021] Error found when test is running: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
    11-03 19:31:21.834: D/TestCase(11635):  at android.app.ContextImpl.startActivity(ContextImpl.java:1232)
    11-03 19:31:21.834: D/TestCase(11635):  at android.app.ContextImpl.startActivity(ContextImpl.java:1219)
    11-03 19:31:21.834: D/TestCase(11635):  at android.content.Contextwrapper.startActivity(Contextwrapper.java:322)
    11-03 19:31:21.834: D/TestCase(11635):  at com.originatorTestCase.TestCase.core.multimedia.LaunchRearCameraTestAction.start(LaunchRearCameraTestAction.java:24)
    11-03 19:31:21.834: D/TestCase(11635):  at com.originatorTestCase.TestCase.framework.TestActionExecutor.startAction(TestActionExecutor.java:54)
    11-03 19:31:21.834: D/TestCase(11635):  at com.originatorTestCase.TestCase.framework.TestActionExecutor.access$1(TestActionExecutor.java:49)
    11-03 19:31:21.834: D/TestCase(11635):  at com.originatorTestCase.TestCase.framework.TestActionExecutor$ActionThread.run(TestActionExecutor.java:166)
    11-03 19:31:21.837: D/TestCase(11635): [11.03.14_19:31:021] TestAction Execution Finished : LaunchRearCamera id : 3
    11-03 19:31:21.838: D/TestCase(11635): [11.03.14_19:31:021] TestRunner onFinish(ITestAction) : [null]nullnull(null):
    11-03 19:31:21.862: D/TestCase(11635): [11.03.14_19:31:021] Completed [LaunchRearCamera TestAction] iteration : 1
    11-03 19:31:21.862: D/TestCase(11635): RESULT = [action="LaunchRearCamera" status="FAIL" iteration="1" startTime="11.03.14 19:31:21" duration="0" endTime="11.03.14 19:31:21" FailedReason=" [null]nullnull(null): Executing error : android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? ""]
    11-03 19:31:21.863: D/TestCase(11635): [11.03.14_19:31:021] Has errors so stop test case RearCameraTakePictureTest
    11-03 19:31:21.886: D/TestCase(11635): [11.03.14_19:31:021] Completed total 1 iterations for action LaunchRearCamera.
    11-03 19:31:21.888: D/TestCase(11635): [11.03.14_19:31:021] ==========================================================
    11-03 19:31:21.906: D/TestCase(11635): [11.03.14_19:31:021] ==========================================================
    11-03 19:31:21.912: D/TestCase(11635): [11.03.14_19:31:021] Start Test Action TakePicture
    11-03 19:31:21.922: D/TestCase(11635): [11.03.14_19:31:021] Preparing for test action TakePicture
    11-03 19:31:21.925: D/TestCase(11635): [11.03.14_19:31:021] Begin [TakePicture TestAction] iteration : 1
    11-03 19:31:21.928: D/TestCase(11635): [11.03.14_19:31:021] Next random TakePicture-duration = 15
    11-03 19:31:21.947: D/TestCase(11635): [11.03.14_19:31:021] triggering schedule Task
    11-03 19:31:21.966: D/TestCase(11635): [11.03.14_19:31:021] initializing task infor
    11-03 19:31:21.968: D/TestCase(11635): [11.03.14_19:31:021] initializing thread
    11-03 19:31:21.974: D/TestCase(11635): [11.03.14_19:31:021] adding thread to task info
    11-03 19:31:21.976: D/TestCase(11635): [11.03.14_19:31:021] putting thread refrence in concurrent hash map
    11-03 19:31:21.977: D/TestCase(11635): [11.03.14_19:31:021] starting thread
    11-03 19:31:21.979: D/TestCase(11635): [11.03.14_19:31:021] came back after starting thread
    11-03 19:31:21.991: D/TestCase(11635): [11.03.14_19:31:021] in Action thread. 
    11-03 19:31:21.991: D/TestCase(11635): [11.03.14_19:31:021] Acquire WL for TakePicture
    11-03 19:31:21.995: D/TestCase(11635): [11.03.14_19:31:021] came back after triggering schedule Task
    11-03 19:31:21.996: D/TestCase(11635): [11.03.14_19:31:021] Came back after call back of testAction : LaunchRearCamera
    11-03 19:31:21.996: D/TestCase(11635): [11.03.14_19:31:021] Came back after starting action thread
    11-03 19:31:22.014: D/TestCase(11635): [11.03.14_19:31:022] from thread starting itest action 
    11-03 19:31:22.015: D/TestCase(11635): [11.03.14_19:31:022] Recieved onFinishPrepare
    11-03 19:31:22.024: D/TestCase(11635): [11.03.14_19:31:022] Error found when test is running: java.lang.NullPointerException: Attempt to invoke direct method 'void com..core.util.CameraActivity.takePicture()' on a null object reference
    11-03 19:31:22.024: D/TestCase(11635):  at core.util.CameraActivity.TakePicture(CameraActivity.java:403)
    11-03 19:31:22.024: D/TestCase(11635):  at

解决方法

你的问题在这里:

在com.qualcomm.post.core.multimedia.LaunchRearCameraTestAction.start(LaunchRearCameraTestAction.java:24)

在此代码中,您需要在调用startActivity()之前将新任务标志添加到Intent:

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

从Activity上下文外部调用startActivity()需要FLAG_ACTIVITY_NEW_TASK标志异常 – Android的更多相关文章

  1. ios – 使用watchOS 2在Apple Watch上渲染折线图

    我正在尝试使用watchOS2在AppleWatch上渲染线条/步骤图.与iOS9不同,watchOS2不支持Quartz.它只支持CoreGraphics.我尝试编写一些代码来绘制折线图但我得到一个错误“CGContextRestoreGState:无效的上下文0x0.这是一个严重的错误.这个应用程序,或它使用的库,正在使用无效的上下文,从而有助于整体系统稳定性和可靠性降低.这个通知是礼貌的:请

  2. performBlockAndWait在iOS 7上使用专用队列死锁的子上下文

    如果它出现在主队列中,那么你就会遇到问题,因为你正在阻止它.假设情况并非如此,您是否可以从Xcode共享显示截止日期的线程堆栈?一旦我好好看看那个堆栈,我会更新我的答案.Quellish是正确的,你没有正确插入孩子.该子MOC上的任何活动都应该在-performBlock:或-performBlockAndWait:中.我会扩展-performBlockAndWait:来覆盖对象的整个创建和决策,而不仅仅是保存.更新1-createWithAttributes是什么:inManagedobjectCont

  3. ios – 合并子上下文时的NSObjectInaccessbileExceptions

    我尝试手动重现,但失败了.是否有其他可能发生这种情况的情况,是否有处理此类问题的提示?解决方法在创建子上下文时,您可以尝试使用以下行:

  4. ios – CGContextClear警告

    解决方法我想说它肯定与CGContextClear有关.它保留了你在记忆中的所有东西.虽然您的上下文未被清除或释放,但它会将该上下文中定义的元素保留在内存中.您使用的是哪个版本的iOS?

  5. ios – 设置NSDataDetector的上下文日期

    假设今天是2014年1月20日.如果我使用NSDataDetector从“明天下午4点”字符串中提取日期,我将得到2014-01-21T16:00.大.但是,假设我希望NSDataDetector假装当前日期是2014年1月14日.这样,当我解析“明天下午4点”时,我将得到2014-01-15T16:00.如果我在设备上更改系统时间,我会得到我想要的.但是,有没有办法以编程方式指定它?

  6. 你将NSArrayController的托管对象上下文绑定到Xcode 4中的是什么?

    实际上,我对绑定一切都有同样的问题;我的UI对象都不适用于我的模型.我唯一能想到的是File的Owner和NSArrayController之间的连接出了问题.我此时还没有编写任何代码,因为我理解我不应该仅仅链接UI字段和核心数据.它是不同的因为我使用的是基于文档的应用程序?“不使用核心数据”的答案不会有成效;我知道我可以回到常规数据对象上.如果可能的话,我想在核心数据的背景下解决这个问题.TIA!

  7. ios – UIApplication.delegate必须仅在主线程中使用[复制]

    我应该在主调度中的viewControllers中声明这些)变量位置声明定义了它的范围.您需要确定这些变量的范围.您可以将它们声明为项目或应用程序级别(全局),类级别或特定此功能级别.如果要在其他ViewControllers中使用这些变量,则使用公共/开放/内部访问控制将其声明为全局或类级别.

  8. ios – 核心数据 – 保存上下文后撤消更改

    但是,实际情况并非如此!即使我使用托管对象上的更改保存上下文,以下-undo调用仍将成功撤消更改.这不是针对文档中陈述的内容吗?也许我做错了什么?

  9. ios – 我可以安全地在@try catch块中包装’CoreData无法解决错误’错误

    )是的,我偶尔会得到’CoreData无法完成故障’的错误.在我的特定应用程序中,这通常发生在一种“数据绑定”过程中,因此我可以安全地丢弃故障对象并继续前进.我想通过在@try-catch块中包装数据绑定的循环内部并且只跳过我得到CoreData错误的行来完成此操作.我可以使用CoreData安全地执行此操作吗?

  10. ios – 如何在UIActivityViewController调用然后关闭后执行操作

    解决方法在这种情况下,您可以使用completionHadler:

随机推荐

  1. bluetooth-lowenergy – Altbeacon库无法在Android 5.0上运行

    昨天我在Nexus4上获得了Android5.0的更新,并且altbeacon库停止了检测信标.似乎在监视和测距时,didEnterRegion和didRangeBeaconsInRegion都没有被调用.即使RadiusNetworks的Locate应用程序现在表现不同,一旦检测到信标的值,它们就不再得到更新,并且通常看起来好像信标超出了范围.我注意到的一点是,现在在logcat中出现以下行“B

  2. android – react-native动态更改响应者

    我正在使用react-native进行Android开发.我有一个视图,如果用户长按,我想显示一个可以拖动的动画视图.我可以使用PanResponder实现这一点,它工作正常.但我想要做的是当用户长按时,用户应该能够继续相同的触摸/按下并拖动新显示的Animated.View.如果您熟悉Google云端硬盘应用,则它具有类似的功能.当用户长按列表中的任何项目时,它会显示可拖动的项目.用户可以直接拖

  3. android – 是否有可能通过使用与最初使用的证书不同的证书对其进行签名来发布更新的应用程序

    是否可以通过使用与最初使用的证书不同的证书进行签名来发布Android应用程序的更新?我知道当我们尝试将这样的构建上传到市场时,它通常会给出错误消息.但有没有任何出路,比如将其标记为主要版本,指定市场中的某个地方?解决方法不,你不能这样做.证书是一种工具,可确保您是首次上传应用程序的人.所以总是备份密钥库!

  4. 如何检测Android中是否存在麦克风?

    ..所以我想在让用户访问语音输入功能之前检测麦克风是否存在.如何检测设备上是否有麦克风.谢谢.解决方法AndroidAPI参考:hasSystemFeature

  5. Android – 调用GONE然后VISIBLE使视图显示在错误的位置

    我有两个视图,A和B,视图A在视图B上方.当我以编程方式将视图A设置为GONE时,它将消失,并且它正下方的视图将转到视图A的位置.但是,当我再次将相同的视图设置为VISIBLE时,它会在视图B上显示.我不希望这样.我希望视图B回到原来的位置,这是我认为会发生的事情.我怎样才能做到这一点?编辑–代码}这里是XML:解决方法您可以尝试将两个视图放在RelativeLayout中并相对于彼此设置它们的位置.

  6. android – 获得一首歌的流派

    我如何阅读与歌曲相关的流派?我可以读这首歌,但是如何抓住这首歌的流派,它存放在哪里?解决方法检查此代码:

  7. android – 使用textShadow折叠工具栏

    我有一个折叠工具栏的问题,在展开状态我想在文本下面有一个模糊的阴影,我使用这段代码:用:我可以更改textColor,它可以工作,但阴影不起作用.我为阴影尝试了很多不同的值.是否可以为折叠文本投射阴影?

  8. android – 重用arm共享库

    我已经建立了armarm共享库.我有兴趣重用一个函数.我想调用该函数并获得返回值.有可能做这样的事吗?我没有任何头文件.我试过这个Android.mk,我把libtest.so放在/jni和/libs/armeabi,/lib/armeabi中.此时我的cpp文件编译,但现在是什么?我从objdump知道它的名字编辑:我试图用这个android.mk从hello-jni示例中添加prebuild库:它工作,但libtest.so相同的代码显示以下错误(启动时)libtest.so存在于libhello-j

  9. android – 为NumberPicker捕获键盘’Done’

    我有一个AlertDialog只有一些文本,一个NumberPicker,一个OK和一个取消.(我知道,这个对话框还没有做它应该保留暂停和恢复状态的事情.)我想在软键盘或其他IME上执行“完成”操作来关闭对话框,就像按下了“OK”一样,因为只有一个小部件可以编辑.看起来处理IME“Done”的最佳方法通常是在TextView上使用setonEditorActionListener.但我没有任何Te

  10. android – 想要在调用WebChromeClient#onCreateWindow时知道目标URL

    当我点击一个带有target=“_blank”属性的超链接时,会调用WebChromeClient#onCreateWindow,但我找不到新的窗口将打开的新方法?主页url是我唯一能知道的东西?我想根据目标网址更改应用行为.任何帮助表示赞赏,谢谢!

返回
顶部