I want to get the GPS location of my device. I am using GeolocatorPlugin for Xamarin to get the Longitude and Latitude of my device. GPS is enabled on my device. I already added permission to my android manifest but I still get the error: "A geolocation error occured: Unauthorized" How can I fix this?
try
{
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 50;
var position = await locator.GetPositionAsync();
entLocation.Text = position.Longitude.ToString() + "," + position.Latitude.ToString();
}
catch (Exception ex)
{
//will catch any general exception and set message in a string
string msg = ex.Message;
await DisplayAlert("error", msg, "ok");
}
Put the code below inside your MainActivity.cs in your Android Project.
if(CheckSelfPermission(Manifest.Permission.AccessCoarseLocation) != (int)Permission.Granted)
{
RequestPermissions(new string[] { Manifest.Permission.AccessCoarseLocation, Manifest.Permission.AccessFineLocation }, 0);
}
I am trying to retrieve the Archived Messages From OpenFire
Please Note :
I have added the Archive Message Plugin.
Same code was working fine Locally, no throwing error for server installation for openfire.
I have gone through all the solutions provided on internet but failed to succeed.
I can see the archived messages in openfire panel.
below is the code to retrieve the messages :
public MamManager.MamQueryResult getArchivedMessages() {
//org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPPError: feature-not-implemented - cancel
try {
MamManager mamManager = MamManager.getInstanceFor(connection);
boolean isSupported = mamManager.isSupportedByServer();
if (isSupported) {
MamManager.MamQueryResult mamQueryResult = mamManager.pageAfter(JidCreate.from(mUsername + SERVICE_NAME), "2r2Vf-68", 250);
List<Forwarded> forwardedMessages = mamQueryResult.forwardedMessages;
Forwarded d = forwardedMessages.get(0);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Other then this I am also trying to implement the OfflineMessageManager for smack 4.2
below is the code for the offline maanger :
public static void handleOfflineMessages() throws Exception {
OfflineMessageManager offlineMessageManager = new OfflineMessageManager(getConnection());
if (!offlineMessageManager.supportsFlexibleRetrieval()) {
return;
}
if (offlineMessageManager.getMessageCount() == 0) {
String d = "ss";
} else {
List<Message> msgs = offlineMessageManager.getMessages();
for (Message msg : msgs) {
BareJid fullJid = msg.getFrom().asBareJid();
String messageBody = msg.getBody();
if (messageBody != null) {
}
}
// offlineMessageManager.deleteMessages();
}
}
Note : The above method is not throwing any error my I am always
getting the message count = 0. where as I am following the official
Doc for this. i.e not sending presence so as to get all offline
messages. but failed to do so.
this is the link for official doc : OfflineMessageManager
can anyone point what i am doing wrong?
Reload again at plugin in OF
Monitoring Service
That all
i use different savegames in my app. "coins" , "levels" , ...
It works fine but if a conflict detected then its wrong result.
/**
* Conflict resolution for when Snapshots are opened. Must be run in an AsyncTask or in a
* background thread,
*/
Snapshots.OpenSnapshotResult processSnapshotOpenResult(Snapshots.OpenSnapshotResult result, int retryCount) {
retryCount++;
int status = result.getStatus().getStatusCode();
Log.i(TAG, "Load Result for saveGame<" + savedGame.getName() + "> status: " + status);
if (status == GamesStatusCodes.STATUS_OK) {
return result;
} else if (status == GamesStatusCodes.STATUS_SNAPSHOT_CONTENTS_UNAVAILABLE) {
return result;
} else if (status == GamesStatusCodes.STATUS_SNAPSHOT_CONFLICT) {
saveResolveConflictGameData = true;
Log.i(TAG, "Konflikt aufgetreten");
Snapshots.OpenSnapshotResult resolveResult = null;
Snapshot snapshot = result.getSnapshot();
Snapshot conflictSnapshot = result.getConflictingSnapshot();
Snapshot mResolvedSnapshot = null;
mResolvedSnapshot = snapshot;
SnapshotMetadata s1Meta = snapshot.getMetadata();
SnapshotMetadata cMeta = conflictSnapshot.getMetadata();
// resolveConflict and get new merged Parser Object
//
Parser conflictParserTemp = savedGame.resolveConflict(snapshot, conflictSnapshot);
if ( conflictParserTemp == null) {
Log.e(TAG, "savedGame.resolveConflict(snapshot,conflictSnapshot) Error");
return result;
}
//
// wurde schon ein conflict behandelt ?
//
if ( conflictParser != null ) {
// merge previous Conflict with this conflict
conflictParser.merge(conflictParserTemp);
} else {
// set first conflict Parser
conflictParser = conflictParserTemp;
}
Log.i(TAG, String.format("Games.Snapshots.resolveConflict() Step %d", retryCount));
resolveResult =
Games.Snapshots.resolveConflict(
activity.mGoogleApiClient, result.getConflictId(), mResolvedSnapshot).await();
if (retryCount < MAX_SNAPSHOT_RESOLVE_RETRIES) {
// Recursively attempt again
return processSnapshotOpenResult(resolveResult, retryCount);
} else {
// Failed, log error and show Toast to the user
String message = "Could not resolve snapshot conflicts";
Log.e(TAG, message);
Toast.makeText(activity.getBaseContext(), message, Toast.LENGTH_LONG).show();
return resolveResult;
}
}
// Fail, return null.
return null;
}
The Error is that if I load savegame "coins" I become all conflicts from other savegames.
I see it here.
SnapshotMetadata s1Meta = snapshot.getMetadata();
SnapshotMetadata cMeta = conflictSnapshot.getMetadata();
The Snapshot for korrekt coins savegame show this:
SnapshotMetadataEntity{Game=GameEntity{ApplicationId=520840013521,
DisplayName=Crush me, PrimaryCategory=Simulation,
SecondaryCategory=null, Description=hallo, DeveloperName=steffen
höhmann, IconImageUri=null, IconImageUrl=null, HiResImageUri=null,
HiResImageUrl=null, FeaturedImageUri=null, FeaturedImageUrl=null,
PlayEnabledGame=true, InstanceInstalled=true,
InstancePackageName=cherry.de.wubbleburst, AchievementTotalCount=0,
LeaderboardCount=0, RealTimeMultiplayerEnabled=false,
TurnBasedMultiplayerEnabled=false, AreSnapshotsEnabled=true,
ThemeColor=00456B, HasGamepadSupport=false},
Owner=PlayerEntity{PlayerId=113260033482974102226,
DisplayName=shoehmi, HasDebugAccess=false, IconImageUri=null,
IconImageUrl=null, HiResImageUri=null, HiResImageUrl=null,
RetrievedTimestamp=1454003980807, Title=Anfänger,
LevelInfo=com.google.android.gms.games.PlayerLevelInfo#1e1b36},
SnapshotId=drive://113260033482974102226/520840013521/coins,
CoverImageUri=null, CoverImageUrl=null, CoverImageAspectRatio=0.0,
Description=null, LastModifiedTimestamp=1454004003382, PlayedTime=-1,
UniqueName=coins, ChangePending=true, ProgressValue=-1}
drive://113260033482974102226/520840013521/coins
and the snapshotData:
timestamp;coins#1453929273252;100#1453929280956;-70#230179;70
but he shows me savegame snaphot from "level" savegame as conflicted Snapshot:
levelId;points#1;3241#2;9634
and the Conflict Snapshot Metadata say it is a "coins" savegame:
SnapshotMetadataEntity{Game=GameEntity{ApplicationId=520840013521,
DisplayName=Crush me, PrimaryCategory=Simulation,
SecondaryCategory=null, Description=hallo, DeveloperName=steffen
höhmann, IconImageUri=null, IconImageUrl=null, HiResImageUri=null,
HiResImageUrl=null, FeaturedImageUri=null, FeaturedImageUrl=null,
PlayEnabledGame=true, InstanceInstalled=true,
InstancePackageName=cherry.de.wubbleburst, AchievementTotalCount=0,
LeaderboardCount=0, RealTimeMultiplayerEnabled=false,
TurnBasedMultiplayerEnabled=false, AreSnapshotsEnabled=true,
ThemeColor=00456B, HasGamepadSupport=false},
Owner=PlayerEntity{PlayerId=113260033482974102226,
DisplayName=shoehmi, HasDebugAccess=false, IconImageUri=null,
IconImageUrl=null, HiResImageUri=null, HiResImageUrl=null,
RetrievedTimestamp=1454003980807, Title=Anfänger,
LevelInfo=com.google.android.gms.games.PlayerLevelInfo#1e1b36},
SnapshotId=drive://113260033482974102226/520840013521/coins,
CoverImageUri=null, CoverImageUrl=null, CoverImageAspectRatio=0.0,
Description=null, LastModifiedTimestamp=1454004003382, PlayedTime=-1,
UniqueName=coins, ChangePending=true, ProgressValue=-1}
drive://113260033482974102226/520840013521/coins
Why only if conflict occured and without conflicts its running correct and
save / load correct??
Please Help me???
sorry for my english ;)
I am using Google App Engine as backend for GCM. It is working fine except below error:
{ "error": { "errors": [ {
"domain": "global",
"reason": "backendError",
"message": "com.google.apphosting.api.ApiProxy$CancelledException: The API call urlfetch.Fetch() was explicitly cancelled." } ],
"code": 503, "message":
"com.google.apphosting.api.ApiProxy$CancelledException: The API call
urlfetch.Fetch() was explicitly cancelled." } }
To find cause I searched urlfetch.Fetch() method in my entire code, but I dint find it.
Does anyone got this same error before? If so then please tell me how you resolved it?
For more info, I added below code to send push notification for more than 1000 users.
private List<RegistrationRecord> regIdTrim(List<RegistrationRecord> wholeList, final int start) {
List<RegistrationRecord> parts = wholeList.subList(start,(start+1000)> wholeList.size()? wholeList.size() : start+1000);
return parts;
}
/**
* Send to the first 1000 devices (You can modify this to send to any number of devices or a specific device)
*
* #param message The message to send
*/
public void sendMessage(#Named("message") String message) throws IOException {
int count = ofy().load().type(RegistrationRecord.class).count();
if(count<=1) {
List<RegistrationRecord> records = ofy().load().type(RegistrationRecord.class).limit(count).list();
sendMsg(records,message);
}else
{
int msgsDone=0;
List<RegistrationRecord> records = ofy().load().type(RegistrationRecord.class).list();
do {
List<RegistrationRecord> regIdsParts = regIdTrim(records, msgsDone);
msgsDone+=1000;
sendMsg(regIdsParts,message);
}while(msgsDone<count);
}
}
private void sendMsg(List<RegistrationRecord> records,#Named("message") String msgToSend) throws IOException {
if (msgToSend == null || msgToSend.trim().length() == 0) {
log.warning("Not sending msgToSend because it is empty");
return;
}
Sender sender = new Sender(API_KEY);
// Message msg = new Message.Builder().addData("msgToSend", msgToSend).build();
Message msg = new Message.Builder().
addData("notification_title", msgToSend)
.addData("description","Check ").build();
// crop longer messages
if (msgToSend.length() > 1000) {
msgToSend = msgToSend.substring(0, 1000) + "[...]";
}
for (RegistrationRecord record : records) {
Result result = sender.send(msg, record.getRegId(), 5);
if (result.getMessageId() != null) {
log.info("Message sent to " + record.getRegId());
String canonicalRegId = result.getCanonicalRegistrationId();
if (canonicalRegId != null) {
// if the regId changed, we have to update the datastore
log.info("Registration Id changed for " + record.getRegId() + " updating to " + canonicalRegId);
record.setRegId(canonicalRegId);
ofy().save().entity(record).now();
}
} else {
String error = result.getErrorCodeName();
if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
log.warning("Registration Id " + record.getRegId() + " no longer registered with GCM, removing from datastore");
// if the device is no longer registered with Gcm, remove it from the datastore
ofy().delete().entity(record).now();
} else {
log.warning("Error when sending msgToSend : " + error);
}
}
}
}
It looks like server is blocking you :/
I believe it has something to do with the 1000 network requests you're shooting at it.
Send the server a list of the 1000 ids you want to push to them, and let the server handle the pushes.
Here is a function get the node of a webservice of drupal in ssets\www\modules\node\node.js of the android project. When i click content and try to retrieve a node in the apps in android emulator, there is an error message "node_page_view reference error:nid is not defined", the apps seems can read the node/%, so i want to debug the function, see the alert(node); in the following code. But i re-run the program, there is nothing happen, any ideas?
function node_page_view(node) {
alert(node);
try {
if (drupalgap.settings.debug) {
console.log('node_page_view()');
console.log(JSON.stringify(arguments));
}
if (node) {
var build = {
'theme':'node',
'node':node, // TODO - is this line of code doing anything?
'title':{'markup':node.title}, // TODO - this is a core field and should probably by fetched from entity.js
'content':{'markup':node.content},
};
// If the comments are hidden, do nothing.
if (node.comment == 0) { }
// If the comments are closed or open, show the comments.
else if (node.comment == 1 || node.comment == 2) {
// Build an empty list for the comments
build.comments = {
'theme':'jqm_item_list',
'title':'Comments',
'items':[],
'attributes':{'id':'comment_listing_items'},
};
// If the comments are open, show the comment form.
if (node.comment == 2) {
build.comments_form = {
'markup':
'<h2>Add comment</h2>' +
drupalgap_get_form('comment_edit', {'nid':node.nid})
};
}
}
return build;
}
else {
alert('node_page_view - failed to load node (' + nid + ')');
}
}
catch (error) {
alert('node_page_view - ' + error);
}
}
Have you tried weinre?
http://people.apache.org/~pmuellr/weinre/docs/latest/
or Medic:
https://github.com/filmaj/medic