2

В приложении есть своя галерея, но не могу в ней выбрать картинку через ACTION_GET_CONTENT. Галерея запускается но при клике по картинке ничего не происходит, андроид монитор молчит. В других галереях картинка выбирается.Как мне кажется моя галерея не передает URI картинки. В чем проблема? Где я туплю? Код ниже

 @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.safr);

    sp = getSharedPreferences("resume", MODE_PRIVATE);

    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    startActivityForResult(intent, SELECT_PICTURE);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (resultCode == RESULT_OK) {
        if (requestCode == SELECT_PICTURE)
        {
            Uri selectedImageUri = data.getData();
            selectedImagePath = getPath(selectedImageUri);
            try {
                FileInputStream fileis=new FileInputStream(selectedImagePath);
                BufferedInputStream bufferedstream=new BufferedInputStream(fileis);
                byte[] bMapArray= new byte[bufferedstream.available()];
                bufferedstream.read(bMapArray);

                if (fileis != null)
                {
                    Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.setType("image/*");
                    intent.putExtra(Intent.EXTRA_STREAM, selectedImageUri);
                    startActivityForResult(Intent.createChooser(intent, ""), SELECT_PICTURE);
                }
                if (bufferedstream != null)
                {
                    bufferedstream.close();
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    int column_index = cursor
            .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);

}

Галерея представляет собой GridView, код адаптера

public class Adapter extends ArrayAdapter<File> {

LayoutInflater mInflater;
Picasso mPicasso;
private static final String TAG = "myLogs";

public Adapter(Context context, File[] objects) {
    super(context, R.layout.list_item, objects);
    mInflater = LayoutInflater.from(context);
    mPicasso = Picasso.with(context);
}

@Override
public View getView ( final int position, View convertView, ViewGroup parent){

    View view = convertView;
         if (view == null) {
             view = mInflater.inflate(R.layout.list_item, parent, false);
         }
    ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
    mPicasso.load(getItem(position)).fit().centerCrop().into(imageView);

    return view;
}

}

Манифест

<activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.GET_CONTENT" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.OPENABLE" />
            <data android:mimeType="image/*" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.PICK"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="image/*"/>
        </intent-filter>
2
  • 1
    вам нужно показать на каком этапе ошибка, и intent-filter компонента с которым вы пытаетесь работать, после вызова. 27 авг 2016 в 23:26
  • отредактировано
    – evb
    28 авг 2016 в 17:42

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Посмотрите другие вопросы с метками или задайте свой вопрос.