Search code examples
androidnativescriptintentfilter

How to show chooser Intent with my own android app on click of whatsapp profile image share


I’m trying to show my native script app as a chooser intent when whats app profile image share button on top right was clicked, and want to know how to handle those things within my app. Where do I need to add the code to display image inside my app upon click my app in the chooser intent?

i'have found similar issue here How to show chooser Intent with my own android app on click of WhatsApp location? where it is given for map, but i want it for image.

I expect to open the image of whats app profile, on tap of intent and display that image inside my app. and let the user choose save or cancel in user defined folder structure. can anyone guide me?

i tried this to handle incoming image but its not working.

let intent = android.getIntent();
let action = android.intent.getAction();
let type = android.intent.getType();

if (android.intent.ACTION_SEND.equals(action) && type != null) {
    if ("text/plain".equals(type)) {
        handleSendText(intent); // Handle text being sent
    } else if (type.startsWith("image/")) {
        handleSendImage(intent); // Handle single image being sent
    }
} else if (android.intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
    if (type.startsWith("image/")) {
        handleSendMultipleImages(intent); // Handle multiple images being sent
    }
} else {
    // Handle other intents, such as being started from the home screen
}

function handleSendImage(intent) {
    var imageUri = intent.getParcelableExtra(android.intent.EXTRA_STREAM);
    console.log("-----image uri-------");
    console.log(imageUri);
    if (imageUri != null) {
        // Update UI to reflect image being shared
    }
}

Solution

  • You have to update your intent-filter for NativeScript Activity to let system know your Activity can handle selection of an image.

    <activity android:name="com.tns.NativeScriptActivity"...>  
    
      ...
    
      <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="image/*" />
      </intent-filter>   
    
    </activity>