I've got a dental camera and iam try to get windows to press space when the camera button is pressed
I have the OEM software and driver installed, it works perfect, gets the feed and makes a snapshot when camera button is pressed. I need to use another software for the feed and the snapshot, the software gets the feed but doesn't react to camera button, it only reacts to space key press(part of the oem driver), so my way of solving this was getting the device by product id and listening the button press event and remapping it space press.
I am pretty much stuck at this point.
How can I listen on events coming from the device I've got?
public static Device findDCam(){
// Create the libusb context
Context context = new Context();
// Initialize the libusb context
int result = LibUsb.init(context);
if (result < 0)
{
throw new LibUsbException("Unable to initialize libusb", result);
}
// Read the USB device list
DeviceList list = new DeviceList();
result = LibUsb.getDeviceList(context, list);
if (result < 0)
{
throw new LibUsbException("Unable to get device list", result);
}
try
{
// Iterate over all devices and list them
for (Device device: list)
{
DeviceDescriptor descriptor = new DeviceDescriptor();
result = LibUsb.getDeviceDescriptor(device, descriptor);
if (result < 0)
{
throw new LibUsbException(
"Unable to read device descriptor", result);
}
if(descriptor.idProduct()== -3810){
System.out.println("D cam found");
return device;
}
}
}
finally
{
// Ensure the allocated device list is freed
LibUsb.freeDeviceList(list, true);
}
// Deinitialize the libusb context
LibUsb.exit(context);
return null;
}
I've also thought that maybe it's impossible using usb4java since as far as i understood, if i want to listen on the usb port i need to take control from the driver and then its pointless.
Maybe iam going all wrong and i should use the driver instead?
Or maybe there is an app that can read button presses from a specific device and remap it?
If the camera has a standard driver, this should work through this video capture SDK. To quick test it, run the demo executable included in the package, select the camera in the list, check the "webcam snapshot button" checkbox and start the camera. Then press the camera button to test the snapshot.
I am working on a android news app which gets news from google news rss feed. I am currently getting news and showing it to the user in my app. But I want to show notification to the user when new news appears on google rss. I have no idea how to do it as I am new to android and could not find anything relevant on google. Thank you.
Here is my code I have done so far
internal static List<FeedItem> GetFeedItems(string url)
{
List<FeedItem> feedItemsList = new List<FeedItem>();
try
{
HttpClient wc = new HttpClient();
var html = wc.GetStringAsync(new Uri(url)).Result;
XElement xmlitems = XElement.Parse(html);
// We need to create a list of the elements
List<XElement> elements = xmlitems.Descendants("item").ToList();
// Now we're putting the informations that we got in our ListBox in the XAML code
// we have to use a foreach statment to be able to read all the elements
// Description , Link , Title are the attributes in the RSSItem class that I've already added
List<FeedItem> aux = new List<FeedItem>();
foreach (XElement rssItem in elements)
{
FeedItem rss = new FeedItem();
rss.Description = rssItem.Element("description").Value;
rss.Link = rssItem.Element("link").Value;
rss.Title = rssItem.Element("title").Value;
feedItemsList.Add(rss);
}
}
catch (Exception)
{
throw;
}
return feedItemsList;
}
Use parse's push notification,it's very easy to use and has great documents.
https://parse.com
go for push notification service. its the only way to get the notification .
follow this tutorial... http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/
Notification manager is what you want here.
see this http://developer.android.com/guide/topics/ui/notifiers/notifications.html ?
A simple google search also shows tutorials for the same
Several of my timeline item designs require multiple images, yet I am having difficulty attaching them all reliably. The timeline.insert function only seems to allow for one attachment and inserting attachments after the timeline item is inserted sometimes results in the images not being rendered.
I also tried using setAttachments on the timeline item itself but it didn't seem to actually upload the attachments when inserting the item. Using the code below I tend to get mixed results. Sometimes it works and other times it fails to render the image. There seems to be a correlation with how long I wait to view the notification after receiving it, if I view it too quickly it never fully renders.
Does anyone have any thoughts or suggestions on how I could overcome this or see anything I'm doing wrong?
//CardFactory.java - Create TimelineItem with attachment list
public static TimelineItem getConceptCard(String conceptImage) {
TimelineItem timelineItem = new TimelineItem();
timelineItem.setHtml("<article class=\"photo\">\n <img src=\"attachment:0\" width=\"100%\" height=\"100%\">\n <div class=\"photo-overlay\"/>\n <section>\n <p class=\"text-auto-size\">Test</p>\n </section>\n</article>\n");
List<Attachment> attachments = new ArrayList<Attachment>();
Attachment img1 = new Attachment();
img1.setId("backImage");
img1.setContentType("image/jpeg");
img1.setContentUrl(WebUtil.buildStaticImgUrl("cardconcepts/" + conceptImage + ".JPG"));
attachments.add(img1);
timelineItem.setAttachments(attachments);
timelineItem.setNotification(new NotificationConfig().setLevel("DEFAULT"));
return timelineItem;
}
//MainServlet.java - Send TimelineItem on button press
} else if (req.getParameter("operation").equals("insertConceptCard")) {
TimelineItem timelineItem = CardFactory.getConceptCard(req.getParameter("conceptCard"));
MirrorClient.insertTimelineCard(credential, timelineItem);
//MirrorClient.java - Insert TimelineItem with multiple attachments
public static void insertTimelineCard(Credential credential, TimelineItem item) throws IOException {
Mirror.Timeline timeline = getMirror(credential).timeline();
TimelineItem timelineItem = timeline.insert(item).execute();
for(Attachment TAttach : item.getAttachments()){
InputStreamContent mediaContent = new InputStreamContent(TAttach.getContentType(), new URL(TAttach.getContentUrl()).openStream());
timeline.attachments().insert(timelineItem.getId(), mediaContent).execute();
}
I am not sure if it is possible given your requirements, but if the attachments are public images, you don't actually need to attach them. You can use the img tag with a normal http URL. My experience has been that these get fetched fairly quickly, are cached if you use them frequently, and render correctly even if they don't render immediately.
(Even if your requirements need to keep these more private, you may wish to use standard image fetching with some kind of nonce instead of trying to attach them. I realize this doesn't quite answer your question, but it may be a useful workaround.)
I have this code, almost unmodified from examples:
UserSearchManager usm = new UserSearchManager(conn);
Form searchForm = usm.getSearchForm("search.myserver.com");
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("Username", true);
answerForm.setAnswer("search", contact.getJid());
ReportedData data = usm.getSearchResults(answerForm, "search.myserver.com");
This works perfectly in a Desktop environment, using Smack library, but I can't get it to work in Android (where I have to use asmack).
The problem is searchForm is null because getSearchForm returns null. This seems to be pretty odd as I can't seem to find any documentation on which cases that method should return null.
The server is Openfire, if it helps.
Update 04/2014
The original answer below contains now old and outdated information. Since aSmack 0.8 it's no longer necessary to manually configure the provider manager. Calling SmackAndroid.init(Context) as the aSmack README tells you to do, takes care of all necessary initializations.
Original Answer
In the end, the problem was global to all asmack. It seems it's a known issue: the smack.providers file, usually in /META-INF folder in normal versions of smack, can't be loaded in Android because its jar packaging. So all the providers must be initialized by hand, as shown in Mike Ryan's answer in this thread: http://community.igniterealtime.org/message/201866#201866
I removed the stuff that didn't worked for me, and this is the result.
public void configure(ProviderManager pm) {
// Private Data Storage
pm.addIQProvider("query","jabber:iq:private", new PrivateDataManager.PrivateDataIQProvider());
// Time
try {
pm.addIQProvider("query","jabber:iq:time", Class.forName("org.jivesoftware.smackx.packet.Time"));
} catch (ClassNotFoundException e) {
Log.w("TestClient", "Can't load class for org.jivesoftware.smackx.packet.Time");
}
// Roster Exchange
pm.addExtensionProvider("x","jabber:x:roster", new RosterExchangeProvider());
// Message Events
pm.addExtensionProvider("x","jabber:x:event", new MessageEventProvider());
// Chat State
pm.addExtensionProvider("active","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
pm.addExtensionProvider("composing","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
pm.addExtensionProvider("paused","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
pm.addExtensionProvider("inactive","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
pm.addExtensionProvider("gone","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
// XHTML
pm.addExtensionProvider("html","http://jabber.org/protocol/xhtml-im", new XHTMLExtensionProvider());
// Group Chat Invitations
pm.addExtensionProvider("x","jabber:x:conference", new GroupChatInvitation.Provider());
// Service Discovery # Items
pm.addIQProvider("query","http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
// Service Discovery # Info
pm.addIQProvider("query","http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
// Data Forms
pm.addExtensionProvider("x","jabber:x:data", new DataFormProvider());
// MUC User
pm.addExtensionProvider("x","http://jabber.org/protocol/muc#user", new MUCUserProvider());
// MUC Admin
pm.addIQProvider("query","http://jabber.org/protocol/muc#admin", new MUCAdminProvider());
// MUC Owner
pm.addIQProvider("query","http://jabber.org/protocol/muc#owner", new MUCOwnerProvider());
// Delayed Delivery
pm.addExtensionProvider("x","jabber:x:delay", new DelayInformationProvider());
// Version
try {
pm.addIQProvider("query","jabber:iq:version", Class.forName("org.jivesoftware.smackx.packet.Version"));
} catch (ClassNotFoundException e) {
// Not sure what's happening here.
}
// VCard
pm.addIQProvider("vCard","vcard-temp", new VCardProvider());
// Offline Message Requests
pm.addIQProvider("offline","http://jabber.org/protocol/offline", new OfflineMessageRequest.Provider());
// Offline Message Indicator
pm.addExtensionProvider("offline","http://jabber.org/protocol/offline", new OfflineMessageInfo.Provider());
// Last Activity
pm.addIQProvider("query","jabber:iq:last", new LastActivity.Provider());
// User Search
pm.addIQProvider("query","jabber:iq:search", new UserSearch.Provider());
// SharedGroupsInfo
pm.addIQProvider("sharedgroup","http://www.jivesoftware.org/protocol/sharedgroup", new SharedGroupsInfo.Provider());
// JEP-33: Extended Stanza Addressing
pm.addExtensionProvider("addresses","http://jabber.org/protocol/address", new MultipleAddressesProvider());
// FileTransfer
pm.addIQProvider("si","http://jabber.org/protocol/si", new StreamInitiationProvider());
pm.addIQProvider("query","http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
// Privacy
pm.addIQProvider("query","jabber:iq:privacy", new PrivacyProvider());
pm.addIQProvider("command", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider());
pm.addExtensionProvider("malformed-action", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.MalformedActionError());
pm.addExtensionProvider("bad-locale", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadLocaleError());
pm.addExtensionProvider("bad-payload", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadPayloadError());
pm.addExtensionProvider("bad-sessionid", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadSessionIDError());
pm.addExtensionProvider("session-expired", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.SessionExpiredError());
}
I only commented a couple lines, and voilĂ . This should be called before instantiating XMPPConnection, with a line like this:
configure(ProviderManager.getInstance());
Now I'll have to deal with my other problems, but at least this one is solved :)
In the code example XmppTool.java, getSearchFrom is used in searchUsers().
public List<User> searchUsers(String serverDomain,String userName){
List<User> list = new ArrayList<User>();
UserSearchManager userSearchManager = new UserSearchManager(con);
try {
Form searchForm = userSearchManager.getSearchForm("search."+serverDomain);
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("Username", true);
answerForm.setAnswer("Name", true);
answerForm.setAnswer("search", userName);
ReportedData data = userSearchManager.getSearchResults(answerForm, "search."+serverDomain);
Iterator<Row> rows = data.getRows();
while(rows.hasNext()){
User user = new User();
Row row = rows.next();
user.setUserName(row.getValues("Username").next().toString());
user.setName(row.getValues("Name").next().toString());
SLog.i(tag, user.toString());
list.add(user);
}
} catch (XMPPException e) {
SLog.e(tag, Log.getStackTraceString(e));
}
return list;
}
You may refer to the global settings in the java file to repair your code.
The Javadoc of UserSearchManager explains as follows:
The UserSearchManager is a facade built upon Jabber Search Services (JEP-055) to allow for searching repositories on a Jabber Server. This implementation allows for transparency of implementation of searching (DataForms or No DataForms), but allows the user to simply use the DataForm model for both types of support.
XMPPConnection con = new XMPPConnection("jabber.org");
con.login("john", "doe");
UserSearchManager search = new UserSearchManager(con, "users.jabber.org");
Form searchForm = search.getSearchForm();
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("last", "DeMoro");
ReportedData data = search.getSearchResults(answerForm);
// Use Returned Data
I am trying to make a notification message appear when I click the menu item, it shows me the indicator but I don't see the message, can someone explain where i did wrong :
private MenuItem AMenu = new MenuItem("Notify", 101, 10)
{
public void run()
{
ReadableListImpl mylist= new ReadableListImpl();
ApplicationMessageFolder folder = null;
if(ApplicationMessageFolderRegistry.getInstance().getApplicationFolder(0x33c7ce29883abe5fL)==null){
folder = ApplicationMessageFolderRegistry.getInstance().registerFolder(
0x33c7ce29883abe5fL, "Test Folder", mylist );
}else {
folder = ApplicationMessageFolderRegistry.getInstance().getApplicationFolder(0x33c7ce29883abe5fL);
}
//DemoMessage source is available in the messagelistdemo.
DemoMessage msg = new DemoMessage("me#here.com", "Pizza Toppings","What would you like on your pizza?", System.currentTimeMillis());
mylist.addMessage(msg);
folder.fireElementAdded(msg,true);
System.out.println("nr of messages"+folder.hasNewMessages());
ApplicationIndicatorRegistry reg =
ApplicationIndicatorRegistry.getInstance();
EncodedImage image = EncodedImage.getEncodedImageResource("new.png" );
ApplicationIcon icon = new ApplicationIcon( image );
ApplicationIndicator indicator = reg.register( icon, false, true);
ApplicationIndicator appIndicator = reg.getApplicationIndicator();
appIndicator.setIcon(icon);
appIndicator.setValue(appIndicator.getValue() + 1);
appIndicator.setNotificationState(true);
appIndicator.setVisible(true);;
}
};
I noticed two things looking at your code:
First, you create a new ReadableListImpl each time the menu item gets invoked. This means the ReadableListImpl instance you add the message to is not always the same as the one that was used when registering the folder. So your code should work on first invocation but not on subsequent ones.
Second, with BB OS 6 a message can appear in two places, the home screen (notification bar) and the message list (the 'Messages' app). It might be possible that your message did actually show up in the message list but not in the notification bar. From my experience messages show up in the notification bar only if the message's status is ApplicationMessage.Status.UNOPENED.
Use ApplicationFolderIntegrationConfig if you want to have control over where your message should show up.