Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for app links intent #160

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
local.properties
.env
upload-keystore.jks

# Autogenerated on build. See build.gradle
samples/MobileBuyIntegration/src/main/AndroidManifest.xml
11 changes: 11 additions & 0 deletions samples/MobileBuyIntegration/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,14 @@ dependencies {
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
}

task generateAndroidManifestFromTemplate {
doLast {
def templateFile = file('src/main/AndroidManifest.template.xml')
def outputFile = file('src/main/AndroidManifest.xml')
def content = templateFile.getText('UTF-8').replace('{{STOREFRONT_DOMAIN}}', "$storefrontDomain")
outputFile.write(content, 'UTF-8')
}
}

preBuild.dependsOn(generateAndroidManifestFromTemplate)
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@
<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:scheme="https"
android:host="{{STOREFRONT_DOMAIN}}"
android:pathPrefix="/" />
</intent-filter>

<meta-data
android:name="android.app.lib_name"
android:value="" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
* MIT License
*
*
* Copyright 2023-present, Shopify Inc.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -23,6 +23,7 @@
package com.shopify.checkout_sdk_mobile_buy_integration_sample

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
Expand Down Expand Up @@ -94,6 +95,33 @@ class MainActivity : ComponentActivity() {
geolocationPermissionCallback = null
geolocationOrigin = null
}

handleIntent(intent)
}

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
Timber.d("[INTENT] NEW INTENT")
handleIntent(intent)
}

private fun handleIntent(intent: Intent) {
Timber.d("[INTENT] HANDLING INTENT")
if (intent.action == Intent.ACTION_VIEW) {
intent.data?.let { uri ->
if (uri.path == "/cart") {
Timber.d("Navigating to Cart")
// Logic to navigate to the cart screen
navigateToCart()
}
}
}
}

private fun navigateToCart() {
// Replace this with actual navigation logic to your cart feature
Timber.d("Cart path received, launching cart UI")
// Example: startActivity(Intent(this, CartActivity::class.java))
}

// Show a file chooser when prompted by the event processor
Expand Down
Loading