gpt4 book ai didi

java - 为什么 addIntentsToList 方法给出错误 'Cannot resolve the method'

转载 作者:行者123 更新时间:2023-12-02 04:48:00 24 4
gpt4 key购买 nike

我正在尝试创建一个程序,可以拍摄照片或从图库中拍摄照片,然后将其显示在 ListView 上,我在视频的帮助下完成了所有操作,但是 addIntentsToList 方法给出了错误“无法解析”方法”

       try {

mTempPhoto = createTempImageFile(getExternalCacheDir());
mImageUri = mTempPhoto.getAbsolutePath();


List<Intent> intentList = new ArrayList<>();
Intent chooserIntent = null;


Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

takePhotoIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTempPhoto));

intentList = addIntentsToList(this, intentList, pickIntent);
intentList = addIntentsToList(this, intentList, takePhotoIntent);

if (!intentList.isEmpty()) {
chooserIntent = Intent.createChooser(intentList.remove(intentList.size() - 1),"Choose your image source");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentList.toArray(new Parcelable[]{}));
}

startActivityForResult(chooserIntent, REQUEST_CODE_TAKE_PHOTO);
} catch (IOException e) {
Log.e("ERROR", e.getMessage(), e);
}
}
}

最佳答案

您遇到此错误是因为该方法未实现。

当您使用 @Mariovc 代码时,您应该使用整个类 https://gist.github.com/Mariovc/f06e70ebe8ca52fbbbe2

private static List<Intent> addIntentsToList(Context context, List<Intent> list, Intent intent) {
List<ResolveInfo> resInfo = context.getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : resInfo) {
String packageName = resolveInfo.activityInfo.packageName;
Intent targetedIntent = new Intent(intent);
targetedIntent.setPackage(packageName);
list.add(targetedIntent);
Log.d(TAG, "Intent: " + intent.getAction() + " package: " + packageName);
}
return list;
}

关于java - 为什么 addIntentsToList 方法给出错误 'Cannot resolve the method',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56466418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com