Unity3d Access GooglePlay Internal purchase details (ii)

Source: Internet
Author: User
Tags unique id

Because the content of this article is more, finishing spend a long time, it is completed, the following is the directory structure for easy access:


Unity3d Access GooglePlay Internal purchase details (i)

Introduction

first, the preparation conditions:

Second, Google Developer background application creation instructions:


Unity3d Access GooglePlay Internal purchase details (ii)

Iii. Unity3d to the Android communication and acceptance of communications

Iv. Unity to export an official signature of APK

v. Use Eclipse to run the Unity-exported project

Six, Java code access to Google internal purchase:

Seven, Google's internal purchase of Java code


Unity3d Access GooglePlay Internal purchase details (iii)

Eight, apk upload the Google Store beta and add testers

ix. zipalign Processing of APK documents

10. Add the Google + Group and invite it to be a tester

11, test machine GooglePlay installation and configuration:


Unity3d Access GooglePlay Internal purchase details (iv)

12, the real machine test in the common errors and resolution methods:

13. Successful test purchase and official release


————————————————————————————————————————————————————————————


Iii. Unity3d to the Android communication and acceptance of communications

1, as the test is temporary written Unity3ddemo, only the most basic payment function. First of all, the unity of Android Communication, which is basically fixed code.

In the example, 2 kinds of effective products were added, and the SKU in the backstage was jb_1,lb_1 respectively;


2, which mainly on a few lines of code, basic general-purpose, need to change the "Pay" method, as well as note the string parameters passed (used to distinguish between different SKUs):

private void Unitytoandroid (string buykey)

{

Androidjavaclass M_unityplayer = Newandroidjavaclass ("Com.unity3d.player.UnityPlayer");

Androidjavaobject m_curactivity = m_unityplayer.getstatic<androidjavaobject> ("currentActivity");

M_curactivity.call ("Pay", Buykey);

}


3, all the code is as follows:

Using Unityengine;

Usingsystem.collections;

Public Classguipay:monobehaviour

{

private int i = 0;

private int j = 0;

private String Key;//suk

private string messagefromandroid;//messages received from Andro

void Ongui () {

if (Guilayout.button ("Gold 1", Guilayout.height (), Guilayout.width (150)) {

i++;

Key= "Jb_1";

Unitytoandroid (key);

}

if (Guilayout.button ("Gift 1", guilayout.height (), Guilayout.width (150)) {

j + +;

Key = "Lb_1";

Unitytoandroid (key);

}

Guilayout.button ("Purchase:" +key+ "respectively:" +i.tostring () + "Times/" +j.tostring () + "Times", Guilayout.height (M), Guilayout.width (200) );

Guilayout.button ("Androidmessage:" +messagefromandroid,guilayout.height (), Guilayout.width (200));

}

Android Payment Communications

private void Unitytoandroid (Stringbuykey) {

Androidjavaclass m_unityplayer =new androidjavaclass ("Com.unity3d.player.UnityPlayer");

Androidjavaobject m_curactivity =m_unityplayer.getstatic<androidjavaobject> ("currentActivity");

if (m_curactivity = null)

{

Debug.logerror ("Get no Java objects");

Return

}

M_curactivity.call ("Pay", Buykey);

}

The message is received from Andro because this script hangs on the existing Maincamera object, from which the message is fetched, corresponding to the Java code to designate the message sent object as Maincamera

void Messgae (String message)

{

messagefromandroid = message;

}

}

4, the operating effect is as follows, click will be an error, so can only be tested on the real machine:

5, Next, open the settings, check the export of an Android project, icon, application name, starting page, etc. if only do test can not be formal. That is, if not officially issued apk, only need formal package name, formal signature, official release remember to modify other icon, starting page and other information:

6, upload to the Google Store requires a formal signature, can not be signed for debug mode, or upload failure . The signature is made in the following way:



Iv. Unity to export an official signature of APK

I. The meaning of the signature

To ensure that the legitimate IDs of each application developer are used to prevent some of the open vendors from using the same package name to confuse the replacement of installed programs, we need to uniquely sign our published APK file to guarantee the consistency of each release we publish ( such as Automatic Updates will not be installed because of a version inconsistency.

Here is a detailed explanation :

Installation package apk name, in the world, there are many developers, is likely to name duplication, when the name is repeated when the need to have a unique identifier to distinguish. This is Andong's signature. This signature does not need to apply to Google, but its own local signature can be.

This signature is unique, very important, be sure to keep good, is to make a successor version of the important basis for update. If replaced, even the same application will not overwrite the installation, but be installed separately as another new application. And when you submit the application, if you replace the signature, it will not be used as a later update version.

Ii. Signature Steps (only Android needs to sign)

In general, Android's APK installation package is compiled by Eclipse, and he has his own signature plugin. Includes formal signatures and dubug test signatures.

Instead of using eclipse, we use Unity's own signature feature.

1, the project confirmed that no bug, need to pour out the apk file:


2, open the Export Settings option:


3, This publishing settings under the default is debug signature, if only their own testing, you do not need to modify, upload Google Store, need to make a signature.


4, choose Create New KeyStore, the following select Save location,


5, click Key


6, fill in the detailed signature information, must remember the password, because in eclipes inside to use. stored in a reliable location and cannot be retrieved after loss:


7, the certificate is as follows, command line tool can open, need to install JDK:

Verify signature information:

Command line Input jarsigner-verify-verbose-certs xxx.apk (apk full path) You can see the comparison signature information (you need to have JDK installed)

 

8, the signature column default is unsigned, do not sign, debug mode


when you export apk again later, you must first select the signature, and you need to enter the original password before compiling

 

9, if the debug signature, then uploaded to the Google Application store will encounter this situation:

 

10, the correct signature can be uploaded correctly



11, of course, can also use Eclipes to sign, specifically please Baidu. Next we have to access Google's eclipes inside the API:


v. Use Eclipse to run the Unity-exported project

1, open the Eclipes, create the work space.


2. New Android Project:


3, fill in the same package name as unity, other default can be, next Next




5, this is just the creation of the empty project


6, the next will be unity of the project, inside the folder directly dragged to the HNN project, the selection of all coverage, our project content will be replaced by Unity content:




7, in order to test whether it can run on the real machine, you can compile the project:


8, to find the compiled apk installed to the real machine test, can start, buttons, of course, now has no effect:


Six,Java code access to Google internal purchase:

The following is the developer center in the detailed explanation of the purchase, English documents, you can Google translation. Link Address:

In-appbilling Overview

Preparingyour In-app Billing Application

1, first we need to download the SDK. In the eclipes can be downloaded to, at present because the link outside the network, download may need to VPN, inside the demo file is not big.

This is his official demo, the introduction of how to access the Android project in the purchase, which is why we choose Unity to export the Android project, instead of selecting Eclipes dozen jar files, put into unity to compile APK:



What we need is: iinappbillingservice.aidl this file.

2, drag the file into our engineering src directory, the path please set yourself well.


3, also need to join the necessary tool class.


That is, all the code underneath the Util folder. The same drag to our engineering directory, dragged in May be reported to introduce the path of error, pay attention to modify to conform to your own project of the normal path. For example, after my project has been imported, the structure is approximately the same.

From the top to the next order for the internal purchase must file, unity of the band-type, internal purchase tools. File directory structure:

4, Androidmainfest file to add permissions, if you have done other access functions, such as sharing, permissions to do the merger.

<uses-permission android:name= "Com.android.vending.BILLING"/>

5. Then we write code in Java code that is called by unity and that messages are returned to unity.

The previous article said:


6, send messages to the Uinty, generally used to transfer whether the purchase success and so on.

7, unity in the acceptance of content to continue to do processing:

8, in the purchase aspect, needs to write the Base64 RAS public key. Is the previous article said that the Google developer backstage Application key

9, and then write SKU, this SKU is the unique ID of the purchase item, can be passed from unity, can also be written in Java, we do here to do the incoming.

10, other when the purchase of all kinds of listening, whether to login, whether the test conditions, whether binding bank cards and so on, mainly for reference to the code in the demo.






Seven, Google's internal purchase of Java code

The following are all the code in the default class derived by unity:

PACKAGECOM.TAOJINZHE.HNN;

importcom.unity3d.player.*;

importandroid.app.NativeActivity;

Importandroid.content.res.Configuration;

Importandroid.graphics.PixelFormat;

Importandroid.os.Bundle;

Importandroid.view.KeyEvent;

Import android.view.MotionEvent;

Importandroid.view.View;

Importandroid.view.Window;

Importandroid.view.WindowManager;

importandroid.app.Activity;

Importandroid.app.AlertDialog;

Importandroid.content.Intent;

Importandroid.content.SharedPreferences;

Import Android.util.Log;

Importandroid.widget.ImageView;

Importandroid.widget.Toast;

Importcom.util.IabHelper;

Importcom.util.IabResult;

Importcom.util.Inventory;

Importcom.util.Purchase;

Public Classunityplayernativeactivity extends Nativeactivity

{

       protected Unityplayer munityplayer;              //don ' t change the name of Thisvariable; Ref

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.