I have Pax A920 which runs with android .
So how to using printing service in java?
I suggest you to use the Neptune api. you can google pax 920 neptune api demo and the fist link that shows up (https://docs.hips.com/docs/pax-a920) contains a demo that shows all the basic functions (including the printer) and you can run it on your device:
In the Application you first need a function to retrieve the IDAL:
public static IDAL getDal() {
if(dal == null){ //dal is a private static IDAL variable of the application
try {
dal = NeptuneLiteUser.getInstance().getDal(context);
} catch (Exception e) {}
}
return dal;
}
then in your activity you can just do the following:
try {
IPrinter printer= MyApp.getDal().getPrinter();
printer.init();
printer.printStr("Your text",null);
printer.start();
} catch (PrinterDevException e) {
e.printStackTrace();
}
Related
I am working on a project right now where I use jsoup in a class with the function retrieveMedia in order to return an ArrayList filled with data from the webpage. I run it in a thread since you shouldn't be connecting to URLs from the main thread. I run it and join it. However, it doesn't work (I tested the same code in Eclipse separate from Android Studio and it worked fine). It seems that no matter what I do I can't get jsoup to connect to the webpage. Below is my class MediaRetriever.
public class MediaRetreiever {
public ArrayList<Media> retrieveMedia() {
ArrayList<Media> mediaOutput = new ArrayList<Media>(); //Store each scraped post
Thread downloadThread = new Thread(new Runnable() {
public void run() {
Document doc = null;
try {
doc = Jsoup.connect(<Website Im connecting to>).timeout(20000).get();
} catch (IOException e) {
System.out.println("Failed to connect to webpage.");
mediaOutput.add(new Media("Failed to connect", "oops", "", "oh well"));
return;
}
Elements mediaFeed = doc.getElementById("main").getElementsByClass("node");
for (Element e : mediaFeed) {
String title, author, imageUrl, content;
title=e.getElementsByClass("title").text().trim();
author=e.getElementsByClass("content").tagName("p").select("em").text().trim();
content=e.getElementsByClass("content").text().replace(author,"").trim();
Media media = new Media(title, author, "", content);
mediaOutput.add(media);
}
}
});
downloadThread.start();
try {
downloadThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
return mediaOutput;
}
}
Running this class's method from another class and it doesn't ever connect. Any ideas?
Since you say that the problem persists only in Android, it looks like that you should add the user agent string to your request - first get the user agent string of a browser that displays correctly the site, and then add it to the request:
doc = Jsoup.connect(<Website Im connecting to>)
.userAgent("your-user-agent-string")
.timeout(20000).get();
And as a sidenote - if you are catching exception, don't print your own error message - print the original message, it may be very useful.
I want to develop an application who can send direct messages look this:
public static void sendDirectMessage(Long recipientId, String message){
System.out.print("[Bot] Sending message to #"+recipientId+"... ");
try {
twitter.sendDirectMessage(recipientId, message);
System.out.println("done");
} catch (TwitterException e) {
System.out.println("fail");
e.printStackTrace();
System.err.println("[Error] "+e.getErrorMessage());
}
}
I call to this statement with:
private static String
customer_key = "",
Oth_key = "",
access_token = "",
access_key = "";
private static TwitterBot bot;
public static void main(String[] args) {
try {
bot = new TwitterBot(customer_key, Oth_key, access_token, access_key);
} catch (TwitterException e) {
e.printStackTrace();
} catch (InterruptedException e) {
System.err.println("[Err] "+e.getMessage());
}
bot.sendDirectMessage(bot.getUserData("AbA2L1").getId(), "Message test:!");
}
it's return error:
404:The URI requested is invalid or the resource requested, such as a user, does not exists. Also returned when the requested format is not supported by the requested method.
message - Sorry, that page does not exist.
code - 34
Note:
The functions search(), getHomeTimeline() and updateStatus() works.
I have activated Read, Write and Direct messages on twitter application permissions.
sorry for my bad english.
It's work with this vertion, add it into pom.xml file:
<dependencies>
<!-- https://mvnrepository.com/artifact/org.twitter4j/twitter4j-core -->
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>4.0.7</version>
</dependency>
</dependencies>
Good luck.
Which version of Twitter4J are you using? The new Direct Message API is only a few weeks old so you may need a new version.
Use Twitter4j-core-4.0.7 version for Direct Message Functionality of Twitter.
Other Version of Twitter4j Library shows TwitterException of User Not Found or Page Does not exist.
I am doing web service now, and already succeed installing SOAP in my web service..
It is working perfectly when i "run as java application".. (I use eclipse as my environment)
Here is my client method:
public static void main(String[] args) {
LogbookSOAPServiceLocator locator = new LogbookSOAPServiceLocator();
try {
LogbookSOAP logbookSOAP = locator.getLogbookSOAPPort();
System.out.println(logbookSOAP.fetchLog("21").getDriverName());
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
This succesfully work in console, can i use it anywhre in my user interface? like .jsp file?
Thanks!
Sure you can. At first you need to install web container to deploy your application. Then create web project. Step by step tutorial by Oracle based on Oracle WebLogic Server but you can use other one.
The simpliest way to using JSP Scriptlets and put all our logic in JSP page.
<%#page import="your imports here"%>
........
<%
LogbookSOAPServiceLocator locator = new LogbookSOAPServiceLocator();
try {
LogbookSOAP logbookSOAP = locator.getLogbookSOAPPort();
System.out.println(logbookSOAP.fetchLog("21").getDriverName());
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
%>
But it is not really good way because as your know best practice is to avod code logic in JSP pages especially Scriptets JSP coding conventions. Better code it in java wrapper class which you can call from JSP and after executing it will return result to the page.
I'm trying to integrate InMobi into my unity game to show ads. I made a jar library and call needed method via JNI in unity but getting the following error:
Android Java Exception: java.lang.NoClassDefFoundError‏
My method is static because unity doesn't do Call() for me, so I can do only CallStatic().
public static void ShowInMobi(final Context context)
{
//com.google.ads.mediation.inmobi.InMobiAdapter.disableHardwareAcceleration();
//((Activity) context).runOnUiThread(new Runnable() {
// public void run() {
String CLASS_TO_LOAD ="com.inmobi.commons.InMobi";
try
{
Class<?> newClass = Class.forName(CLASS_TO_LOAD);
System.out.println("Class "+newClass+" found successfully!");
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
System.out.println("Class "+CLASS_TO_LOAD+" not found!");
}
catch (Throwable any)
{
System.out.println("Unexpected error! "+any);
}
if(interstitialInMobi==null)
{
com.inmobi.commons.InMobi.initialize((Activity) context, "my_ad_unit_id");
interstitialInMobi = new IMInterstitial((Activity) context, "my_ad_unit_id");
interstitialInMobi.loadInterstitial();
}
else
{
if (interstitialInMobi.getState() == IMInterstitial.State.READY){
interstitialInMobi.show();
interstitialInMobi.loadInterstitial();
}
}
//}
//});
Sohan from InMobi here
Looks like you are trying to use the native SDK directly in Unity. InMobi has a Unity plugin that you can use instead. The plugin acts as the mediator between the native SDK and your app.
You can check this link for further integration details.
I want to be able to launch native and J2ME applications through my application using the content handler API (JSR 211) on a Nokia 6212.
At the moment, I am unable to do so, as it always states that there is "No Content Handler Found" and throws a javax.microedition.content.ContentHandlerException.
At the moment, I am trying to get the phone to launch its browser and go to a certain website, just to test that I can use the framework. I have tried many different Invocation objects:
//throw exceptions
new Invocation("http://www.somesite.com/index.html",
"application/internet-shortcut");
new Invocation("http://www.google.co.uk","text/html");
// a long shot, I know
new Invocation("http://www.somesite.com/text.txt","text/plain");
// massive long shot
new Invocation("http://www.google.co.uk","application/browser");
//appears to download the link and content (and definitely does in the Nokia
// emulator) and then throws an exception
new Invocation("http://www.google.co.uk");
new Invocation("http://www.somesite.com/index.html");
Below is the code that I have been using, please bear in mind the parameters often changed to generate the different Invocation objects.
/*
* Invokes an application using the Content Handler API
*/
public void doInvoke(String url, String mime, String payload){
Registry register = Registry.getRegistry(this.getClass().getName());
Invocation invoke = new Invocation(url, mime, null, false,
ContentHandler.ACTION_OPEN);
boolean mustQuit = false;
try {
mustQuit = register.invoke(invoke);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (ContentHandlerException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if(mustQuit){
this.quit();
}
}
Try this:
Registry register = Registry.getRegistry(this.getClass().getName());
You must call Registry.getRegistry for the MIDlet inheritor. Just use your MIDlet for getting the class name.