sending image from 1st app to 2nd app using implicit intent

18 views Asked by At

I am trying to send some text and an image through implicit intent from 1st app to 2nd app .the text is sent from 1st app to 2nd app and it's showing on my 2nd app but the image isn't showing on my 2nd app.

this is the app1 java code (sending intent ) I have tried.

`
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void process(View view) {
        if (view.getId() == R.id.sharebtn) {
            Uri imageUri = Uri.parse("android.resource://com.example.lab6_implicitintent/drawable/jasmine");
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("image/*");
            intent.putExtra(Intent.EXTRA_STREAM, imageUri);
            intent.putExtra(Intent.EXTRA_TEXT, "Hey, my name is summaiya");
            startActivity(Intent.createChooser(intent, "Send image to"));
        }
    }
}`

this is app 2 code (receiving intent).


`public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Receive the intent
        Intent receivedIntent = getIntent();
        String receivedText = receivedIntent.getStringExtra(Intent.EXTRA_TEXT);
        Uri receivedImageUri = receivedIntent.getParcelableExtra(Intent.EXTRA_STREAM);

        // Display the received text in a TextView
        TextView textView = findViewById(R.id.textView);
        textView.setText(receivedText);

        // Display the received image in an ImageView
        ImageView imageView = findViewById(R.id.imageView);
        imageView.setImageURI(receivedImageUri);
    }
}
0

There are 0 answers