in-app billing with phonegap for android app - android

I am developing an android phonegap application and I want to use in app billing in it. I installed the phonegap billing plugin and it works perfectly. Can you help me make it work correct with a link.
For example, here is the script code:
<script >
function successHandler (result) {
var strResult = "";
if(typeof result === 'object') {
strResult = JSON.stringify(result);
} else {
strResult = result;
}
alert("SUCCESS: \r\n"+strResult );
}
function errorHandler (error) {
alert("ERROR: \r\n"+error );
}
// Click on init button
function init(){
// Initialize the billing plugin
inappbilling.init(successHandler, errorHandler, {showLog:true});
}
// Click on purchase button
function buy(){
// make the purchase
inappbilling.buy(successHandler, errorHandler, "good_id");
}
// Click on ownedProducts button
function ownedProducts(){
// Initialize the billing plugin
inappbilling.getPurchases(successHandler, errorHandler);
}
// Click on Consume purchase button
function consumePurchase(){
inappbilling.consumePurchase(successHandler, errorHandler, "good_id");
}
// Click on subscribe button
function subscribe(){
// make the purchase
inappbilling.subscribe(successHandler, errorHandler,"good_id");
}
// Click on Query Details button
function getDetails(){
// Query the store for the product details
inappbilling.getProductDetails(successHandler, errorHandler, "good_id");
}
// Click on Get Available Products button
function getAvailable(){
// Get the products available for purchase.
inappbilling.getAvailableProducts(successHandler, errorHandler);
}
</script>
And i need it to work with for example -
Good
Thats after clicking on a link first of all i ll be able to pay before linking to a page.
Thanks. Sorry for my bad English.

I'm not sure i understood what you want, your english is worst than mine. But if you just want to launch a purchase when clicking and after redirect, you may use onclick event and window.location.replace :
<a href="good.html" id='good' data-ignore="true" onclick="buy()" >Good</a>
// Click on purchase button
function buy(){
// make the purchase
inappbilling.buy(successHandler, errorHandler, "good_id");
return false;
}
and then add window.location.replace('yourlinkpage'); on your successHandler
But maybe an input submit should be more appropriate?

Related

jQuery 'taphold' does not fire, while 'tap' does

In my flutter app I have html inside a webview and some javascript with jquery attached. I want to trigger different actions depending on if a list item receives 'tap' or 'taphold'. I'm using jquery-mobile 1.5.0-rc1.
My javascript is as follows:
$('div.board').on('taphold tap', 'div.thread, div.thread-special', function(event) {
console.log('event');
var $item = $(this); // The item that was clicked or held
var scope = $item.data('itemscope'); // No numbered IDs! You can find everything about the item
// etc.
var type = event.type;
if (type === 'tap') {
console.log('tap');
} else if (type === 'taphold') {
console.log('taphold');
}
});
When I tap, I can see a 'tap' in the console. When I taphold, nothing at all happens or appears on the console. Any idea why?

Cordova pickcontact doesn't work

I try to pick a contact with cordova plugin contacts, but I still have a bug. My button #pickContact opens correctly the activity where I can tap on a contact. But when I tap on one, nothing happens. When I go back to my page, I have the error message OPERATION_CANCELLED_ERROR (code 6).
I really don't understand where is the problem. I run my app on Android Marshmallow. I thought about a permission problem, but my app can find correctly contacts with navigator.contacts.find, but not with navigator.contacts.pickContact
Here is my code :
function pickContact() {
navigator.contacts.pickContact(function(contact){
alert('ok !');
},function(err){
alert('bug !' + err);
console.log('Error: ' + err);
});
}
var app = {
// Application Constructor
initialize: function() {
this.onDeviceReady();
if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry)/)) {
document.addEventListener("deviceready", this.onDeviceReady, false);
} else {
this.onDeviceReady();
}
},
onDeviceReady: function() {
$("#pickContact").click(pickContact);
},
// Update DOM on a Received Event
receivedEvent: function(id) {
}
};
app.initialize();
Thanks for your help !
As per the reference doc of contacts plugin your selected contact will set into JSON.stringify(contact) you can alert it to see which contacts are selected (I have used this plugin but I don't need this function to pick any single contact so not sure if there is any done button or not) then press done or ok button, which will redirect you to your another function where you can get that contacts or fulfill your next requirements.
function pickContact() {
navigator.contacts.pickContact(function(contact){
alert(JSON.stringify(contact));
//This is added by me, on done button click or single selection
setContacts(contact);
},function(err){
alert('bug !' + err);
console.log('Error: ' + err);
});
}
//This is added by me
function setContacts(ct)
{
alert(JSON.stringify(ct));
$("#contactlist").append(ct);
//or
var getData = JSON.parse(ct);
if(getData.length > 1)
{
for(i=0;i<getData.length;i++)
{
$("#contactlist").append(getData[i]);
}
}
}
Let me know if I am wrong or right.
Thanks a lot for your answer. Unfortunately , your code doesn't works for me, but I found what to do :
When pickcontact opens your native app "contacts", your cordova app is removed on background. On android, that means that you loose the state of your app, and so you have a bug. To solve the problem, you need to add onresume event on your js file, like this :
var app = {
// Application Constructor
initialize: function() {
this.onDeviceReady();
if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry)/)) {
document.addEventListener("deviceready", this.onDeviceReady, false);
} else {
this.onDeviceReady();
}
},
onDeviceReady: function() {
$("#pickContact").click(pickContact);
},
onResume: function(resumeEvent) {
//alert('onResume');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
}
};
app.initialize();
After that, you can retrieve your picked contact with a function like this :
function pickContact() {
navigator.contacts.pickContact(function(contact){
$("#divTest").append('<p>The following contact has been selected:' + JSON.stringify(contact));
},function(err){
alert('bug !' + err);
console.log('Error: ' + err);
});
}
So, like everytime in programming, when you know the answer, that's easy. But when you don't know, you loose hours and hours...
I hope that will help someone.

Right way of placing interestitial ad in ionic android platform

For showing interestitial ad in my android app (which i have made using ionic) i have used the following code :
<script type="text/javascript">
function runads(){
document.addEventListener("deviceready", onDeviceReady, false);
}
function initAds() {
if (admob) {
var adPublisherIds = {
ios : {
banner : "###############",
interstitial : "##################"
},
android : {
banner : "#############",
interstitial : "#########################"
}
};
var admobid = (/(android)/i.test(navigator.userAgent)) ? adPublisherIds.android : adPublisherIds.ios;
admob.setOptions({
publisherId: admobid.banner,
interstitialAdId: admobid.interstitial,
tappxIdiOs: "/XXXXXXXXX/Pub-XXXX-iOS-IIII",
tappxIdAndroid: "/XXXXXXXXX/Pub-XXXX-Android-AAAA",
tappxShare: 0.5
});
registerAdEvents();
} else {
alert('AdMobAds plugin not ready');
}
}
function onAdLoaded(e) {
if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
admob.showInterstitialAd();
showNextInterstitial = setTimeout(function() {
admob.requestInterstitialAd();
}, 2 * 60 * 1000); // 2 minutes
}
}
// optional, in case respond to events
function registerAdEvents() {
document.addEventListener(admob.events.onAdLoaded, onAdLoaded);
document.addEventListener(admob.events.onAdFailedToLoad, function (e) {});
document.addEventListener(admob.events.onAdOpened, function (e) {});
document.addEventListener(admob.events.onAdClosed, function (e) {});
document.addEventListener(admob.events.onAdLeftApplication, function (e) {});
document.addEventListener(admob.events.onInAppPurchaseRequested, function (e) {});
}
function onDeviceReady() {
document.removeEventListener('deviceready', onDeviceReady, false);
initAds();
// display a banner at startup
admob.createBannerView();
// request an interstitial
admob.requestInterstitialAd();
}
My interestitial ad is showing perfectly using this code.Then, i have uploaded it in google play store.suddenly i have got a message from google Admob team regarding interestitial ad placing . The message is -
Hello,We are alerting you that your app is currently in violation of the AdMob program policies. Importantly, this will require action on your part to ensure no disruption in ad serving. Please read below for more information on the actions you need to take:
Violation explanation
LAYOUT ENCOURAGES ACCIDENTAL CLICKS - INTERSTITIAL ADS:Publishers are not permitted to encourage users to click AdMob interstitial ads in any way. Please review how you’ve implemented interstitial ads and be mindful of the following non-compliant implementation(s):Interstitial ads that load unexpectedly while a user is viewing the app’s content.For more information about our policies and tips for how to comply please read the following:
Interstitial ads that load unexpectedly while a user is viewing the app’s content.For more information about our policies and tips for how to comply please read the following:AdMob ad placement policyAdMob interstitial ad guidanceAdMob preload instructions for Android and iOSAction required: Please make changes immediately to your app to comply with AdMob program policies.Current account status: ActiveYou do not need to contact us once you've made the necessary changes to your app. Please be aware that if additional violations are accrued, ad serving may be disabled to the app listed above.Note that the app listed above is just one example and the same violation may exist on other apps you own. We suggest that you review all your apps for compliance with the AdMob program policies to reduce the likelihood of future warnings.For more information regarding our policy warning notifications, visit our Help Center.Thank you for your cooperation.Sincerely,The Google AdMob Team
How Can i solve this problem ?
Probably what is going on is that the loading of an interstitial ad takes some time, so you need to plan the loading of an interstitial and ensure the interstitial is available when you need to show it. If not, launching admob.showInterstitialAd() will load the interstital and show it when it is available (as the flag autoShowInterstitial is true by default, see https://github.com/appfeel/admob-google-cordova/wiki/setOptions).
There is a complete example on how to plan the interstitials: https://github.com/appfeel/admob-google-cordova/wiki/showInterstitialAd.
Basically what you do is to request an interstitial and let the app know if the interstitial is available or not. Probably your code for ionic should look like this:
angular.module('myApp', ['admobModule'])
.constant('AdmobConfig', {
bannerId: /(android)/i.test(navigator.userAgent) ? "ca-app-pub-XXXXXXXXXXXXXXXX/ANDROID_BANNER_ID" : "ca-app-pub-XXXXXXXXXXXXXXXX/IOS_BANNER_ID",
interstitialId: /(android)/i.test(navigator.userAgent) ? "ca-app-pub-XXXXXXXXXXXXXXXX/ANDROID_INTERSTITIAL_ID" : "ca-app-pub-XXXXXXXXXXXXXXXX/IOS_INTERSTITIAL_ID",
})
.config(function (admobSvcProvider, AdmobConfig) {
admobSvcProvider.setOptions({
publisherId: AdmobConfig.bannerId,
interstitialAdId: AdmobConfig.interstitialId,
autoShowInterstitial: false,
});
})
.run(function ($rootScope, $ionicPlatform, $timeout, admobSvc) {
admobSvc.requestInterstitialAd();
$rootScope.isInterstitialAvailable = false;
$rootScope.isAppForeground = false;
$rootScope.$on(admobSvc.events.onAdLoaded, function onAdLoaded(evt, e) {
if ($rootScope.isAppForeground) {
if (e.adType === admobSvc.AD_TYPE.INTERSTITIAL) {
$rootScope.isInterstitialAvailable = true;
}
}
});
$rootScope.$on(admobSvc.events.onAdOpened, function onAdOpened(evt, e) {
if ($rootScope.isAppForeground) {
if (e.adType === admobSvc.AD_TYPE.INTERSTITIAL) {
$rootScope.isInterstitialAvailable = false;
$timeout(admobSvc.requestInterstitialAd, 1); // Immediately request next interstitial asap
}
}
});
$ionicPlatform.on('pause', function onPause() {
if ($rootScope.isAppForeground) {
$rootScope.isAppForeground = false;
}
});
$ionicPlatform.on('resume', function onResume() {
if (!$rootScope.isAppForeground) {
$timeout(admobSvc.requestInterstitialAd, 1);
$rootScope.isAppForeground = true;
}
});
})
.controller('YourController', function ($rootScope, admobSvc) {
var vm = this;
vm.pleaseShowInterstitial = function () {
if ($rootScope.isInterstitialAvailable) {
admobSvc.showInterstitialAd();
}
};
});
Also note that there is a management for foreground app. This is important as if not, the user could put the app in background and the interstitial would automatically be shown. In your case it is not so relevant, as you control when the interstitial is shown, but I recommend you to keep this, in case you decide to start auto showing interstitials :)

Sharing to Facebook shows error "We are Sorry, this post is no longer available. It may have been removed"

I'm trying to implement Facebook sharing in my game using Unity 3D + Facebook Unity SDK. But when I tried testing to post to my wall, this error shows up: "We are Sorry, this post is no longer available. It may have been removed." Can anybody help me? Thanks in advance.
BTW, here's my code:
using UnityEngine;
using System.Collections;
public class FacebookController : MonoBehaviour {
public bool isUsingFacebook = true; //Are we using Facebook SDK? This variable is only
//Feed parameters.
private string link = "market://details?id=com.LaserCookie.Queue"; //The link that will show the user the game's google play store address
private string linkName = "Queue"; //The link name
private string linkCaption = "Wow this game is great! 10/10 must play!"; // The caption of the link
private string linkDescription = "I achieved the score of " + PlayerController.instance.score.ToString() + "! Try to beat me if you can!"; //The description of the link
private string picture = "http://www.drycreekequestriancenter.com/testImage.jpeg"; //This is the image / game icon for the link. For now, it's shamelessly got from a random source. Thank you, random citizen...
void Awake()
{
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
//Init FB
private void Init()
{
if (!FB.IsInitialized)
{
FB.Init(OnInitComplete, OnHideUnity);
}
}
//Callback that will be called when the initialization is completed
private void OnInitComplete()
{
Debug.Log("FB.Init completed: Is user logged in? " + FB.IsLoggedIn);
//Check if we are logged in.
//If not, we will log in.
//If we are, post status.
if (!FB.IsLoggedIn)
{
LoginWithPublish();
}
else
{
PostImpl();
}
}
//Callback that will be called when the game is shown / not
private void OnHideUnity(bool isGameShown)
{
Debug.Log("Is game showing? " + isGameShown);
}
//Post to Facebook. This is the only exposed method because we only use this to post to Facebook.
//The initialization and login will be called when needed.
//It will first detect whether or not we have been initialized. And will init if we haven't.
//Then it will check whether or not we have been logged in with publish. And will log in if not.
public void PostToFacebook()
{
//Are we using facebook SDK?
if (isUsingFacebook)
{
if (!FB.IsInitialized) //Check for initialization
{
Init();
}
else if (!FB.IsLoggedIn) //Check for login
{
LoginWithPublish();
}
else //Post if we are already initia;ized and logged in
{
PostImpl();
}
}
}
//The true implementation of the posting
private void PostImpl()
{
FB.Feed("",link, linkName,linkCaption,linkDescription,picture);
}
//Login to Facebook with publish
private void LoginWithPublish()
{
// It is generally good behavior to split asking for read and publish
// permissions rather than ask for them all at once.
//
// In your own game, consider postponing this call until the moment
// you actually need it.
FB.Login("publish_actions", LoginCallback);
}
//Login callback
void LoginCallback(FBResult result)
{
if (result.Error != null)
{
Debug.Log( "Error Response:\n" + result.Error );
//TODO: Retry login if we have error? Or do we display a pop up?
}
else if (!FB.IsLoggedIn)
{
Debug.Log( "Login cancelled by Player" );
//TODO: Do we display a pop up?
}
else
{
Debug.Log( "Login was successful!" );
PostImpl();
}
}
}
You need to add Key Hash for FB application.
Go to My Apps, select you application, open Setting tab, add platform for android, and add you key hash.
check this link out
Setting a Release Key Hash
I've fixed the issue. It turns out it's because I used my still in development google store address as the link. I thought it would be automatically recognized regardless of my app is live or not. Thank you anyway. :)

Facebook apprequests dialog always returns cancelled Titanium Android?

I'm using facebook 3.0.1 titanium module. In Android, the Facebook apprequests dialog always returns as cancelled, even while the actual apprequest is send as can be seen on Facebook. Because of this I cannot store the requestid in my back-end, which makes the apprequest useless.
But in iOS it works fine.
This is my code
var fb = require('facebook');
fb.appid = 'my_app_id';
fb.permissions = ['publish_stream', 'read_stream', 'email']; // Permissions your app needs
fb.forceDialogAuth = true;
fb.addEventListener('login', function(evt) {
if (evt.success) {
fb.dialog("apprequests", {
message:"LeaugeNation",
// max_recipients : "2"
}, function(response) {
alert(JSON.stringify(response));
if(response.result) {
alert("send friend req");
// sendFacebookInvite(e.result);
}
});
} else if (evt.error) {
alert("error");
} else if (evt.cancelled) {
alert("cancelled");
} else {
alert("default");
}
});
fb.authorize();
If i run the code i'm getting the following result
{"cancelled":true,"code":-1,"success":false}
I made the following changes, but did't got the result.
changed the appid won't change result
changed the Key Hash for that Facebook App
Thanks in advance.
Can you please tell me what change, that i want to made to get the correct result in Android.
You must look to facebook setting. did you register Your activity and allow the permission from developers site which you are using here. Also If you are not exporting your app please export properly with proper keystore.

Categories

Resources