What is the data's that chrome intent shares with android apps-ThrowExceptions

Exception or error:

I’m trying to grab information from chrome intent. the scenario is when I share a web page from chrome or any other browser with my application I want to grab the title and an image and let’s say a short description and store it into my app. But the issue is as far as I did research the only thing I get from the chrome intent is the URL. so the question is how to find out what chrome intent shares with my app if I can grab extra data beside the URL how to grab it?
the code below grabs only the URL from chrome, so how to grab web page title and image?

androidManifest.xml

<activity
            android:name=".WebActivity"
            android:parentActivityName=".MainActivity"
            android:theme="@style/AppTheme.NoActionBar"></activity>
        <activity
            android:name=".GetDataActivity"
            android:parentActivityName=".MainActivity"
            android:theme="@style/AppTheme.NoActionBar">
            <!-- Used to handle Chrome then menu then share.-->
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:mimeType="text/plain" />
                <data android:mimeType="image/*" />
            </intent-filter>
        </activity>

GetDataActivity.java

public class GetDataActivity extends AppCompatActivity {

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

        // Get intent, action and MIME type
        Intent intent = getIntent();
        String action = intent.getAction();
        String type = intent.getType();

        if (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 (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
            if ("text/plain".equals(type)) {
                handleSendMultipleTexts(intent); // Handle multiple images being sent
            }
        } else {
            // Handle other intents, such as being started from the home screen
        }
    }

    void handleSendText(Intent intent) {
        String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
        if (sharedText != null) {
            TextView datTitle = findViewById(R.id.dataTitle);
            datTitle.setText(sharedText);
        }
    }

    void handleSendImage(Intent intent) {
        Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
        if (imageUri != null) {
            ImageView datImage = findViewById(R.id.dataImage);
            datImage.setImageURI(imageUri);
        }
    }

    void handleSendMultipleTexts(Intent intent) {
        ArrayList<Uri> imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        if (imageUris != null) {
            // Update UI to reflect multiple images being shared
        }
    }
}
How to solve:

Chrome browser on mobile not sharing anything except the link or url,. So I was thinking of a way to grab information like image and title form my mobile app in the device. But that’s not how it works. You only have the link so you have two options one is to send the link to your server and grab the information in away you want like crawling or grabbing metadata or graph data’s. The other is doing the same thing in your mobile app in the device which it’s almost impossible.

Leave a Reply

Your email address will not be published. Required fields are marked *