onepf / OpenIAB

Open In-App Billing for Google Play, SlideMe, Amazon Store, Nokia Store, Samsung Apps, Yandex.Store, Appland, Aptoide, AppMall and Fortumo.
http://onepf.org/openiab/
Apache License 2.0
475 stars 171 forks source link

Tutorial: SamsungApps. no example on how to use samsung in-app purchase #136

Closed evolapp closed 10 years ago

evolapp commented 10 years ago

I have no problem with google, amazon, but I have no idea on how to test with samsung in-app purchase. Google is the default. To use amazon, refer to here: https://github.com/onepf/OpenIAB/issues/125

        Context mContext = getApplicationContext();
        Options opts = new Options();
        opts.availableStores = new ArrayList();
        opts.availableStores.add(new AmazonAppstore(mContext) {
            public boolean isPackageInstaller(String packageName) {
                return true;
            }
        });
      mHelper = new OpenIabHelper(this, opts);

But to use samsung, i tried to follow amazon example, but failed..

        Options opts = new Options();
        opts.availableStores.add(new SamsungApps(this, opts) {
            public boolean isPackageInstaller(String packageName) {
                return true;
            }
        }); 
      mHelper = new OpenIabHelper(this, opts);  

but force closed, please help, thank a lot

oorlov commented 10 years ago

And what is in log?

evolapp commented 10 years ago

i think my code to select samsung in app payment is wrong, because i just "guess" the code. the log is:

02-20 21:13:00.554: W/dalvikvm(31291): threadid=1: thread exiting with uncaught exception (group=0x4164b2a0) 02-20 21:13:00.562: E/AndroidRuntime(31291): FATAL EXCEPTION: main 02-20 21:13:00.562: E/AndroidRuntime(31291): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.MainActivity}: java.lang.NullPointerException 02-20 21:13:00.562: E/AndroidRuntime(31291): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097) 02-20 21:13:00.562: E/AndroidRuntime(31291): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122) 02-20 21:13:00.562: E/AndroidRuntime(31291): at android.app.ActivityThread.access$600(ActivityThread.java:140) 02-20 21:13:00.562: E/AndroidRuntime(31291): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228) 02-20 21:13:00.562: E/AndroidRuntime(31291): at android.os.Handler.dispatchMessage(Handler.java:99) 02-20 21:13:00.562: E/AndroidRuntime(31291): at android.os.Looper.loop(Looper.java:137) 02-20 21:13:00.562: E/AndroidRuntime(31291): at android.app.ActivityThread.main(ActivityThread.java:4895) 02-20 21:13:00.562: E/AndroidRuntime(31291): at java.lang.reflect.Method.invokeNative(Native Method) 02-20 21:13:00.562: E/AndroidRuntime(31291): at java.lang.reflect.Method.invoke(Method.java:511) 02-20 21:13:00.562: E/AndroidRuntime(31291): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994) 02-20 21:13:00.562: E/AndroidRuntime(31291): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761) 02-20 21:13:00.562: E/AndroidRuntime(31291): at dalvik.system.NativeStart.main(Native Method) 02-20 21:13:00.562: E/AndroidRuntime(31291): Caused by: java.lang.NullPointerException 02-20 21:13:00.562: E/AndroidRuntime(31291): at com.example.myapp.MainActivity.setupInAppBilling(MainActivity.java:444)

=> line 444: this line is opts.availableStores.add(new SamsungApps(this, opts) {

02-20 21:13:00.562: E/AndroidRuntime(31291): at com.example.myapp.MainActivity.onCreate(MainActivity.java:378) 02-20 21:13:00.562: E/AndroidRuntime(31291): at android.app.Activity.performCreate(Activity.java:5163) 02-20 21:13:00.562: E/AndroidRuntime(31291): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 02-20 21:13:00.562: E/AndroidRuntime(31291): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)

thank you for help!

evolapp commented 10 years ago

btw, this library does not support samsung Non-consumable goods?

oorlov commented 10 years ago

It definetely supports.

Have you finished SamsungApps setup?

SamsungApps activates only after you map general SKU (from google or Amazon) to Samsung SKU (it looks like group_id/item_id) Also you need to provide activity that currently on screen in OpenIABHelper constructor as a Context parameter

oorlov commented 10 years ago

It definetely supports.

Have you finished SamsungApps setup?

SamsungApps activates only after you map general SKU (from google or Amazon) to Samsung SKU (it looks like group_id/item_id) Also you need to provide activity that currently on screen in OpenIABHelper constructor as a Context parameter

oorlov commented 10 years ago
        OpenIabHelper.mapSku(SKU_PREMIUM, OpenIabHelper.NAME_AMAZON, "org.onepf.trivialdrive.amazon.premium");
        OpenIabHelper.mapSku(SKU_PREMIUM, OpenIabHelper.NAME_SAMSUNG, "100000100696/000001003746");
        OpenIabHelper.mapSku(SKU_PREMIUM, "com.yandex.store", "org.onepf.trivialdrive.premium");

        OpenIabHelper.mapSku(SKU_GAS, OpenIabHelper.NAME_AMAZON, "org.onepf.trivialdrive.amazon.gas");
        OpenIabHelper.mapSku(SKU_GAS, OpenIabHelper.NAME_SAMSUNG, "100000100696/000001003744");
        OpenIabHelper.mapSku(SKU_GAS, "com.yandex.store", "org.onepf.trivialdrive.gas");

        OpenIabHelper.mapSku(SKU_INFINITE_GAS, OpenIabHelper.NAME_AMAZON, "org.onepf.trivialdrive.amazon.infinite_gas");
        OpenIabHelper.mapSku(SKU_INFINITE_GAS, OpenIabHelper.NAME_SAMSUNG, "100000100696/000001003747");
        OpenIabHelper.mapSku(SKU_INFINITE_GAS, "com.yandex.store", "org.onepf.trivialdrive.infinite_gas");
oorlov commented 10 years ago

135

evolapp commented 10 years ago

thanks for reply, i did mapped sku and followed the sample code, anyway, how can I force to use samsungapp store? I tried below: OpenIabHelper.mapSku(SKU_PREMIUM, OpenIabHelper.NAME_SAMSUNG, "100000100696/000001003746"); Map<String, String> storeKeys = new HashMap<String, String>();
mHelper = new OpenIabHelper(this, storeKeys); but with no luck...

below is also failed... Options opts = new Options(); opts.availableStores.add(new SamsungApps(this, opts) { public boolean isPackageInstaller(String packageName) { return true; } }); mHelper = new OpenIabHelper(this, opts);

Anyway, let me ask again, what is the way to force to use samsung app store? Your help is highly appreciated!

oorlov commented 10 years ago

There is only one way to force OpenIAB works with any store. For Samsung it looks like this:

        Options opts = new Options();
        opts.storeKeys = storeKeys;
        opts.availableStores = new ArrayList<Appstore>();
        opts.availableStores.add(new SamsungApps((Activity)this, opts) {
            public boolean isPackageInstaller(String packageName) {
                return true;
            }
            public boolean isBillingAvailable(String packageName) {
                return true;
            }
        });
        mHelper = new OpenIabHelper(this, opts);

Also I would recommend to run following code to ensure that Samsung IAP service is installed before OpenIabHelper is constructed:

        try {
            PackageManager pm = this.getPackageManager();
            try {
                pm.getApplicationInfo("com.sec.android.iap", PackageManager.GET_META_DATA);
            } catch (NameNotFoundException e) {
                Intent intent = new Intent();
                intent.setData(Uri.parse("samsungapps://ProductDetail/com.sec.android.iap"));
                if (Build.VERSION.SDK_INT >= 12) {
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | 32);
                } else {
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                }
                startActivity(intent);
                this.finish();
                e.printStackTrace();
            }
        } catch (Exception e1) {
            e1.printStackTrace();
        }

And take into account the following thing: If you publish application with the same android package in SamsungApps and GooglePlay, SamsungApps will update .apk installed from GooglePlay. If version you published in SamsungApps works only SamsungApps, your users wouldn't have access to their items acquired in GooglePlay previously

evolapp commented 10 years ago

thank a lot for your reply. I tried the part1 code. I think it can connect to samsung, but still, it did not work.

02-22 23:48:26.963: D/TrivialDrive(30089): Setup finished. 02-22 23:48:26.963: D/TrivialDrive(30089): Setup successful. Querying inventory. 02-22 23:48:26.978: D/SamsungAppsBillingService(30089): getItemsInbox, startNum = 1, endNum = 100 02-22 23:48:26.978: W/dalvikvm(30089): threadid=13: thread exiting with uncaught exception (group=0x4164b2a0) 02-22 23:48:26.986: E/AndroidRuntime(30089): FATAL EXCEPTION: Thread-3905 02-22 23:48:26.986: E/AndroidRuntime(30089): java.lang.NullPointerException 02-22 23:48:26.986: E/AndroidRuntime(30089): at org.onepf.oms.appstore.SamsungAppsBillingService.queryInventory(SamsungAppsBillingService.java:190) 02-22 23:48:26.986: E/AndroidRuntime(30089): at org.onepf.oms.OpenIabHelper.queryInventory(OpenIabHelper.java:749) 02-22 23:48:26.986: E/AndroidRuntime(30089): at org.onepf.oms.OpenIabHelper$5.run(OpenIabHelper.java:776)

the line is: itemInbox = mIapConnector.getItemsInbox(activity.getPackageName(), itemGroupId, startNum, endNum, "19700101", today);

I checked, all of below variables are not null: activity.getPackageName(), itemGroupId, startNum, endNum, "19700101", today, mIapConnector no idea on why java.lang.NullPointerException happened.

thanks!

MCWiener101 commented 10 years ago

Checkout http://img-developer.samsung.com/contents/cmm/EN_Samsung_IAP2.0_Android_Programming_Guide_v1.0.pdf

It seems there is stuff needed in AndroidManifest - 2.4

evolapp commented 10 years ago

@sleepybuddha thank a lot, u r right!

    <uses-permission android:name="com.sec.android.iap.permission.BILLING"/>
    <uses-permission android:name="android.permission.INTERNET"/>   
oorlov commented 10 years ago

Hi!

We've improved Appstore selection mechanism, so now it analyzes packageInstaller for Amazon and SamsungApps (Please find latest version it on master branch). Now you don'y need to extend Appstore classes as specified above.

To say to OpenIAB to connect to SamsungApps or to Amazon SDK Tester, only special .apk install command is needed:

# first put .apk on device
adb push YourApp.apk /mnt/sdcard
# install for SamsungApps:
adb shell pm install -i com.sec.android.app.samsungapps /mnt/sdcard/YourApp.apk
# install for Amazon SDK Tester:
adb shell pm install -i com.amazon.venezia /mnt/sdcard/YourApp.apk

Does it help? We will add it in next release pretty soon