I am implementing a shopping app.In that when a product is shared it should send a dynamic link so that when a person clicks it , opens in app only.Finally i achieved this feature.But when i am opening app from a shared dynamic link i am getting home page rather than product page.I need help regarding getting specific product page rather opening home page of shopping.
Here i am including code. AndroidManifest.xml
<activity android:name=".Postdetails">
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value="MainActivity" />
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="postdetailsnew.com" android:scheme="https"
android:pathPattern=".*"/>
</intent-filter>
</activity>
PostDetails.java Here PostDetails page is the single product design page or activity .In this i wrote following code.
sharebutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s="https://app_code.app.goo.gl/?link="+ProductLinkInBrowser+"&apn=com.example.maneesh.shop";
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, s);
sendIntent.setType("text/plain");
startActivity(sendIntent);
}
}
FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent())
.addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
#Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
// Get deep link from result (may be null if no link is found)
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
FirebaseAppInvite invite=FirebaseAppInvite.getInvitation(pendingDynamicLinkData);
if(invite!=null){
String invitationId=invite.getInvitationId();
}
}
}
})
.addOnFailureListener(this, new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.w("Heyy", "getDynamicLink:onFailure", e);
}
});
So here finally app main page is opened with dynamic link but not the specific product page which is shared.Please guide me to achieve this.
You need to parse the URL in the dynamic link, and fire an intent to send the user to the right part of your app. Generally you'll have the Dynamic Links listener set up in your main activity, and will route from there to any specific needs.
The deepLink variable in your code will be the URL your passed in the dynamic link, like http://yourshop.com/product/12345. You could call deepLink.getPath() which would return you product/12345, and then fire and intent for that, e.g:
String path = deepLink.getPath();
String[] parts = path.split("/")
if (parts[0] == "product") {
Intent intent = new Intent(this, PostDetails.class);
intent.putExtra("productid", parts[1]);
startActivity(intent);
}
Related
This is the link which i created to share an url of a particular product in java class
String url="http://www.example.com/productId/";
String finalurl = url + productId.getText().toString();
Intent i = new Intent(Intent.ACTION_SEND);
i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("*/*");
i.putExtra(Intent.EXTRA_STREAM, getLocalBitmapUri(bitmap));
i.putExtra(Intent.EXTRA_TEXT, name.getText().toString()+ "\n" + finalurl);
startActivity(Intent.createChooser(i, "Share Image"));
this is the intent filter that has created to an activity through App links Assistant
<activity
android:name=".login.Launchscreen"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.example.com"
android:pathPrefix="/productId"
android:scheme="http" />
</intent-filter>
<tools:validation testUrl="http://www.example.com/productId/" />
</activity>
this is the java code through which i can extract the data which i appended to my link
Intent intent = getIntent();
String appLinkAction = intent.getAction();
Uri appLinkData = intent.getData();
if (Intent.ACTION_VIEW.equals(appLinkAction) && appLinkData != null) {
proid = appLinkData.getLastPathSegment();
}
through above code i can share url through whatsapp and when i click on the shared app link it is redirecting to my app successfully but what i need is i want to redirect the user to play store when my application is not in his device and when the application is in his device he should be navigated to particular activity. can anyone help me please.All i want is in android app.Thanks in advance
You can check whether app is installed or not using package manager
final boolean isAppInstalled = appInstalledOrNot(\\ your URL package name\\);
private boolean appInstalledOrNot(String packagname) {
PackageManager pm = getActivity().getPackageManager();
try {
pm.getPackageInfo(packagname, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
// now check on your button click
if (isAppInstalled)
{
Intent LaunchIntent = getContext().getPackageManager().getLaunchIntentForPackage(\\ your URL package name\\);
getContext().startActivity(LaunchIntent);
} else {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(\\your URL\\));
} catch (android.content.ActivityNotFoundException anfe) {
anfe.printStackTrace();
}
}
you can use branch.io for create deep link and check app is not install go
to play store.
https://branch.io/how-branch-links-work/
step 1: Above link sign up
step 2: open branch dashboard
step 3. select Set Up SDK then open new page that page select your device
step 4: if you select android open new page that page contain this option
follow this
1.Enter app information
2.Get the SDK files
3.Configure Manifest
4.Start a Branch session
step 5: come back to dashboard see first option LIVE and TEST
1.you click live then select Account Setting see live key
2.you click test then select Account Setting see test key
<meta-data
android:name="io.branch.sdk.BranchKey"
android:value="put live key" />
<meta-data
android:name="io.branch.sdk.BranchKey.test"
android:value="put test key" />
if use test key for testing perpose, if you go to live set false
<meta-data
android:name="io.branch.sdk.TestMode"
android:value="true" />
step 6: go to link setting
1.see android
1.select two check box one I have an Android App and Enable app link
2.see Android URI Scheme enter your uri for if you install the app
you click the deep link open the app.
(example:appName://open)
3.see google play search for if you not install the app then redirect to
google play store
1.first you upload app to play store then search and set
4.set SHA256 Cert Fingerprints
5.see link domain option
1.use Default Link Domain link
<activity
android:name=".MainActivity"
android:alwaysRetainTaskState="true"
android:configChanges="orientation"
android:hardwareAccelerated="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="#style/MyAppTheme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="open"
android:scheme="set your android Scheme uri" />
<data
android:host="Default Link Domain link"
android:pathPrefix="/"
android:scheme="https" />
</intent-filter>
</activity>
step 7: click deep link handle on MainAtivity
public void onStart() {
super.onStart();
Branch branch = Branch.getInstance();
// Branch init
branch.initSession(new Branch.BranchReferralInitListener() {
#Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error == null) {
if(referringParams.has("post_id")){
mPostId = referringParams.getString("post_id");
}
} else {
Log.i("BRANCH SDK", error.getMessage());
}
}
}, this.getIntent().getData(), this);
}
step 8: create deep link for post or news in your app
try {
BranchUniversalObject buo = new BranchUniversalObject()
.setCanonicalIdentifier("app/launch")
.setTitle("appName")
.setContentDescription(postContent)
.setContentImageUrl(imageUrl)
.setContentIndexingMode(BranchUniversalObject.CONTENT_INDEX_MODE.PUBLIC)
.setContentMetadata(new ContentMetadata()
.addCustomMetadata("install", "true")
.addCustomMetadata("TYPE", "POST")
.addCustomMetadata("post_id", "" + postId));
LinkProperties lp = new LinkProperties().setChannel("url_share")
.setFeature("sharing")
.setCampaign("post share")
.setStage("cricspace")
.addControlParameter("$desktop_url", "your app web link")
.addControlParameter("mobile", mobileNo)
.addControlParameter("post_id", "" + postId)
.addControlParameter("TYPE", "POST")
.addControlParameter("custom_random",
Long.toString(Calendar.getInstance().getTimeInMillis()));
ShareSheetStyle shareSheetStyle = new ShareSheetStyle(context, "Check this
out!", postContent)
.setCopyUrlStyle(context.getResources().
getDrawable(android.R.drawable.ic_menu_send), "Copy", "Added to
clipboard")
.setMoreOptionStyle(context.getResources().
getDrawable(android.R.drawable.ic_menu_search), "Show more")
.addPreferredSharingOption(SharingHelper.SHARE_WITH.FACEBOOK)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.WHATS_APP)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.GMAIL)
.addPreferredSharingOption
(SharingHelper.SHARE_WITH.FACEBOOK_MESSENGER)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.HANGOUT)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.INSTAGRAM)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.WECHAT)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.TWITTER)
.setAsFullWidthStyle(true)
.setSharingTitle("Share With");
// buo.setContentDescription(postModel.getPostContent()+"\n\n"
+deepLinkReferralURL );
buo.generateShortUrl(context, lp, (url, error) -> {
if (error == null) {
buo.showShareSheet((AppCompatActivity) context, lp,
shareSheetStyle, new Branch.BranchLinkShareListener() {
#Override
public void onShareLinkDialogLaunched() {
onCallBack.onShareLinkDialog();
}
#Override
public void onShareLinkDialogDismissed() {
}
#Override
public void onLinkShareResponse(String sharedLink, String
sharedChannel, BranchError error) {
}
#Override
public void onChannelSelected(String channelName) {
}
});
}
});
} catch (Exception e) {
Log.e("error", e.toString());
}
How should be my android manifest file if I want to show my app in the chooser apps if someone clicks the dynamic link? The URL prefix is like -
https://testapp.page.link. At that stage if someone clicks the link then it first opens the browser then it redirects to my app. But I want to show my app in the chooser app list. At this time my manifest file is like follows-
<activity android:name=".extraActivities.DynamicLinkActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="test.com"
android:pathPattern="https://testapp.page.link*"
android:scheme="https"
/>
</intent-filter>
</activity>
We need to write intent-filter in the manifest file as follows-
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="testapp.com"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="testapp.page.link"
android:scheme="https"
android:pathPattern=".*"/>
</intent-filter>
Where "testapp.page.link" is the actually the URL prefixes shown at the top left corner of Firebase dynamic link console. And "testapp.com" is the first part of any link. Eg: https://testapp.com/user_profile?id="Zsdsdjwenncsdmsd". From this link, we can extract the user Id as "Zsdsdjwenncsdmsd" at the receiving end of the dynamic link. A complete example is shown below-
If anyone clicks share button this will create the dynamic link-
shareBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
shareProgressBar.setVisibility(View.VISIBLE);
Task<ShortDynamicLink> shortDynamicLinkTask = buildDeepLink(getString(R.string.grp_post_link)+postsModel.getPostId()+"&groupKey="+postsModel.getGroupKey()+"&groupName="+ dataSnapshot.getValue(String.class));
shortDynamicLinkTask.addOnCompleteListener(new OnCompleteListener<ShortDynamicLink>() {
#Override
public void onComplete(#NonNull Task<ShortDynamicLink> task) {
grpPostsViewHolder.shareProgressBar.setVisibility(View.GONE);
if(task.isSuccessful()){
Uri uri = task.getResult().getShortLink();
share(dataSnapshot.getValue(String.class), uri.toString());
}else {
Toast.makeText(context, "Can't create link", Toast.LENGTH_SHORT).show();
}
}
});
shortDynamicLinkTask.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
shareProgressBar.setVisibility(View.GONE);
}
});
The dynamic link creator function and share function-
/*-----------------------------------------------------------------------------*/
private Task<ShortDynamicLink> buildDeepLink(String deepLink) {
String uriPrefix = getString(R.string.dynamic_links_uri_prefix);
return FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse(deepLink))
.setDomainUriPrefix(uriPrefix)
.setNavigationInfoParameters(new DynamicLink.NavigationInfoParameters.Builder()
.build())
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder()
.setMinimumVersion(3)
.build())
.buildShortDynamicLink();
}
/*-----------------------------------------------------------------------------*/
private void share(String name, String deepLink) {
String message = "Find "+name+" on SelfieLe - link: "+deepLink;
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(intent);
}
/*---------------------------------------------------------------------------------*/
The String resources are-
R.string.grp_post_link, and R.string.dynamic_links_uri_prefix:
<string name="user_profile_link">https://testapp.com/user_profile?id=</string>
<string name="dynamic_links_uri_prefix">https://testapp.page.link</string>
At receiving end we can extract postId, groupKey etc as follows
FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent()).addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
#Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
}
if (deepLink != null) {
getGrpPost(deepLink.getQueryParameter("id"), deepLink.getQueryParameter("groupKey"), deepLink.getQueryParameter("groupName"));
}else {
Toast.makeText(DynamicLinkActivity.this, "Can't find link", Toast.LENGTH_SHORT).show();
}
}
}).addOnFailureListener(this, new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(DynamicLinkActivity.this, "Can't find link", Toast.LENGTH_SHORT).show();
}
});
The getGroupPost(); is as follows
private void getGrpPost(String id, String groupKey, final String groupName) {
//Do what you want
}
Problem:
Why is "Short dynamic links" created programatically wont open/launch the app directly?
But link created at console, shows only one prompt to choose browser then app launches directly.
I want to launch app directly when user clicks the dynamic url created dynamically by android app.
When clicking dynamic short link created dynamically by android app the following things happen,
1.Option to open in browser shows
2.The browser opens,shows a loading dialog box
3.Again shows option to open in browser(this time app shows in the more options area)
4.Clicking browser opens website,clicking app lauches app but the deep link is lost.
Any Help would be great.
Manifest.xml
...
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="notifika.tupio.me"
android:scheme="https" />
</intent-filter>
...
Link Generation
public void createDynamicLink(final Context context, final SingleNotification notification){
final Uri[] mInvitationUrl = {null};
String link = "https://notifika.tupio.me/?public=" + notification.getTag();
FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse(link))
.setDynamicLinkDomain("notifika.page.link")
.setAndroidParameters(
new DynamicLink.AndroidParameters.Builder("me.tupio.notifika")
.build())
.setGoogleAnalyticsParameters(
new DynamicLink.GoogleAnalyticsParameters.Builder()
.setSource("In-App")
.setMedium("social")
.setCampaign("Word-Word")
.build())
.setSocialMetaTagParameters(
new DynamicLink.SocialMetaTagParameters.Builder()
.setTitle("Notifika")
.setDescription("Sent and Receive Notification like this.Download the app now")
.build())
.buildShortDynamicLink()
.addOnSuccessListener(new OnSuccessListener<ShortDynamicLink>() {
#Override
public void onSuccess(ShortDynamicLink shortDynamicLink) {
mInvitationUrl[0] = shortDynamicLink.getShortLink();
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, notification.getTitle()+"\n"+notification.getMessage().substring(0, Math.min(notification.getMessage().length(), 100)) + "..." +context.getResources().getString(R.string.share_link_desc)+"\n"+mInvitationUrl[0]);
context.startActivity(Intent.createChooser(intent, "Share"));
}
});
}
MainActivity.class
FirebaseDynamicLinks.getInstance()
.getDynamicLink(getIntent())
.addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
#Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
// Get deep link from result (may be null if no link is found)
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
Log.v("Deeplink",deepLink.toString());
}
//
// If the user isn't signed in and the pending Dynamic Link is
// an invitation, sign in the user anonymously, and record the
// referrer's UID.
//
if (deepLink != null
&& deepLink.getBooleanQueryParameter("public",false)) {
String referrerUid = deepLink.getQueryParameter("public");
Log.v("Deeplink", referrerUid);
Toast.makeText(getApplicationContext(),referrerUid,Toast.LENGTH_LONG).show();
}
}
});
Followed this guide.
You'll need to add an intent filter for your page.link/app.goo.gl domain as well, so the deep link goes straight to your app. See: https://firebase.google.com/docs/dynamic-links/android/receive#app_links
I'm working with the instagram API and I don't understand what I should put in for the redirect api. At the moment I simply put in https://127.0.0.1
But I dont really understand. Also, once I get the allow/cancel screen and I press allow it gives me an error saying that I cant go to that address but I can also see the authorization code appended on to the address. So how can i redirect back from my redirect uri? How can I tell android that after user clicks allow to come back into the app use the code for further authentication?
Im sure you will say something like make my own custom scheme/ intent filters etc but please be a little more supportive im new and I dont understand and I did do research on them.
My on resume method is below
#Override
protected void onResume() {
super.onResume();
// the intent filter defined in AndroidManifest will handle the return from ACTION_VIEW intent
Uri uri = getIntent().getData();
if (uri != null && uri.toString().startsWith(redirectUri)) {
// use the parameter your API exposes for the code (mostly it's "code")
String code = uri.getQueryParameter("code");
if (code != null) {
// get access token
LoginService loginService =
ServiceGenerator.createService(LoginService.class, clientId, clientSecret);
AccessToken accessToken = loginService.getAccessToken(code, "authorization_code");
} else if (uri.getQueryParameter("error") != null) {
// show an error message here
}
}
}
This is my manifest snippet dealing with intent filters:
<activity
android:name=".LoginActivity"
android:label="#string/title_activity_login" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="redirecturi"
android:scheme="your" />
</intent-filter>
</activity>
You have to setup an event listener on the browser view and check for code in URL param if the URL is equal to the redirect_uri, and then make POST request to the auth URL using the code and client_secret as documented in Instagram authentication
something like this:
webView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
String code = url.getQueryParameter("code");
// ...
}
});
I have option in my app to start browser and load imdb website.
I'm using ActionView for this.
Intent intent1 = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse(website));
try {
activity.startActivity(intent1);
} catch (Exception e) {
Toast.makeText(activity, R.string.no_imdb, Toast.LENGTH_SHORT)
.show();
}
The problem occurs when I tap on back button.
When default browser app is launched everything is ok.
When Opera Mini app is launched, when I tap on back button, it seems like my app receives two back actions, and finish my current activity.
How to prevent this?
Try starting the intent in a new task:
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Or
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Please add this code to your android manifest for activity that you need return
<activity
android:name="YourActivityName"
android:launchMode="singleTask">
<intent-filter>
<action android:name="schemas.your_package.YourActivityName" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.ALTERNATIVE" />
</intent-filter>
</activity>
and add this to your web page
click to load app
because only one app has this action name (schemas.your_package.YourActivityName) on your phone, web page directly return to app
Also You can Use Airbnb DeepLink lib
Example
Here's an example where we register SampleActivity to pull out an ID from a deep link like example://example.com/deepLink/123. We annotated with #DeepLink and specify there will be a parameter that we'll identify with id.
#DeepLink("example://example.com/deepLink/{id}")
public class SampleActivity extends Activity {
#Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (intent.getBooleanExtra(DeepLink.IS_DEEP_LINK, false)) {
Bundle parameters = intent.getExtras();
String idString = parameters.getString("id");
// Do something with idString
}
}
}