I'm trying to use AllJoyn for my app, but when I'm trying to use code from sample (sample 13), I can't join to session and get error BUS_BLOCKING_CALL_NOT_ALLOWED.
bus.registerBusListener(new BusListener() {
#Override
public void foundAdvertisedName(String name,
short transport,
String namePrefix) {
short contactPort = CONTACT_PORT;
SessionOpts sessionOpts = new SessionOpts();
Mutable.IntegerValue sessionId = new Mutable.IntegerValue();
Status status = bus.joinSession("com.my.well.known.name", //here's error: status = BUS_BLOCKING_CALL_NOT_ALLOWED
contactPort,
sessionId,
sessionOpts,
new SessionListener());
bus.cancelAdvertiseName("com.my.well.known.name",SessionOpts.TRANSPORT_ANY);
}
});
This code is from sample and I have no idea what's wrong with it. Can you help me?
If necessary, here's full code: http://pastebin.com/f1sD7RtK
I'm trying to create new channel and connect to it automatically, without user's participation.
Also I'll be very grateful for any good advices or samples.
Try calling bus.enableConcurrentCallbacks() prior to calling bus.joinSession(...) in the foundAdvertisedName method.
This will allow AllJoyn to dispatch an additional callback while the current one, foundAdvertisedName, is still executing.
Here's a link to the documentation that explains what is happening.
Related
I got App api_id, App api_hash and Production configuration from telegram.org, I need to use from this method messages.sendMessage for Sends a text message to a specific number phone's telegram(for example: +1888888). How can I use from this method. Is there any a simple sample?
I suggest you using a top-layer library over MTProto to make things easier. For example you can use Telethon. You should use SendMessageRequest in order to send message. After creating a client you can call it like this (in newest version of Telethon the phone number is resolved automatically):
from telethon.tl.functions.messages import SendMessageRequest
client(SendMessageRequest('phone_number', 'hello'))
If you're using TDLib, you may use this function (taken from here) or a similar one:
private static void sendMessage(long chatId, String message) {
// initialize reply markup just for testing
TdApi.InlineKeyboardButton[] row = {new TdApi.InlineKeyboardButton("https://telegram.org?1", new TdApi.InlineKeyboardButtonTypeUrl()), new TdApi.InlineKeyboardButton("https://telegram.org?2", new TdApi.InlineKeyboardButtonTypeUrl()), new TdApi.InlineKeyboardButton("https://telegram.org?3", new TdApi.InlineKeyboardButtonTypeUrl())};
TdApi.ReplyMarkup replyMarkup = new TdApi.ReplyMarkupInlineKeyboard(new TdApi.InlineKeyboardButton[][]{row, row, row});
TdApi.InputMessageContent content = new TdApi.InputMessageText(new TdApi.FormattedText(message, null), false, true);
client.send(new TdApi.SendMessage(chatId, 0, false, false, replyMarkup, content), defaultHandler);
}
Don't forget that, you need to add each phone number to user's Telegram contacts first to get the chatId. It can be achieved by passing an array of phone numbers to this function:
---functions---
contacts.importContacts#2c800be5 contacts:Vector<InputContact> = contacts.ImportedContacts
I have an ASP.NET C# MVC4 Web site that I have working wonderfully for the most part. However, when we tested on mobile, the cookies that I am using for authentication would not work. I set the Auth cookie in my controller action but when trying to access them on the next call they are not there. Once again this is ONLY A PROBLEM ON MOBILE. Works fine in desktop versions of IE, Chrome and Firefox. Does not work with Chrome on Android.
Code to write cookie (in controller action):
//Set information into object that can be read out of the cookie later
FormsAuthModel UserDataObj = new FormsAuthModel
{
UserID = dmUser.ID,
PasswordChange = dmUser.PasswordChange
};
string UserData = Convert.ToBase64String(clsShared.Serialize(UserDataObj));
//Create the ticket
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, dmUser.UserName, DateTime.Now, DateTime.Now.AddDays(1), false, UserData, FormsAuthentication.FormsCookiePath);
// Encrypt the ticket
string encTicket = FormsAuthentication.Encrypt(ticket);
// Create the cookie
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
System.Web.HttpContext.Current.Response.Cookies.Add(cookie);
Code to read cookie (in Global.asax.cs - Application_PostAuthenticateRequest):
HttpCookie authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
if (authCookie != null)
{
try
{
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
UserDataObj = (FormsAuthModel)clsShared.Deserialize(Convert.FromBase64String(authTicket.UserData), typeof(FormsAuthModel));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
//WriteEvent(string.Format("Error deserializing auth ticket - {0}", ex.Message), EventLogEntryType.Error);
}
}
The AuthCookie is always null on the subsequent requests. What the user sees is a login screen, they fill it out and they get redirected right back to the login screen.
I could not find anything in my searches that helped explain why all the mobile requests (my phone, my tablet and other users' phones) would act differently than the desktop browsers.
Any help would be greatly appreciated.
Thanks!!
OK I found a solution although I am not sure why. I changed the cookie creation code as follows and it worked.
//Set information into object that can be read out of the cookie later
FormsAuthModel UserDataObj = new FormsAuthModel
{
UserID = dmUser.ID,
PasswordChange = dmUser.PasswordChange
};
string UserData = Convert.ToBase64String(clsShared.Serialize(UserDataObj));
//Create the ticket
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, dmUser.UserName, DateTime.Now, DateTime.Now.AddDays(1), false, UserData, FormsAuthentication.FormsCookiePath);
// Encrypt the ticket
string encTicket = FormsAuthentication.Encrypt(ticket);
// Create the cookie - FIX IS HERE!!!
Response.Cookies[FormsAuthentication.FormsCookieName].Value = encTicket;
//HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
//Response.Cookies.Add(cookie);
Notice that the only change is in adding the cookie by setting the value directly instead of creating a cookie object and adding that to the collection.
i.e. - Response.Cookies["Name"] = Value;
I got the idea from this MS article: https://msdn.microsoft.com/en-us/library/ms178194.aspx.
So does anyone know why this would make a difference? I have used the cookie instance method several times before and never had this problem.
I don't understand why Profile always return error : "ProviderNotFoundException". I followed pre-comipiled integration instructions, and I use latest versions on github for soomla-cocos2dx-core,cocos2dx-profile and cocos2dx-store.
Here is an example done with cocos2dx v3.5 (same behaviour on 3.4):
soomla::CCError *profileError = nullptr;
bool isLoggedIn = soomla::CCSoomlaProfile::getInstance()->isLoggedIn(soomla::TWITTER, &profileError);
if (profileError)
MessageBox(profileError->getInfo(), "Error");
else
CCLOG("logged in TWITTER: %d",isLoggedIn);
Application compiles successfully but that code throws a MessageBox saying "ProviderNotFoundException".
In AppDelegate.cpp here is the init I do from applicationDidFinishLaunching:
#define NEWSTRING(s) __String::create(s)
SOOMLA_STORE_EVENTS = new TSoomlaStoreEvents(); // My defined store events
PRODUCTSFORSALE = TItemsForSale::create(); //class for buy items
STOREITEMS = __Dictionary::create();
soomla::CCSoomla::initialize(SOOMLA_CUSTOM_SECRET);//"customSecret");
STOREITEMS->setObject(NEWSTRING(SOOMLA_ANDROID_PUBLIC_KEY), "androidPublicKey");
STOREITEMS->setObject(Bool::create(true), "SSV");
soomla::CCSoomlaStore::initialize(PRODUCTSFORSALE, STOREITEMS);
//----- SOOMLA PROFILE
__Dictionary *profileParams = __Dictionary::create();
__Dictionary *twitterParams = __Dictionary::create();
__Dictionary *googleParams = __Dictionary::create();
twitterParams->setObject(NEWSTRING(SOOMLA_TWITTER_CONSUMER_KEY), "consumerKey");
twitterParams->setObject(NEWSTRING(SOOMLA_TWITTER_CONSUMER_SECRET), "consumerSecret");
googleParams->setObject( NEWSTRING(SOOMLA_GOOGLE_CLIENTID), "clientId");
profileParams->setObject(twitterParams, soomla::CCUserProfileUtils::providerEnumToString(soomla::TWITTER)->getCString());
profileParams->setObject(googleParams, soomla::CCUserProfileUtils::providerEnumToString(soomla::GOOGLE)->getCString());
soomla::CCSoomlaProfile::initialize(profileParams);
Can you help me going further with Profile, please?
this is not an answer, but you might be able to glean something from here: http://answers.soom.la/t/resolved-twitter-providernotfoundexception/675/6
and here: http://answers.soom.la/t/resolved-exception-with-cocos2d-x-profile/1572
As I understand they use reflection in order to load providers (
https://github.com/soomla/ios-profile/blob/9e887f07e0d7f1acb680e02c593a8ce485c93252/SoomlaiOSProfile/ProviderLoader.m#L43). Maybe those classed just have not been loaded.
You can try to use "-ObjC" linker flag, or something like that.
We are using Azure Mobile Services to Push notifications to a Xamarin Android and a Xamarin iOS and a Windows Universal App. The Windows Universal App has plenty of documentation around what we need, although we haven’t had a chance to implement it yet. However, both Xamarin Android and iOS are missing all documentation around Push Notifications. If you go to http://azure.microsoft.com/en-us/documentation/services/mobile-services/ and select Xamarin Android or Xamarin iOS and .NET Backend there are zero links for documentation around these APIs. After digging around a ton yesterday I found this: http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-xamarin-android-get-started-push/ and http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-xamarin-ios-get-started-push/ both which were last updated in September of last year. The documentation was promised to be updated over 5 months ago.
When I use the Xamarin Component from Microsoft for Azure Mobile Services: http://components.xamarin.com/view/azure-mobile-services/ I am able to get the MobileServiceClient up and running, but not the Push notifications.
The API:
Push pushManager = MobileService.GetPush();
string deviceId = "what is this???";
//Option 1:
pushManager.RegisterNativeAsync(deviceId);
//Option 2:
GcmRegistration googleNotificationRegistration = new GcmRegistration(deviceId);
pushManager.RegisterAsync(googleNotificationRegistration);
Documentation I’m using:
Push.RegisterAsync:
https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.mobileservices.push.registerasync.aspx
GcmRegistration: I can’t find any documentation for this class
Registration (Base class for GcmRegistration):
https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.mobileservices.registration.aspx
Note: the parameter for Registration is not named deviceId it is named channelUri
Push.RegisterNativeAsync:
https://msdn.microsoft.com/en-us/library/dn643553.aspx
Note: the parameter of RegisterNativeAsync is not named deviceId it is named channelUri
My question is simple:
What is deviceId supposed to be? And how do I get it?
All the documentation above is for Winodws Universal Apps not for Xamarin Apps on Mono.
In the writing up of this question I have found articles about "Get Started with Notification Hubs":
Xamarin iOS - http://azure.microsoft.com/en-us/documentation/articles/partner-xamarin-notification-hubs-ios-get-started/
Xamarin Android - http://azure.microsoft.com/en-us/documentation/articles/partner-xamarin-notification-hubs-android-get-started/
Are these the example I should be using? They look old and the Android one mentions nothing about Azure Mobile Services. Should I not even be using the Azure Mobile Services Xamarin Component for Android?
tl;dr
deviceId should be just the GCMRegistrationId.
I looked into the source code of the implementations of the component DLLs and also Android SDKs.
Firstly, let's take a look to your option 1 and option 2 behind the scene. Basically both eventually do the same job of creating a GcmRegistration and passing it the internal RegistrationManager.
public Task RegisterAsync (Registration registration)
{
if (registration == null) {
throw new ArgumentNullException ("registration");
}
if (string.IsNullOrWhiteSpace (registration.PushHandle)) {
throw new ArgumentNullException ("registration.deviceId");
}
return this.RegistrationManager.RegisterAsync (registration);
}
public Task RegisterNativeAsync (string deviceId, IEnumerable<string> tags)
{
if (string.IsNullOrWhiteSpace (deviceId)) {
throw new ArgumentNullException ("deviceId");
}
GcmRegistration registration = new GcmRegistration (deviceId, tags);
return this.RegistrationManager.RegisterAsync (registration);
}
Then, one of the API calls that I can find involving the Registration.PushHandle (which is the deviceId you passed) is as below
public async Task<IEnumerable<Registration>> ListRegistrationsAsync (string deviceId)
{
MobileServiceHttpResponse mobileServiceHttpResponse = await this.client.HttpClient.RequestAsync (HttpMethod.Get, string.Format ("/push/registrations?deviceId={0}&platform={1}", new object[] {
Uri.EscapeUriString (deviceId),
Uri.EscapeUriString (Platform.Instance.PushUtility.GetPlatform ())
}), this.client.CurrentUser, null, true, null, MobileServiceFeatures.None);
return JsonConvert.DeserializeObject<IEnumerable<Registration>> (mobileServiceHttpResponse.Content, new JsonConverter[] {
new RegistrationConverter ()
});
}
I have then switched to Android Mobile Services SDK to look for similar code to find some hints. Sadly, it is found called pnsHandle in android but still no hints what it is.
/**
* Registers the client for native notifications with the specified tags
* #param pnsHandle PNS specific identifier
* #param tags Tags to use in the registration
* #return The created registration
* #throws Exception
*/
public Registration register(String pnsHandle, String... tags) throws Exception {
if (isNullOrWhiteSpace(pnsHandle)) {
throw new IllegalArgumentException("pnsHandle");
}
Registration registration = PnsSpecificRegistrationFactory.getInstance().createNativeRegistration(mNotificationHubPath);
registration.setPNSHandle(pnsHandle);
registration.setName(Registration.DEFAULT_REGISTRATION_NAME);
registration.addTags(tags);
return registerInternal(registration);
}
Finally, I guess the below example code from http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-android-get-started-push/#update-app should be calling the same API which now explain everything, i.e. deviceId is just the GCMRegistrationId.
#Override
public void onRegistered(Context context, final String gcmRegistrationId) {
super.onRegistered(context, gcmRegistrationId);
new AsyncTask<Void, Void, Void>() {
protected Void doInBackground(Void... params) {
try {
ToDoActivity.mClient.getPush().register(gcmRegistrationId, null);
return null;
}
catch(Exception e) {
// handle error
}
return null;
}
}.execute();
}
I am using Smack in an Android app for XMPP based communication. I am trying to create a privacy list using PrivacyManager. I have created a PrivacyList successfully, but when I try to access that list it returns ClassCastException. Here is the code:
PrivacyListManager privacyManager;
privacyManager = PrivacyListManager.getInstanceFor(connection);
PrivacyList privacyList = privacyManager.getPrivacyList("msg_block_list");
Investigating a bit more, I have found that the exception occurs in getRequest method in PrivacyListManager.java class on following line:
Privacy privacyAnswer =
(Privacy) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
Here is the getRequest method:
private Privacy getRequest(Privacy requestPrivacy) throws XMPPException {
// The request is a get iq type
requestPrivacy.setType(Privacy.Type.GET);
requestPrivacy.setFrom(this.getUser());
// Filter packets looking for an answer from the server.
PacketFilter responseFilter = new PacketIDFilter(requestPrivacy.getPacketID());
PacketCollector response = connection.createPacketCollector(responseFilter);
// Send create & join packet.
connection.sendPacket(requestPrivacy);
// Wait up to a certain number of seconds for a reply.
Privacy privacyAnswer =
(Privacy) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
response.cancel();
// Interprete the result and answer the privacy only if it is valid
if (privacyAnswer == null) {
throw new XMPPException("No response from server.");
}
else if (privacyAnswer.getError() != null) {
throw new XMPPException(privacyAnswer.getError());
}
return privacyAnswer;
}
I have followed this tutorial for implementing PrivacyList. Anyone can help?
PacketCollector's method getResult() returns Packet object, but it could be any inherited from Packet class object, either Message or Presence or IQ (in IQ case you can use (privacy) cast, because Privacy is IQ's child class). In your case it seems like you get object which is present in another hierarchy, than Privacy class.
I have found the problem. The XML file smack.providers was missing. I created the file with following contents and it worked.
<?xml version="1.0"?>
<!-- Providers file for default Smack extensions -->
<smackProviders>
<!-- Privacy -->
<iqProvider>
<elementName>query</elementName>
<namespace>jabber:iq:privacy</namespace>
<className>org.jivesoftware.smack.provider.PrivacyProvider</className>
</iqProvider>
</smackProviders>