2

I have used this example so that other applications can call my activity to receive data from them.

Specifically, I want when uploading an image from a browser my application can supply that image.

In the following image can see that case. A list of applications that provide images when the user clicks upload file:

enter image description here

I used this code that is copied from the link I added to the start.

    <activity
        android:name=".LoginActivity"
        android:label="@string/title_activity_login">
        <!-- filter for sending text or images; accepts SEND action and text or image data -->
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/*" />
            <data android:mimeType="text/plain" />
        </intent-filter>
    </activity>

I can not get my app to appear in the apps list shown in the photo.

Also I test this, as @Avi suggests:

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

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.APP_BROWSER" />
            <category android:name="android.intent.category.BROWSABLE" />

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

Getting the same results

Note: I am using the chrome browser in Android

user3782779
  • 1,669
  • 3
  • 22
  • 36

3 Answers3

0

Change below line

<action android:name="android.intent.action.SEND" />

to

<action android:name="android.intent.action.VIEW" />
0

I got my app to appear in the browser when uploading an image with the following code.

        <intent-filter>
            <action android:name="android.media.action.IMAGE_CAPTURE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.media.action.STILL_IMAGE_CAMERA" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
user3782779
  • 1,669
  • 3
  • 22
  • 36
0

Try this-

Manifest file:

<activity
    android:name=".activities.HomeActivity"
    android:label="@string/app_name">
    <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>

Your MainActivity file:

val data: Uri? = intent?.data

// Figure out what to do based on the intent type
if (intent?.type?.startsWith("image/") == true) {
    // This handles the intents with image data or of any other type based on your specified condition.
} else if (intent?.type == "text/plain") {
    // This handle the intents with text or based on your conditions
    //Use any popup like toast, snackbar, dialog, etc of your preference.
}

And also please do check whether you have mentioned your action as VIEW or SEND. If its a VIEW it wont reflect in your result but if its SEND then it will work. Check for this if in any of the file you have mentioned this-

val sendIntent = Intent(Intent.ACTION_SEND)   //Replace to SEND if you have used ACTION_VIEW

sendIntent.type = "image/*"
val title = context?.resources?.getString(R.string.chooser_text)
if (context?.packageManager != null) {
    context?.startActivity(Intent.createChooser(sendIntent, title))
}

And if you want to fetch the result of your action the insert this too...

Intent("com.example.RESULT_ACTION", Uri.parse("content://result_uri")).also { result ->
    setResult(Activity.RESULT_OK, result)
}
finish()

For better understanding of this flow, refer this -> https://developer.android.com/training/basics/intents/filters