onActivityResult RESULT_OK can not be resolved to a variable in android?

前端 未结 3 594
孤城傲影
孤城傲影 2021-01-31 13:41

I am trying to launch camera in fragment but onActivityResult in fragment doesn\'t resolve RESULT_OK. What should i do?

I am launching camera using:

publ         


        
相关标签:
3条回答
  • 2021-01-31 13:56

    RESULT_OK is constant of Activity class. In Activity class you can access directly but in other classes you need to write class name (Activity) also.

    Use Activity.RESULT_OK instead of RESULT_OK.


    In your case it will be

    if (requestCode == CAMERA_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
    
    0 讨论(0)
  • 2021-01-31 14:04

    In fragment we must use getActivity() method as prefix with RESULT_OK.

    In your case it will be:-

    if (requestCode == CAMERA_REQUEST_CODE && resultCode == getActivity().RESULT_OK)
    
    0 讨论(0)
  • 2021-01-31 14:04

    Alternatively you can add import static android.app.Activity.RESULT_OK; and use it in your case like if (requestCode == CAMERA_REQUEST_CODE && resultCode == RESULT_OK) {..}

    0 讨论(0)
提交回复
热议问题