Reputation: 1095
What I want is to share the link of specific page of my application. Suppose I am in a profile page of some user in my app and I want to share that user to some of my friends so I would like to share it via WhatsApp and other applications.
So basically I want to share a link to my app.
This is what I am doing right 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's partially done. if user hasn't installed my app then this code redirect him to google play store page to download this app.
Main problem is when user have already this app this link just opens the app. I want to redirect user to that specific page when he clicks on a link.
How can I do this?
I heard something about intent-filter
but 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" />
UPDATED
Now I am trying to share my app link 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"));
Inside my manifest I have declared an activity like this
<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>
But I am still not able to see my app when I click on the link I shared using WhatsApp or any other means.
Please help me
Any help will be really appreciated. Thanks in advance.
Upvotes: 4
Views: 3189
Reputation: 12976
Add the following intent-filters to your activity declaration, in the AndroidManifest of your project :
<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() method of your activity lifecycle, you can use the getData() of the intent that has fired your activity.
Upvotes: 3