'Receive Images from another app to our app

So when I am in other media apps like google photos I select an image and click the share button then in the share window I want my app to be displayed so that i can click it and get that image to my app. I have build a simple chat application where users can send text and images to each other where all the data is stored in Firebase. So when one clicks my app in the sharing screen the image should take me to the Chat activity where i have all my chats so that i click one of my chats and the image is then sent to them. So how to achieve this process?I have searched everywhere and couldn't get the hang of the right tutorial all i am finding is sharing data from our app and not from other app to our app. Thank you.

Edit : I have created a separate activity that should be launched when a user choses to share a image from other app.But when i click my app in the sharing menu then my app goes all white screen instead of launching the SharingActivity. Below is my code and manifest file.

SharingActivity.java

package com.pappu5.navigation;


public class SharingActivity extends AppCompatActivity {

    FirebaseRecyclerAdapter<FriendsData, SharingActivity.ShareHolder> frv;
    private RecyclerView rv;
    private DatabaseReference dr, drUsers;
    private FirebaseAuth auth;
    private String user;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);


        rv = (RecyclerView) findViewById(R.id.friendsView);
        auth = FirebaseAuth.getInstance();
        user = auth.getCurrentUser().getUid();
        dr = FirebaseDatabase.getInstance().getReference().child("Friends_Formed").child(user);
        drUsers = FirebaseDatabase.getInstance().getReference().child("Chat_Profiles");
        dr.keepSynced(true);
        drUsers.keepSynced(true);
        rv.setHasFixedSize(true);
        rv.setLayoutManager(new LinearLayoutManager(getApplicationContext()));

        Query personsQuery = dr.orderByKey();

        FirebaseRecyclerOptions<FriendsData> options =
                new FirebaseRecyclerOptions.Builder<FriendsData>().setLifecycleOwner(this)
                        .setQuery(personsQuery, FriendsData.class)
                        .build();

        frv = new FirebaseRecyclerAdapter<FriendsData, SharingActivity.ShareHolder>(options) {
            @Override
            protected void onBindViewHolder(@NonNull final SharingActivity.ShareHolder holder, int position, @NonNull FriendsData model) {
                holder.setDate(model.getDate());
                holder.setImage(model.getThumb_image());

                final String listUsers = getRef(position).getKey();

                if (!listUsers.equals(null))

                    drUsers.child(listUsers).addValueEventListener(new ValueEventListener() {
                        @Override
                        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                            final String username = dataSnapshot.child("name").getValue().toString();
                            String thumb = dataSnapshot.child("thumb_image").getValue().toString();
                            //String online  = dataSnapshot.child("onlineStatus").getValue().toString();

                            if (dataSnapshot.hasChild("onlineStatus")) {
                                String userOnline = dataSnapshot.child("onlineStatus").getValue().toString();
                                holder.setOnlineStatus(userOnline);
                            }

                            holder.setName(username);
                            holder.setImage(thumb);
                            //holder.setOnlineStatus(online);

                            holder.view.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    CharSequence[] actions = new CharSequence[]{"Share to " + username};
                                    AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
                                    builder.setTitle("Select an Action");
                                    builder.setItems(actions, new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            if (i == 0) {

                                                Intent intent = new Intent(getApplicationContext(), ChatActivity.class);
                                                intent.putExtra("id", listUsers);
                                                intent.putExtra("user_name", username);
                                                startActivity(intent);
                                            }
                                        }
                                    });
                                    builder.show();
                                }
                            });


                        }

                        @Override
                        public void onCancelled(@NonNull DatabaseError databaseError) {

                        }
                    });

            }

            @NonNull
            @Override
            public SharingActivity.ShareHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View view = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.friends_status, parent, false);

                return new SharingActivity.ShareHolder(view);
            }
        };
        rv.setAdapter(frv);


    }


    public static class ShareHolder extends RecyclerView.ViewHolder {

        View view;

        public ShareHolder(View itemView) {
            super(itemView);

            view = itemView;
        }

        public void setDate(String date) {
            TextView username = (TextView) view.findViewById(R.id.status2);
            username.setText(date);
        }

        public void setImage(String image) {
            CircleImageView thumb = (CircleImageView) view.findViewById(R.id.circleImageView2);
            Picasso.get().load(image).placeholder(R.drawable.default_avatar).into(thumb);

        }

        public void setName(String name) {
            TextView username = (TextView) view.findViewById(R.id.name2);
            username.setText(name);
        }

        public void setOnlineStatus(String onlineStatus) {
            ImageView image = (ImageView) view.findViewById(R.id.onlineStatus);

            if (onlineStatus.equals("true")) {
                image.setVisibility(View.VISIBLE);
            } else {
                image.setVisibility(View.INVISIBLE);
            }
        }


    }


}




AndroidManifest.xml

<activity android:name=".SharingActivity">
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="text/plain" />
                <data android:mimeType="image/*" />
            </intent-filter>
        </activity>




Solution 1:[1]

You have to add below code inside Manifest.xml under activity tag like

<activity
        android:name=".MainActivity"
        android:configChanges="orientation"
        android:noHistory="true"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustPan">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        // below code with show your app as sharing option
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="text/plain" />
        </intent-filter>

    </activity>

You can change mimeType according to your need. Hope this will help you.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sanwal Singh