I am using default android printer option (android version 4.4)
I want to byPass printManager adapter popup. how to hide the popup and give a direct print to the printer in android
you cannot extend PrintManager class. It is a final class .Please check below link
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4.4_r1/android/print/PrintManager.java
These guys have designed their own printing framework.Where they are designing their own dialog.Have a look
http://apf.isb-vietnam.com/index.php/programming-with-apf.html
It seems to me like the answer is yes.
Here is the print() method from Android's PrintManager class:
public PrintJob print(String printJobName, PrintDocumentAdapter documentAdapter, PrintAttributes attributes)
{
if (mService == null)
{
Log.w(LOG_TAG, "Feature android.software.print not available");
return null;
}
if (!(mContext instanceof Activity))
{
throw new IllegalStateException("Can print only from an activity");
}
if (TextUtils.isEmpty(printJobName))
{
throw new IllegalArgumentException("printJobName cannot be empty");
}
if (documentAdapter == null)
{
throw new IllegalArgumentException("documentAdapter cannot be null");
}
PrintDocumentAdapterDelegate delegate = new PrintDocumentAdapterDelegate((Activity) mContext, documentAdapter);
try
{
Bundle result = mService.print(printJobName, delegate, attributes, mContext.getPackageName(), mAppId, mUserId);
if (result != null)
{
PrintJobInfo printJob = result.getParcelable(EXTRA_PRINT_JOB);
IntentSender intent = result.getParcelable(EXTRA_PRINT_DIALOG_INTENT);
if (printJob == null || intent == null)
{
return null;
}
try
{
mContext.startIntentSender(intent, null, 0, 0, 0);
return new PrintJob(printJob, this);
}
catch (SendIntentException sie)
{
Log.e(LOG_TAG, "Couldn't start print job config activity.", sie);
}
}
}
catch (RemoteException re)
{
Log.e(LOG_TAG, "Error creating a print job", re);
}
return null;
}
Simply create your own class (I will pretend it is named MyPrintManager) which extends PrintManager and #Override the print() method in it. Then, use the code above, but remove this line:
mContext.startIntentSender(intent, null, 0, 0, 0);
Then, get an instance of the MyPrintManager class using the code below:
MyPrintManager printManager = (MyPrintManager) appContext.getSystemService(Context.PRINT_SERVICE);
You could try this, though I am not sure if it works, because I haven't tested it. Please reply with the result, and I will try to help you further if it didn't work.
Related
I have trouble getting data here from database there isn't data,
Data is not displayed outside of the method.
Could you please help me?
List<Person> Refresh() {
Person p = new Person();
ParseQuery <ParseObject> query = ParseQuery.getQuery(NAME_DATABASE);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList , ParseException e) {
if (e == null) {
for (int i = 0; i < scoreList.size(); i++){
p.setId(scoreList.get(i).getInt(Key.ID));
p.setName(scoreList.get(i).getString(Key.NAME));
p.setAge(scoreList.get(i).getString(Key.AGE)); p.setDate_start(scoreList.get(i).getString(Key.DATE_START));
p.setMonth_number(scoreList.get(i).getString(Key.MONTH_NUMBER));
p.setPropriety(scoreList.get(i).getString(Key.PROPRIETY));
p.setPrice(scoreList.get(i).getString(Key.PRICE));
p.setGender(scoreList.get(i).getString(Key.GENDER));
persons.add(p); //there is find data
}
}
else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
return persons; //here there isn't data (size=0)
}
The answer is simple really. You are returning persons outside the findInBackground() method.
else{
Log.d("score", "Error: " + e.getMessage());
}
//Return here after the else statement
return persons;
}
Note : you might want to make persons a global variable or else android studio will tell you to declare it as a final variable.
I'm using Appium for Android
the following works for clicking on the element
driver.findElement(By.xpath("//*[#resource-id='com.app.android:id/prelogin_signup']")).click();
But I am trying to check if an element is on the screen and I tried the following
if (driver.findElement(By.xpath("//*[#resource-id='com.app.android:id/prelogin_signup']")).isDisplayed()) {
System.out.println("FOUND");
} else {
System.out.println("NOT FOUND!");
}
but it returns an Exception saying
INFO: HTTP Status: '405' -> incorrect JSON status mapping for 'unknown error' (500 expected)
org.openqa.selenium.WebDriverException: Method is not implemented
How can I check to see if an element is on the screen?
You can try this, hope it helps
//If the element found, do as you want
if (driver.findElements(By.xpath("//*[#resource-id='com.app.android:id/prelogin_signup']")).size() > 0) {
System.out.println("FOUND");
} else {
System.out.println("NOT FOUND!");
}
you can surround your code with try catch block.
public boolean isElementDisplayed(){
try{
return driver.findElement(By.xpath("//*[#resource-id='com.app.android:id/prelogin_signup']")).isDisplayed();
}catch(Exception e){
//System.out.println(e);
return false;
}
}
you can also make the generic function to check if element is displayed.
public boolean isElementDisplayed(MobileElement element){
try{
return element.isDisplayed();
}catch(Exception e){
//System.out.println(e);
return false;
}
}
You may also try isDisplayed().
if (demoPage.proceedButton().isDisplayed() == true) {
System.out.println("BUTTON FOUND*****");
TestUtil.click(cartPage.proceedButton(), 10);
} else {
System.out.println("PROCEED BUTTON NOT FOUND!*********");
}
Note - I am using Page Factory model. Hence, demoPage.proceedButton() is used, you may use your locator in place of this declaration.
I wrote my own custom error handler for the UI in Vaadin flow. But when I throw the exception my view crash and not show my human readable error message.
I did this in other application using Vaadin 8 and works perfectly. The idea its throw a SgiException in my backend services like:
Product not found
Incorrect value for field "XXX"
Not available stock for the product.
etc.
And then show a system notification
public static void setDefaultErrorHandler(ErrorEvent errorEvent) {
Throwable t = DefaultErrorHandler.findRelevantThrowable(errorEvent.getThrowable());
String message;
if (t != null) {
message = t.getMessage();
} else {
message = "";
}
log.error(message, t);
SgiException sgiException = getCauseOfType(t, SgiException.class);
if (sgiException != null) {
NotificationBuilder.exception(sgiException.getCode(), sgiException.getMessage());
return;
} else {
NotificationBuilder.exception(UNKNOW_ERROR, (message == null ? "" : message));
return;
}
}
private static <T extends Throwable> T getCauseOfType(Throwable th, Class<T> type) {
while (th != null) {
if (type.isAssignableFrom(th.getClass())) {
return (T) th;
} else {
th = th.getCause();
}
}
return null;
}
And this is how I set the custom error handler:
#PostConstruct
public void configBaseView() {
VaadinSession.getCurrent().setErrorHandler(Util::setDefaultErrorHandler);
}
In the view show this:
Note:
Debugging the application, seeing the code it's running, looks the method its called for some reason not show the notification.
This is a nasty behaviour that can't currently be overridden in Vaadin 10. Follow and vote (thumb up or comment) this issue to get it solved: https://github.com/vaadin/flow/issues/801
How do I check if the Internet connection is ON or OFF on a device?
You better check using
CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_DIRECT);
The CoverageInfo class provides some more types of coverage to check for. See http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/system/CoverageInfo.html
I think there is no direct way.
You just request for a server,if there is there is no internet not avilable at that time an exception is thrown, you catch it display an alert to the user.
Some thing like below:
try {
// request http
}
catch(IOException e) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.alert("No Internet Connectivity");
//System.exit(0);
}
});
System.out.println(e);
}
Call this method, if it returns true then you've got connection. It checks to ensure you have enough battery for internet connection, your 3G or wireless is turned on and then you have enough signal.
public synchronized static boolean checkConnection() {
boolean returnVal = true;
if (DeviceInfo.getBatteryLevel() < 6) {
returnVal = false;
}
else if (RadioInfo.getState() == RadioInfo.STATE_OFF) {
returnVal = false;
}
else if (RadioInfo.getSignalLevel() == RadioInfo.LEVEL_NO_COVERAGE) {
returnVal = false;
}
return returnVal;
}
Here's what I use in my application, and it works just fine:
protected static boolean isOutOfServiceRange() {
return !RadioInfo.isDataServiceOperational();
}
I am new to BlackBerry application development and trying to make a simple application to turn my flash light on as a torch. I know there are several applications that do this already, but I would like to try do it on my own.
I have installed eclipse and all the necesary add on to get my development environment running. I have also successfully create the stock standard hello world application.
I am however struggling to find out how to do this. I have been reading through the API documentation and started playing with FlashControl, VideoControl and SnapshotControl.
These however don't seem to expose methods to do this.
I know through the video camera I am able to go to options and turn the flash light on and this is exactly what i'm trying to mimic.
The code i have used so far which seems to just set the camera flash to force on is:
Player p = javax.microedition.media.Manager.createPlayer("capture://video");
p.realize();
p.start();
FlashControl flashControl = (FlashControl) p.getControl("javax.microedition.amms.control.camera.FlashControl");
flashControl.setMode(FlashControl.FORCE);
the problem relevant to the flash control has been resolved by me
as per i am using the flash control on my recent application on
camera.
Here is the code which i used :
public Camera(int j)
{
k = j;
try
{
Player player = Manager.createPlayer("capture://video");
player.realize();
_videoControl = (VideoControl) player.getControl("VideoControl");
flashControl = new FlashControl()
{
public void setMode(int mode)
{
// TODO Auto-generated method stub
}
public boolean isFlashReady()
{
// TODO Auto-generated method stub
return false;
}
public int[] getSupportedModes()
{
// TODO Auto-generated method stub
return null;
}
public int getMode()
{
// TODO Auto-generated method stub
return 0;
}
};
flashControl = (FlashControl) player
.getControl("javax.microedition.amms.control.camera.FlashControl");
try {
if (k == 1)
{
flashControl.setMode(FlashControl.AUTO);
Dialog.alert("slect Auto");
}
else if (k == 2)
{
flashControl.setMode(FlashControl.OFF);
Dialog.alert("slect No");
}
}
catch (Exception e)
{
System.out.println(e);
}
if (_videoControl != null)
{
_videoField = (Field) _videoControl.initDisplayMode(
VideoControl.USE_GUI_PRIMITIVE,
"net.rim.device.api.ui.Field");
// _videoControl.setDisplaySize(330, 420);
// _videoControl.setDisplayLocation(getContentWidth(),
// getContentHeight());
_videoControl.setVisible(true);
add(_videoField);
capture = new ButtonField("Capture", Field.FIELD_HCENTER);
capture.setChangeListener(this);
add(capture);
player.start();
}
}
catch (Exception e)
{
System.out.println(e);
}
}
this logic has been implemented simultaneously with Pinkesh as my colleage
in the comapny
The FlashControl class, available from OS 5.0 allows you to turn the flash on. Just set a flash control on your player with the FORCE flag:
FlashControl flash = (FlashControl)player.getControl("javax.microedition.amms.control.camera.FlashControl");
if(flash!=null) {
try {
flash.setMode(FlashControl.FORCE);
} catch(IllegalArgumentException iae){}
}
For this to work, you'll probably need to open a player to record video or take a picture. I'm not showing that in my code for the sake of brevity, but here you can read a tutorial. If your app is only about turning on the flash, you'd probably like to have the video field hidden.
Try something like this
LED.setState(LED.STATE_ON); // for LED
Backlight.enable(true); // for Screen
this.setMode(FlashControl.ON); // for flash light.
or else import this package
package lsphone.flash.microfireps;