Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old February 1st, 2012, 08:36 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Aug 2010
Posts: 8
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 1 Time in 1 Post
Default Licensing programming structure

I have copied the Google market licensing library into my project, copied the top level sample code in as License.java and made all the necessary changes to the Manifest and strings. All error free and runs normally as was.

What I can't figure out is the program structure to actually integrate the two properly. Do I set the License.java as my main activity and start the previously main activity from within that? If so where does it go?

This is incomprehensible even by Android standards and I can't find any clear examples on the net.

Ta for any ideas.

xoggoth is offline  
Reply With Quote
sponsored links
Old February 2nd, 2012, 12:57 AM   #2 (permalink)
Over Macho Grande?
 
alostpacket's Avatar
 
Join Date: Nov 2009
Location: NY
Posts: 7,873
 
Device(s): GlassXE, MotoX, N5, N4, N7'12, GNex, N1, SGT10.1, Revue, Xoom, Eris, OG Droid
Carrier: TMO

Thanks: 4,582
Thanked 3,563 Times in 1,522 Posts
Default

Can you post a little about the tutorial you are following?

It's been awhile since I used LVL but essentialy the recommended way is to use the built in ServerPolicy example (though to prevent hacking you should modify it).

I'm not sure how much this helps but I found implementing LVL to be a great learning experience but not really any good for my bottom line.
alostpacket is offline  
Reply With Quote
Old February 2nd, 2012, 05:56 AM   #3 (permalink)
New Member
Thread Author (OP)
 
Join Date: Aug 2010
Posts: 8
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 1 Time in 1 Post
Default

Thanks for reply alostpacket. Basically just trying to follow the official Android guidance as here:

Application Licensing | Android Developers

The licensing library and sample I refer to is in the SDK market licensing component. I think the steps are all there in the documentation but, as you say, it looks like "a great learning experience" ie typically Androidy complicated. Just wondering if there was a simpler example anywhere of how to adapt their sample without having to figure out what stuff like "update the UI thread" means.

Later:
Total nightmare as suspected. Code as instructions not valid java, like private Handler mHandler gives illegal modifer error. And not same code as sample. Which is most recent? Who knows? All you chaps who got this to work must be Java geniuses.
xoggoth is offline  
Last edited by xoggoth; February 2nd, 2012 at 07:34 AM.
Reply With Quote
Old February 2nd, 2012, 04:25 PM   #4 (permalink)
Over Macho Grande?
 
alostpacket's Avatar
 
Join Date: Nov 2009
Location: NY
Posts: 7,873
 
Device(s): GlassXE, MotoX, N5, N4, N7'12, GNex, N1, SGT10.1, Revue, Xoom, Eris, OG Droid
Carrier: TMO

Thanks: 4,582
Thanked 3,563 Times in 1,522 Posts
Default

The UI thread is basically your Activity.

A Handler, is a way for your Activity to receive messages from other threads or services.

Since LVL is a service that runs in the background and communicates with a different app, you need a way for the result to be sent back to your app.

This is where LiceseCheckerCallback comes in. While you probably write this code in your Activity (as an inner class), you'll need to remember that it is going to be called by a different thread/app.

So if two different threads try to call a method in your activity at the same time, you can get some serious problems (ie concurrency dead locks, but the name isnt important).

Anyways this is where the Handler comes in. Each activity (aka UI thread) can define a Handler (private or public or whatever) that it can "give out" (pass a reference) to another class.

In this case the Handler (mHandler) is being "given" to the LicenseCheckerCallback class.

(if I remember correctly)

Part of what might be confusing here: in the example they create an inner class inside the main Activity for the LicenseCheckerCallback.

Because the LicenseCheckerCallback implementation in the example is an inner class, that means it can "see" the Handler (mHandler).

And, because of this, there is no obvious "passing" of the handler to the LicenseCheckerCallback.

Anyways, hope this helps -- I'm not sure where your stuck exactly but maybe this will at least give us a starting point as to what to try and figure out.

And yeah, Android is very hard to learn at times. But some things make a TON of sense once you "get" them. Unfortunately the documentation that teaches that stuff is pretty bad But hopefully we can help
alostpacket is offline  
Last edited by alostpacket; February 2nd, 2012 at 04:29 PM.
Reply With Quote
Old February 3rd, 2012, 05:14 AM   #5 (permalink)
New Member
Thread Author (OP)
 
Join Date: Aug 2010
Posts: 8
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 1 Time in 1 Post
Default

Thanks very much. What you say does make sense, it's just the sample that doesn't. The license check is the main activity (publicclass MainActivity extends Activity) with its own layout which leaves the problems, how do you stop the licence layout being shown every time the app is opened and, if you start what was the main activity from within it, how to stop the back button going back to license check?

Not quite got the license check example to accept it's licensed yet, what with all the inevitable problems, invalid preference page path, insufficient memory on device etc to search for solutions to, but as far as I can see it does nothing after licence checking. If it just showed a hello world page in its own view it would help.
xoggoth is offline  
Reply With Quote
Old February 3rd, 2012, 05:31 AM   #6 (permalink)
New Member
Thread Author (OP)
 
Join Date: Aug 2010
Posts: 8
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 1 Time in 1 Post
Default

Ah! This link seems clearer than most

http://android-codes-examples.blogspot.com/2011/02/android-market-license-verification.html

So the main activity start goes in publicvoid allow() . Sort of obvious on hindsight but nice if the example actually did start the main activity here.

xoggoth is offline  
Reply With Quote
Old February 6th, 2012, 10:43 AM   #7 (permalink)
New Member
Thread Author (OP)
 
Join Date: Aug 2010
Posts: 8
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 1 Time in 1 Post
Default Short version

Using the sample to implement licensing in a previously copy protected app.

In eclipse Android SDK Manager download:
Google market licensing package
Only the latest Google APIs
You should now have in your specified path:
the library: ..\android-sdks\extras\google\market-licensing\library
the sample: ..\android-sdks\extras\google\market-licensing\sample

In windows explorer:
copy the library src\com folder to your src folder
copy the sample android\market\licensing\MainActivity.java to your src\etc folder with your other source files
copy sample res\layout\Main.xml to your res\layout folder with your other layout files
rename current starting activity to ViewMain.java
rename MainActivity.java to previous starting activity name
rename Main.xml to License.xml

In Eclipse refresh and:

Ensure project properties build target is Android 2.2 (API Level 8) or above or the licensy stuff and install location line below will not compile. Do this BEFORE you make the changes to the Manifest file as errors will stop you doing it afterwards. Android is backward compatible so the App will work on devices running Android 1.5 or above. (assuming it did before obviously)

In new top level java (now the sample code) change package name and public class name at top to be as previous, change setContentView( etc) to setContentView(R.layout.License), mod BAS64-PUBLIC_KEY and Salt values as per official Android blurb and replace the line displayResult in public void allow with:
Intent i = new Intent(XXX.this, ViewMain.class);
startActivity(i);
finish();
where XXX is your public class name.

In AndroidManifest add/mod in appropriate places:
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
<activity android:name=".ViewMain"></activity>
<uses-sdk android:minSdkVersion="N" /> N MUST be 3 or above here to avoid install on devices that do not support licensing.
If you want users to be able to move the app to the SD card, also add android:installLocation="auto" to the <manifest xmlns:android list. The device must have a build level of 2.2 or above to use this feature. The line is safe with lower versions but will have no effect.

Pitfall! Eclipse tends to auto correct when you rename files so you may find some changes above done for you but it also makes changes you don't want. If the app starts normally whatever test response you have set Eclipse has probably changed the main activity in the Manifest to ViewMain.

Open values\strings.xml and paste in all the strings from sample ..res\values\string.xml except for the app_name line

In AVD manager create a new AVD and select target Google APIs. Need to use this for all license checking using the emulator. Setting up Google account and responses is clear in the official Android page so I won't repeat that but note that the gmail address used should not be one you have already used to purchase your app, that will just show Android market page with paid. Also ensure your test response is not set to "Handle normally" as, due to your previous version being copy protected, you will get a "not market managed" error.

After uploading the new app you can use a phone with the previous version installed. First uninstall then go to Android market where it will say purchased and you can download new version.
xoggoth is offline  
Last edited by xoggoth; February 8th, 2012 at 08:12 AM.
Reply With Quote
The Following User Says Thank You to xoggoth For This Useful Post:
alostpacket (February 6th, 2012)
Reply
Tags
activity, licensing


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 09:23 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.