Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Using Google Licensing to protect your Corona SDK App in 3 Steps
Started by develephant Nov 29 2013 07:03 AM

12 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

develephant

[GLOBAL: userInfoPane.html]
develephant
  • Pro
  • PipPipPipPipPipPip
  • 425 posts
  • Jedi

It's really easy to add an extra layer of protection when submitting your Google Play apps.  Take a look:

 

http://www.develephant.net/using-google-licensing-to-protect-your-corona-sdk-app/

 

Cheers.



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Corona Staff
  • 10,040 posts
  • Jedi

Bravo! 

 

Rob



[TOPIC: post.html]
#3

develephant

[GLOBAL: userInfoPane.html]
develephant
  • Pro
  • PipPipPipPipPipPip
  • 425 posts
  • Jedi

Thanks @Rob Miracle.  You keep me fired up. :)



[TOPIC: post.html]
#4

greg886

[GLOBAL: userInfoPane.html]
greg886
  • Pro
  • PipPipPipPipPipPip
  • 867 posts
  • Jedi

I used this approach, to be a bit more relaxed in case the user didn't have internet connectivity when they try to use the app - not sure if this the best idea or not...

 

 

local device = require("lib.device")
if not device.isSimulator and device.isAndroid then
    
    -- Listener
    local licensingListener = function(event)

        if event and (not event.isError) and (not event.isVerified) then
            -- Show Error Message then QUIT
            native.showAlert(
                "Error", 
                "License Invalid.\n"..
                "Download from Google Play Store.", 
                {"OK"}, 
                function(event)
                    native.requestExit()
                end
            );
        
        else
            -- Allow user to use app (e.g. for any time there is an "error" with the request)
        end
        
    end

     -- Call Google
    local licensing = require("licensing");
    licensing.init("google");
    licensing.verify(licensingListener);

end
 

 



[TOPIC: post.html]
#5

ingemar

[GLOBAL: userInfoPane.html]
ingemar
  • Enterprise
  • PipPipPipPipPipPip
  • 2,365 posts
  • Jedi

I have a similar approach to greg. However I specifically test for network errors. 

local networkError = (event.errorType == "network")

 

I don't want users to get a "pirate" message just because they have Airplane mode active. The caveat is that the users who know about it can just turn off network connectivity / wifi to access the app. But I think it's the price I have to pay to avoid legitimate users from getting false alarms.



[TOPIC: post.html]
#6

develephant

[GLOBAL: userInfoPane.html]
develephant
  • Pro
  • PipPipPipPipPipPip
  • 425 posts
  • Jedi

Great tips everyone.  I did touch upon the simulator "bypass" setting in the midst of some paragraph or another, but I will go in and update it with more additional info and detail.

 

Really appreciate the feedback.

 

Cheers.



[TOPIC: post.html]
#7

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Pro
  • PipPipPipPipPipPip
  • 2,737 posts
  • Jedi

Great material. Don't know how I missed it when first posted. Thanks to Alex as well for including it in his weekly blog entry. 



[TOPIC: post.html]
#8

anita5

[GLOBAL: userInfoPane.html]
anita5
  • Pro
  • Pip
  • 3 posts
  • Newbie

Hi -

I am having problems with the google store initializing my license. 

 

I am getting this error:

Google Play

"Failed to initialize Licensing Service!"

OK

 

I think I followed everyones code - seems like it should work: I am using Version 2013.1260 (2013.11.13) because of graphic and other changes.  Any suggestions?

 

Main:
local licensing = require( "licensing" )
local gInit = licensing.init( "google" )
 
 
local function ExitApp()
native.requestExit()  --assuming this is how we handle pirates
end
 
local function licensingListener( event )
 
 if not event.isVerified then
     if gInit == false then
        native.showAlert("Google Play------","Failed to initialize Licensing Service!",{"OK"})
    end
 
  --failed verify app from the play store, we print a message
--  native.showAlert("Google Play- what is up ","Google Play was unable to verify the license for this app. The app will now close.",{"OK"}, ExitApp)
 end
end
 
licensing.verify( licensingListener )
 
config: (tried it with and without policy )
 

 application = 
    {
        content =
        {
            width = 1600, --1280,
            height = 2048, --2360, --2048,
            scale = "letterBox",
            xAlign = "center",
            yAlign = "center",
            imageSuffix = 
            {
                ["@2x"] = .1,
            },
        },
        license = {
          google = {
             key = "my key" 
           ,policy = "serverManaged",
        },
      },
       
    }
 
Build:

settings = 
{ 
     orientation = 
     { 
         default = "landscapeRight", 
         supported = { "landscapeLeft", "landscapeRight" } 
      }, 
      
      android = 
    {
        versionCode = "4",
    --    usesExpansionFile = true,
         usesPermissions =
        {
             "android.permission.INTERNET",
             "com.android.vending.CHECK_LICENSE",
 --            "com.android.vending.BILLING",
             "android.permission.RECORD_AUDIO", 
             "android.permission.WRITE_EXTERNAL_STORAGE", 
        },
 
    },
}
 


 



[TOPIC: post.html]
#9

thegdog

[GLOBAL: userInfoPane.html]
thegdog
  • Pro
  • PipPipPipPipPipPip
  • 517 posts
  • Jedi

Can't say that I ever had this issue.  I don't know if you can set the licensing init call to a variable, and if the false is really accurate.  Wonder if that is causing the issue?



[TOPIC: post.html]
#10

dchan

[GLOBAL: userInfoPane.html]
dchan
  • Corona Staff
  • 342 posts
  • Jedi

You can try checking event.response or event.errorType to see if those give you a clue.



[TOPIC: post.html]
#11

anita5

[GLOBAL: userInfoPane.html]
anita5
  • Pro
  • Pip
  • 3 posts
  • Newbie

I will try printing out the event.response and event.errortype and not using a variable to check. 

 

 On the simulator I am getting the message below but it is allowing me to go on. Is that unusual? 

 

WARNING: The 'licensing' provider (google) is not available on the simulator    
WARNING: The 'licensing' library is not available on this platform.    


[TOPIC: post.html]
#12

thegdog

[GLOBAL: userInfoPane.html]
thegdog
  • Pro
  • PipPipPipPipPipPip
  • 517 posts
  • Jedi

Licensing only runs on Android devices.  You cannot test it on the Simulator.

 

As well, you must make sure that the Google account on the testing device is listed in the Google Play Developer Console for testing licensing and that you set the response correctly.



[TOPIC: post.html]
#13

ToeKnee

[GLOBAL: userInfoPane.html]
ToeKnee
  • Starter
  • PipPipPipPipPipPip
  • 175 posts
  • Jedi

Hi,

Just looking into this Licensing thing myself.

Don't quote me here as i am a newbie - Line 14 does not have the oncomplete ExitApp  - that you have commented out in line 18.

 

Have yet to test on device (takes a bit of time) but have simmed it on the simulator to see the process

 

--local licensing = require "licensing"
--licensing.init( "google" )
 
--local function licensingListener( event )
local function licensingListener()
--  local verified = event.isVerified
    verified = false
    if verified then
 
--    if event.isVerified then
 
 
Seems to work - or at least confirms the code flow.
T.



[topic_controls]
[/topic_controls]