Skip to content
Open
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
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,32 @@ allprojects {
val response = Verify.isPurchased(this, PACKAGE_ID)
val userName = response.second
val isPaid = response.first
val isInsallApklis = response.third
```


* Check paid Java
```java
Pair<Boolean, String> response = Verify.Companion.isPurchased(this, PACKAGE_ID);
Triple<Boolean, Boolean, String> response = Verify.Companion.isPurchased(this, PACKAGE_ID);
String userName = response.getSecond();
Boolean isPaid = response.getFirst();
Boolean isInsallApklis = response.getThird();
```

* Show alert Kotlin
```kotlin
// ACTION: 1 Apklis is not install, 2 User not logged in, 3 App not purchased
Verify.showAlert(this, ACTION, PACKAGE_ID, title, message)

Verify.showAlert(this, 1, PACKAGE_ID, "Usuario no logueado", "Para poder usar APP_NAME debe iniciar sección en Apklis, luego de iniciar sección puede continuar con el uso de APP_NAME")
```

* Show alert Java
```java
// ACTION: 1 Apklis is not install, 2 User not logged in, 3 App not purchased
Verify.showAlert(this, ACTION, PACKAGE_ID, title, message);

Verify.showAlert(this, 1, PACKAGE_ID, "Usuario no logueado", "Para poder usar APP_NAME debe iniciar sección en Apklis, luego de iniciar sección puede continuar con el uso de APP_NAME");
```
### Contributing
All contributions are welcome!!!
8 changes: 4 additions & 4 deletions apklischeckpayment/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ android {
buildToolsVersion "30.0.2"

defaultConfig {
minSdkVersion 19
minSdkVersion 14
targetSdkVersion 30
versionCode 2
versionName "1.1"
versionCode 3
versionName "1.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand Down Expand Up @@ -41,4 +41,4 @@ dependencies {
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package cu.uci.apklischeckpayment

import android.app.AlertDialog
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.RemoteException

Expand All @@ -11,29 +15,74 @@ class Verify {
private const val APKLIS_PAID = "paid"
private const val APKLIS_USER_NAME = "user_name"

fun isPurchased(context: Context, packageId: String): Pair<Boolean, String?> {
fun isPurchased(context: Context, packageId: String): Triple<Boolean, String?, Boolean> {
var paid = false
var install = false
var userName: String? = null
val providerURI: Uri = Uri.parse("$APKLIS_PROVIDER$packageId")

val packageManager: PackageManager = context.packageManager
try {
val contentResolver = context.contentResolver.acquireContentProviderClient(providerURI)
val cursor = contentResolver?.query(providerURI, null, null, null, null)
cursor?.let {
if (it.moveToFirst()) {
paid = it.getInt(it.getColumnIndex(APKLIS_PAID)) > 0
userName = it.getString(it.getColumnIndex(APKLIS_USER_NAME))
install = true
packageManager.getPackageInfo("cu.uci.android.apklis", PackageManager.GET_ACTIVITIES)
val providerURI: Uri = Uri.parse("$APKLIS_PROVIDER$packageId")
try {
val contentResolver = context.contentResolver.acquireContentProviderClient(providerURI)
val cursor = contentResolver?.query(providerURI, null, null, null, null)
cursor?.let {
if (it.moveToFirst()) {
paid = it.getInt(it.getColumnIndex(APKLIS_PAID)) > 0
userName = it.getString(it.getColumnIndex(APKLIS_USER_NAME))
}
}
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
contentResolver?.close()
} else {
contentResolver?.release()
}
cursor?.close()
} catch (e: RemoteException) {
e.printStackTrace()
}
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
contentResolver?.close()
} else {
contentResolver?.release()
}
cursor?.close()
} catch (e: RemoteException) {
} catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace()
install = false
}
return Pair(paid, userName)
return Triple(paid, userName, install)
}

fun showAlert(context: Context, action: Int, packageId: String, title: String, message: String) {
/*
action = 0 | Install apklis
action = 1 | Login
action = 2 | Purchase
*/
val dialog = AlertDialog.Builder(context)
.setTitle(title)
.setMessage(message)
.setCancelable(false)
.setPositiveButton("Ir a Apklis") { _, _ ->
when (action) {
0 -> {
val url = "https://www.apklis.cu/application/cu.uci.android.apklis"
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(url)
context.startActivity(intent)
}
1 -> {
val intent: Intent? = context.packageManager.getLaunchIntentForPackage("cu.uci.android.apklis")
intent!!.action = Intent.ACTION_VIEW
intent.addCategory(Intent.CATEGORY_LAUNCHER)
context.startActivity(intent)
}
2 -> {
val url = "https://www.apklis.cu/application/$packageId"
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(url)
context.startActivity(intent)
}
}
}
.show()
}
}
}
}
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ android {

defaultConfig {
applicationId "cu.uci.example.check.paid"
minSdkVersion 19
minSdkVersion 14
targetSdkVersion 30
versionCode 2
versionName "1.1"
versionCode 3
versionName "1.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -42,6 +42,6 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

//implementation project(path: ':apklischeckpayment')
implementation 'com.github.Z17-CU:apklischeckpayment:0.0.2'
}
implementation project(path: ':apklischeckpayment')
// implementation 'com.github.Z17-CU:apklischeckpayment:0.0.2'
}
63 changes: 60 additions & 3 deletions app/src/main/java/cu/uci/example/check/paid/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cu.uci.example.check.paid

import androidx.appcompat.app.AppCompatActivity
import android.content.pm.PackageManager
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import cu.uci.apklischeckpayment.Verify

class MainActivity : AppCompatActivity() {
Expand All @@ -14,7 +15,63 @@ class MainActivity : AppCompatActivity() {

val userName = response.second
val isPaid = response.first
val install = response.third

/*
action:
1 - Install apklis
2 - Login in Apklis
3 - Purchase app
*/

if (install) {
// Apklis instalada comprobar compra y login

if (userName == null) {
// Usuario no logueado

Verify.showAlert(
this,
1,
"com.example.nova.prosalud",
"Usuario no logueado",
"Para poder usar ${getString(R.string.app_name)} debe iniciar sección en Apklis, luego de iniciar sección puede continuar con el uso de ${
getString(R.string.app_name)
}"
)
} else {
// Usuario loguado, comprobar compra

if (isPaid) {
// Aplicación comprada, su lógica aquí

Toast.makeText(
applicationContext,
"Todo esta bien, programe sus siguientes acciones",
Toast.LENGTH_LONG
).show()
} else {
// Aplicación no comprada

Verify.showAlert(
this,
2,
"com.example.nova.prosalud",
"Aplicación no comprada",
"Para poder usar ${getString(R.string.app_name)} debe comprar nuestra aplicación, luego de que la compra sea confirmada puede continuar el uso de nuestra aplicación"
)
}
}
} else {
// Apklis no instalado

Toast.makeText(this, "User $userName ${if (isPaid) "paid" else "does not paid"}", Toast.LENGTH_LONG).show()
Verify.showAlert(
this,
0,
"com.example.nova.prosalud",
"Apklis no instalada",
"Para poder usar ${getString(R.string.app_name)} debe instalar Apklis y luego iniciar sección dentro de esta"
)
}
}
}
}