Imported Authenticator and Sync Adapter
Android Frappe Authenticator
Modified Source forked from frappe/mobile: mobile/platforms/android/src/io/frappe at android · revant/mobile · GitHub
If completed, this will add the contacts and event sync to current Cordova App on android, as well as help other android developers to use signed in ERPNext accounts from android phone.
Menu to select account if Authenticator account Added
var app = {
init: function() {
if(cordova.platformId === "android"){
var am = window.plugins.accountmanager;
am.getAccountsByType('io.frappe.auth', function(error, accounts)
{
if(error)
{
return;
}
if (accounts && accounts.length > 0){
app.start_desk();
}
//alert("go");
if(cordova.platformId === "android"){
document.addEventListener('deviceready', function(){
var am = window.plugins.accountmanager;
am.getAccountsByType('io.frappe.auth', function(error, accounts)
{
if(error)
{
return;
}
if (accounts && accounts.length > 0){
accounts.forEach(function(account)
{
$('.splash').addClass('hide');
$('.offcanvas-container').addClass('hide');
$('.android-accounts ul').append('<li class="list-group-item">' + account.name + '</li>');
$(".android-accounts ul li").click(function() {
var select_ac = $(this).html();
am.getUserData(account, 'frappeServer', function(error, frappeServer)
{
var item = document.createElement('LI');
called getAuthToken from Cordova JS
console.log(JSON.stringify(error));
}
else
{
if(frappeServer)
{
desk.frappe_server = frappeServer;
}
}
});
am.getAuthToken(account, "Full access", true, function(error, result){
if (result){
var bearerToken = JSON.parse(result);
desk.access_token = bearerToken.access_token;
$('.splash').removeClass('hide');
$('.offcanvas-container').removeClass('hide');
desk.start();
}
if (error) console.log(error);
});
});
Downloaded Assets with access_token
console.log(localStorage.server);
var url = localStorage.server + "/api/method/frappe.www.desk.get_desk_assets";
if(version && version === "v6") {
url = localStorage.server + "/api/method/frappe.templates.pages.desk.get_desk_assets";
}
$.ajax({
method: "GET",
beforeSend: function(request) {
if (desk.access_token) {
request.setRequestHeader("Authorization", "Bearer " + desk.access_token);
}
},
url: url,
data: {
build_version: build_version
}
}).success(function(data) {
// desk startup
window._version_number = data.message.build_version;
window.app = true;
Consequent calls fail because,
they are standard jquery calls from frappe js
they don’t contain header.
Workaround :
I’m stuck with BroadcastReceiver, as per the Stackoverflow link, I’ve tried adding BroadcastReceiver and <receiver>
tag in manifest.
Stuck with capture of Cordova’s HTTP calls in this receiver.
1 Like
Try using crosswalk instead of default android webview. crosswalk has chromium fullstack browser capabilities.
I think we don’t have control over choosing what cordova uses for rendering website unless we add one more plugin (guess).
@revant_one What’s the current state of your work on the Android integrations?
Are hey stable and will the be merged into the official ERPNext app in the near future?
It looks like an urgently needed future, and I’m surprised that there is so little talking about lately.
No commits from me since long time.