English 中文(简体)
在活动从零碎裂开始时,不要求采取行动
原标题:onActivityResult() not called when Activity started from Fragment

我有一个问题,即从安乐文的书库中提取照片,因为从来没有使用<条码>代谢()。

这是我所写的法典(从零碎块而不是一种活动):

Intent galleryIntent = new Intent(Intent.ACTION_PICK,  android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
getActivity().startActivityForResult(galleryIntent, PICK_IMAGE);

顺便说一句,我已经界定了“<>代谢”(),但从未启动过:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(TAG, "onActivityResult"); // not printed
}

任何想法对此有什么错误?

感谢!

最佳回答

若要有<条码>活性效果(),请将<条码>的零散版本改为<条码>活性效果(,而不是活动页数。 因此,在您的碎片代码中,替换

getActivity().startActivityForResult(galleryIntent, PICK_IMAGE);

iii

startActivityForResult(galleryIntent, PICK_IMAGE);
问题回答

该法典载有:

Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
getActivity().startActivityForResult(galleryIntent, PICK_IMAGE);

在职者必须参与包含分裂性的活动。 从那里,你可以把碎片的任何方法,而不是碎片。

MyFragment myFragment = (MyFragment) getSupportFragmentManager().findFragmentById(R.id.fragment);
myFragment .onCameraResult(requestCode, resultCode, intent);

页: 1

Try this Snippet :

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
    intent.setType("image/*");
    intent.putExtra("return-data", true);
    startActivityForResult(intent, 1);


    @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {

        case 1:
            if(requestCode == 1 && data != null && data.getData() != null){
                Uri _uri = data.getData();

                if (_uri != null) {
                    Cursor cursor = getContentResolver().query(_uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
                    cursor.moveToFirst();
                    final String imageFilePath = cursor.getString(0);
                    File photos= new File(imageFilePath);
                    imageView.setImageBitmap(bitmap);
                    cursor.close();
                }
            }
            super.onActivityResult(requestCode, resultCode, data);
        }
    }   




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签