Android – how do I open my app when I click the app link?
I want to share a link to a specific page of my application. Suppose I'm in a user's profile page in my application and want to share that user with some of my friends, so I want to share it with other applications through WhatsApp
So basically I want to share a link to my application
That's what I'm doing now
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=" + activity.getPackageName());
activity.startActivity(Intent.createChooser(shareIntent, "Share"));
I know this is not what I really want, but it is partially completed. If the user has not installed my app, this code will redirect it to the Google play store page to download the app
The main problem is that when the user already owns this application, this link will only open the application. I want to redirect the user to this specific page when the user clicks the link
How can I do this?
I've heard about intent filters, but I'm not sure how to use them
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/pdf" />
to update
Now, I try to share my app links like this
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra("PostID", postID);
shareIntent.putExtra("UserID", userID);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=" + activity.getPackageName());
activity.startActivity(Intent.createChooser(shareIntent, "Share"));
I declare such activities in the list
<activity
android:name=".activities.ShareActivity"
android:screenOrientation="sensorPortrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
<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:host="details"
android:scheme="market" />
<data
android:host="play.google.com"
android:pathPattern="/store/apps/details?id=my_package_name"
android:scheme="http" />
<data
android:host="play.google.com"
android:pathPattern="/store/apps/details?id=my_package_name"
android:scheme="https" />
</intent-filter>
</activity>
However, when I click the link shared using WhatsApp or any other way, I still can't see my application
Please help me
Any help would be appreciated. Thank you in advance
resolvent:
In the androidmanifest of your project, add the following intent filters to your activity statement:
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
Now, in the oncreate(), onresume(), or onnewintent() methods of the activity lifecycle, you can use getdata(), which triggers the intent of the activity