itemstore is a service that allows you to easily implement in-app purchases on Android and iOS apps. Troublesome in-app purchase processing can be realized with a simple source code, and management such as display / non-display of sales items can be easily performed from the item store screen.
The general flow of use is as follows.
[STEP1] Settings on the developer site [STEP2] Store settings [STEP3] Implementation
This time, I would like to summarize "[STEP3] Implementation: Android Edition".
Android 4.0 (API level 14) or later
This tutorial assumes development in Android Studio.
Copy the downloaded SDK jar file to the libs folder.
If you cannot see the libs folder, change the display of Project in the Tool Window by selecting "Project" in the pull-down menu.
After deploying the SDK, perform a clean build by selecting "Sync Project with Gradle Files" on the toolbar or [Build]-> [Clean Project] from the menu.
If the corresponding API version is 23 or later, add the following under android of build.gradle in the app folder.
Required support for API version 23 or later
android {
〜
useLibrary 'org.apache.http.legacy'
〜
}
If you want to release build with proguard enabled, add the following to proguard-rules.pro in the app folder.
proguard settings
-dontwarn org.apache.http.**
-keep class net.app_c.sdk.** { *; }
To implement the itemstore billing function / push notification function, implement the OnAppCStartedListener interface in the class that is the main activity.
Example)
Implemented OnAppCStartedListener interface
public class MainActivity extends Activity implements AppC.OnAppCStartedListener {
private AppC appc;
・ ・ ・
itemstore billing function
public class MainActivity extends Activity implements AppC.OnAppCStartedListener {
private AppC appc;
〜
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
〜
//itemstore initialization
appc = new AppC(this).on(AppC.API.ITEM_STORE).setMediaKey(_MEDIA_KEY).start();
〜
}
@Override
public void onAppCStarted(boolean flg) {
//Called after the itemstore initialization process is complete
//If you want to call the itemstore related method immediately after starting the app,
//Please do various processing after this callback is called.
}
〜
@Override
public void finish() {
//itemstore exit
appc.finish();
super.finish();
}
〜
}
//itemstore method
//itemstore view call
appc.ItemStore.openItemStore();
//Get the group name of the billing item
String groupName = appc.ItemStore.getItem("Group ID").getName();
//Get the number of billing items you have
int itemCount = appc.ItemStore.getItemCount("Group ID");
//Increase or decrease the number of billing items
//If you want to reduce the number of possessions, enter a negative value in the second argument
appc.ItemStore.addItemCount("Group ID", 1);
//Set the specified value for the number of billing items you have
appc.ItemStore.setItemCount("Group ID", 10);
//Get inquiry key
String inquiryKey = appc.getInquiryKey();
Push notification function
public class MainActivity extends Activity implements AppC.OnAppCStartedListener {
private AppC appc;
〜
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
〜
//itemstore initialization
appc = new AppC(this).on(AppC.API.PUSH).setMediaKey(_MEDIA_KEY).start();
/*
By default, the Activity that starts when you tap the push notification is the Activity that initializes the appC SDK.
If you want to start any activity when you tap the push notification, specify the activity class in the second argument of on.
The icon displayed by push notification is ic by default_The launcher is specified
If you want to change the icon image displayed by push notification, specify any icon in the third argument of on.
appc = new AppC(this).on(AppC.API.PUSH, MainActivity.class, R.drawable.ic_launcher)
.setMediaKey(_MEDIA_KEY)
.start();
*/
〜
}
@Override
public void onAppCStarted(boolean flg) {
//Called after the itemstore initialization process is complete
//If you want to call the itemstore related method immediately after starting the app,
//Please do various processing after this callback is called.
//You can get the delivery text (custom parameter) set in push delivery when you start it with push notification.
//Example) Log.d("appc", "onAppCStarted:" + appc.Push.getParam());
}
@Override
protected void onNewIntent(final Intent intent) {
super.onNewIntent(intent);
//You can get custom parameters when the app is in a task state and there is a push notification
//You can get the delivery text (custom parameter) set in push delivery when you start it with push notification.
//Example) Log.d("appc", "onNewIntent:" + appc.Push.getParam());
}
@Override
public void finish() {
//itemstore exit
appc.finish();
super.finish();
}
〜
}
//Push notification method
//Get delivery text (custom parameters)
String customParameter = appc.Push.getParam();
//Get inquiry key
String inquiryKey = appc.getInquiryKey();
Please use it as needed. If there are other necessary items, please add them as appropriate.
AndroidManifest.xml settings
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="[package name]">
<!-- require AppC -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- require Push Start -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" >
</uses-permission>
<uses-permission android:name="[package name].permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="[package name].permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<!-- require Push End -->
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- require Push Start -->
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="[package name]" />
</intent-filter>
</receiver>
<service android:name="net.app_c.sdk.AppCPushService" />
<!-- require Push End -->
</application>
</manifest>
Recommended Posts