当我尝试打开相机javaclass时应用程序不断崩溃

时间:2017-11-26 07:00:46

标签: java android flickr

所以我尝试构建Flickr应用程序。

在此我使用底部导航视图适配器在5个活动(相机,新闻,用户,搜索,Noti)之间切换。在相机活动我意图相机,但它继续崩溃。 代码是这样的:

CameraActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera1);
    Log.d(TAG, "onCreate: Started");

    photo = (ImageView)findViewById(R.id.dcm);
    button= (Button)findViewById(R.id.button);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            File file = getFile();
            Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
             camera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
            startActivityForResult(camera,CAMERA_REQUEST);
        }
    });

}

private File getFile() {
    File folder = new File("sdcard/camera_app");

    if (!folder.exists()){
        folder.mkdir();
    }
    File image_file = new File(folder,"cam_image.jpg");
    return  image_file;
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    String path = "sdcard/camera_app/cam_image.jpg";
    photo.setImageDrawable(Drawable.createFromPath(path));
setupBottomNavigationView();}

private void setupBottomNavigationView(){
    Log.d(TAG, "setupBottomNavigationView: Setting up bottom navigation view");
    BottomNavigationViewEx bottomNavigationView = (BottomNavigationViewEx) findViewById(R.id.bottomNavView);
    BottomNavigationViewHelper.setupBottomNavigationView(bottomNavigationView);
    BottomNavigationViewHelper.enableNavigation(CameraActivity.this, this, bottomNavigationView);
    Menu menu = bottomNavigationView.getMenu();
    MenuItem menuItem = menu.getItem(ActivityNumber);
    menuItem.setChecked(true);}

我也在清单中添加了相机活动。 AndroidManifest.xml

<uses-feature android:name="android.hardware.camera2"/>

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

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

这是我的Logcat :(我认为错误从这些开始形成):

11-26 14:39:29.480 4983-4983/usth.edu.vn.ictflickr E/AndroidRuntime: FATAL EXCEPTION: main
                                                                 Process: usth.edu.vn.ictflickr, PID: 4983
                                                                 android.os.FileUriExposedException: file:///sdcard/camera_app/cam_image.jpg exposed beyond app through ClipData.Item.getUri()
                                                                     at android.os.StrictMode.onFileUriExposed(StrictMode.java:1958)
                                                                     at android.net.Uri.checkFileUriExposed(Uri.java:2348)
                                                                     at android.content.ClipData.prepareToLeaveProcess(ClipData.java:941)
                                                                     at android.content.Intent.prepareToLeaveProcess(Intent.java:9735)
                                                                     at android.content.Intent.prepareToLeaveProcess(Intent.java:9720)
                                                                     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1609)
                                                                     at android.app.Activity.startActivityForResult(Activity.java:4472)
                                                                     at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
                                                                     at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67)
                                                                     at android.app.Activity.startActivityForResult(Activity.java:4430)
                                                                     at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:732)
                                                                     at usth.edu.vn.ictflickr.Camera.CameraActivity$1.onClick(CameraActivity.java:55)
                                                                     at android.view.View.performClick(View.java:6256)
                                                                     at android.view.View$PerformClick.run(View.java:24701)
                                                                     at android.os.Handler.handleCallback(Handler.java:789)
                                                                     at android.os.Handler.dispatchMessage(Handler.java:98)
                                                                     at android.os.Looper.loop(Looper.java:164)
                                                                     at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                                     at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

11-26 14:39:29.481 1361-3102/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 1554635 , only wrote 1554480

11-26 14:39:29.484 1623-1634/system_process W/ActivityManager:   Force finishing activity usth.edu.vn.ictflickr/.Camera.CameraActivity

11-26 14:39:29.490 1623-1641/system_process I/ActivityManager: Showing crash dialog for package usth.edu.vn.ictflickr u0

11-26 14:39:29.495 1623-1639/system_process E/memtrack: Couldn't load memtrack module

问题2:我想对捕获的图像应用一些过滤器然后将其上传到flickr?有谁知道怎么做?但是当我打开相机后,我的应用程序不会崩溃。感谢

0 个答案:

没有答案