java - Cordova and startResolutionForResult VS. startActivityForResult -



java - Cordova and startResolutionForResult VS. startActivityForResult -

i making cordova plugin google play. @ moment i've "corrupted" plugin modifying cordovaactivity function manually. need set code within of plugin file, not split between cordovaactivity , plugin file.

to this, need transfer callbacks onactivityresult initiated via startresolutionforresult plugin-specific function. comparison, believe startactivityforresult have mechanism, cannot find similar startresolutionforresult.

can think of mechanism this?

here cordovaactivity code , plugin code.

cordovaactivity:

package com.flyingsoft.safari.jigsaw.free; import android.os.bundle; import org.apache.cordova.*; import android.util.log; import android.content.intent; import com.flyingsoftgames.googleplayservices.googleplayservices; public class mygame extends cordovaactivity { private static final string logtag = "mygame"; public void onactivityresult (int requestcode, int responsecode, intent intent) { log.w (logtag, "onactivityresult"); if (!googleplayservices.mgoogleapiclient.isconnecting()) googleplayservices.mgoogleapiclient.connect (); } @override public void oncreate (bundle savedinstancestate) { super.oncreate (savedinstancestate); super.init (); super.loadurl(config.getstarturl()); } }

plugin: bundle com.flyingsoftgames.googleplayservices; import com.google.android.gms.common.connectionresult; import com.google.android.gms.common.scopes; import com.google.android.gms.common.api.googleapiclient; import com.google.android.gms.common.api.googleapiclient.connectioncallbacks; import com.google.android.gms.common.api.googleapiclient.onconnectionfailedlistener; import com.google.android.gms.common.googleplayservicesutil; import com.google.android.gms.games.players; import com.google.android.gms.games.games; import com.google.android.gms.auth.googleauthexception; import com.google.android.gms.auth.googleauthutil; import com.google.android.gms.auth.userrecoverableauthexception; import com.google.android.gms.auth.googleplayservicesavailabilityexception; import com.google.android.gms.plus.account; import com.google.android.gms.plus.plus; import org.apache.cordova.callbackcontext; import org.apache.cordova.cordovainterface; import org.apache.cordova.cordovaplugin; import org.apache.cordova.cordovawebview; import org.apache.cordova.pluginresult; import org.apache.cordova.pluginresult.status; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject; import android.content.context; import android.content.intent; import android.content.intentsender.sendintentexception; import android.app.activity; import android.os.asynctask; import android.os.bundle; import org.apache.cordova.*; import java.io.ioexception; import android.util.log; public class googleplayservices extends cordovaplugin implements googleapiclient.connectioncallbacks, googleapiclient.onconnectionfailedlistener { private static final string logtag = "googleplayservices"; private static final int req_sign_in_required = 55664; public cordovainterface cordova = null; public cordovawebview webview = null; public static googleapiclient mgoogleapiclient = null; public callbackcontext tryconnectcallback = null; public string accesstoken = ""; @override public void initialize (cordovainterface initcordova, cordovawebview initwebview) { cordova = initcordova; webview = initwebview; super.initialize (cordova, webview); } @override public void onconnectionfailed (connectionresult result) { if (!result.hasresolution()) {log.w (logtag, "error: no resolution. google play services connection failed."); return;} seek { result.startresolutionforresult (cordova.getactivity(), result.geterrorcode()); } grab (sendintentexception e) { // there error resolution intent. seek again. mgoogleapiclient.connect (); } } @override public void onconnected (bundle connectionhint) { string maccountname = plus.accountapi.getaccountname(mgoogleapiclient); new retrievetokentask().execute (maccountname); games.setviewforpopups (mgoogleapiclient, webview); } public void onactivityresult (int requestcode, int responsecode, intent intent) { if (!mgoogleapiclient.isconnecting()) mgoogleapiclient.connect (); } @override public void onconnectionsuspended (int cause) { mgoogleapiclient.connect (); } public boolean execute (string action, jsonarray inputs, callbackcontext callbackcontext) throws jsonexception { if ("getplayerid".equals(action)) { string playerid = games.players.getcurrentplayerid (mgoogleapiclient); callbackcontext.sendpluginresult (new pluginresult (pluginresult.status.ok, playerid)); } else if ("tryconnect".equals(action)) { tryconnect (callbackcontext); } else if ("getaccesstoken".equals(action)) { callbackcontext.sendpluginresult (new pluginresult (pluginresult.status.ok, accesstoken)); } homecoming true; } // tryconnect runs callback value of false if google play services isn't available. public void tryconnect (callbackcontext callbackcontext) { boolean isgpsavailable = (googleplayservicesutil.isgoogleplayservicesavailable(cordova.getactivity()) == connectionresult.success); if (!isgpsavailable) { callbackcontext.sendpluginresult (new pluginresult (pluginresult.status.ok, false)); return; } tryconnectcallback = callbackcontext; mgoogleapiclient = new googleapiclient.builder (cordova.getactivity().getapplicationcontext()) .addconnectioncallbacks (this) .addonconnectionfailedlistener (this) .addapi (games.api) .addscope (games.scope_games) .addapi(plus.api) .addscope(plus.scope_plus_login) .build (); mgoogleapiclient.connect (); } private class retrievetokentask extends asynctask<string, void, string> { @override protected string doinbackground (string... params) { string accountname = params[0]; string scope = "oauth2:" + scopes.profile + " " + "email"; context context = cordova.getactivity().getapplicationcontext(); log.e (logtag, "retrievetokentask"); seek { accesstoken = googleauthutil.gettoken (context, accountname, scope); googleauthutil.cleartoken (context, accesstoken); accesstoken = googleauthutil.gettoken (context, accountname, scope); } grab (ioexception e) { log.e (logtag, e.getmessage()); } grab (userrecoverableauthexception e) { cordova.getactivity().startactivityforresult (e.getintent(), req_sign_in_required); } grab (googleauthexception e) { log.e (logtag, e.getmessage()); } homecoming accesstoken; } @override protected void onpostexecute (string newaccesstoken) { super.onpostexecute (newaccesstoken); accesstoken = newaccesstoken; if (tryconnectcallback != null) { string playerid = games.players.getcurrentplayerid (mgoogleapiclient); tryconnectcallback.sendpluginresult (new pluginresult (pluginresult.status.ok, playerid)); tryconnectcallback = null; } } } }

i found solution that.

in initialize method of class extends cordovaplugin 1 call:

cordova.setactivityresultcallback(this);

and implement method:

public void onactivityresult(int requestcode, int resultcode, intent data)

as on android.

java android cordova google-play-services

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -