Android PrintService display toast - android

I have an android PrintService launched by an Application.
I would like to be able to display toasts from the PrintService when I'm selecting the printer on which to print etc. (UI generated by the android system, picture here).
On Android <11 it works fine, however for 11+, I'm not able to display a toast...
I've tried several code (Kotlin) :
Toast.makeText(<context>, message, Toast.LENGTH_LONG).show()
Handler(Looper.getMainLooper()).post {
Toast.makeText(context.applicationContext, message, Toast.LENGTH_LONG).show()
}
Where I tried the following values of :
this (the PrintService)
this.applicationContext
this.baseContext
Still, I'm never able to display a toast on the printer selection page...
Is it possible ? What is wrong in my code ?

Related

PIXEL API 30 device not support toast error messages?

I have a problem with a piece of code in my application. I am using Android Studio and as a device to view the application I use PIXEL API 30. Now the problem is that the devide PIXEL API 30 does not show error messages to the user. for example I have the following fragment that does a check on a user's name:
public class Fragment_user{
public boolean checkname(String name){
if(name.length() == 0) {
Toast.makeText(getContext(), "user add", Toast.LENGTH_SHORT).show();
return false;
}else return true;
}
}
now if I don't enter name I want to show the user a toast error message but toast doesn't work with the PIXEL API 30 device. why? Did I get the code wrong or does the PIXEL API 30 device not support toast error messages?
note: I don't want to use setError
Some times system launcher get's crash idk why!, So try to close your emulator and restart it with using Cold boot now function. I also faced that error so i fixed it with using like that.

How to run a built-in call app when a device gets incoming call in onCallAdded(InCallService) function?

When a phone is ringing ( by an incoming call) If the phone number is a specific number I want to show my custom UI. If It is not, I want to pass it to the (built-in) system call app(Or any other call app is okay).
I should use 'InCallService' and the device set my app as 'a default call app' so that even when the phone screen is locked my custom-UI-activity be shown. The following kotlin source code is my goal.
override fun onCallAdded(call: Call) {
//app should receive a new incoming call via 'onCallAdded'
super.onCallAdded(call)
val phoneNumber = getPhoneNumber(call)
if (isMyTargetNumber(phoneNumber)) {
//show my custom UI
} else {
//run a built-in call app
}
}
The problem that I want to solve is how to run a built-in call app appropriately. I mean I want to complete to wirte the blank of 'else'
else {
//run a built-in call app
}
Apps on the android market like 'truecaller' or 'whosecall' works well the way I want to acheive. I want to make my app such apps. Please help me and advise something to me.

displaying runtime errors in android/ios installed app

I've been trying to get errors to display in a text field within the app for ease of error reporting from users.
I've had some success using this code I found on stackoverflow. It's used at the top level of the app but it's not working on device:
//start code
this.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, errorHandler);
function globalErrorHandler(event:UncaughtErrorEvent):void
{
var message:String;
//check for runtime error
if (event.error is Error)
message = (event.error as Error).getStackTrace();
//handle other errors
else if (event.error is ErrorEvent)
message = (event.error as ErrorEvent).text;
else
message = event.error.toString();
//do something with message (eg display it in textfield)
myTextfield.text = message;
}
//end code
At first this wouldn't work on the device and I thought it was because upon the error, when developing on the pc, flashplayer would display the actionscript popup with the error. Which you would need to click "dismiss all" or close and then the globalErrorHandler was called after and then the error written to the textfield. I thought this is what was keeping it from showing up on the device. However, by adding event.preventDefault() I was able to suppress the actionscript popup when developing on the desktop and the error was written to the textfield successfully. This was not the case however on the andriod device. It still just hangs on the error. It's as if the default error event cannot be suppressed on android.
Thanks for your time. Any help appreciated!
EDIT 22/09/2017: I was able to see the error on device finally. It had to do with while on desktop publishing the error would be shown. However, on device the behavior was different and something was covering the textfield, by bring it to the front on error I was able to see it. However, I still see that some errors deeper in the class hierarchy are not being caught.
In our project we have it simpler (and it is working):
stage.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);
private function onUncaughtError(e:UncaughtErrorEvent):void
{
// Console is basically a TextField for debug/diagnosis output.
if (e.error) Console.error(e.error.getStackTrace());
e.preventDefault();
}
The other thing you should probably check is whether your TextField actually displays any text at all for there might be text embedding issues, unrelated to the error handling routine.
UPD: Loading SWFs so it doesn't mix with the parent.
var request:URLRequest = new URLRequest(path);
var context:LoaderContext = new LoaderContext;
context.applicationDomain = ApplicationDomain.currentDomain;
var loader:Loader = new Loader;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
loader.load(request, context);

Android Toast prevents my devices to sleep

I use Toast to indicate my app's state. And I use the following code in order to control toast showing time.
Toast noCardDetectedToast=null;
void setVisibilityNoCardDetectedToast(boolean visible)
{
if(visible)
{
if(noCardDetectedToast==null)
noCardDetectedToast = Toast.makeText(this, R.string.msg_no_card_detected, Toast.LENGTH_SHORT);
noCardDetectedToast.show();
}
else
{
if(noCardDetectedToast!=null)
{
noCardDetectedToast.cancel();
noCardDetectedToast=null;
}
}
}
When it's necessary to show this Toast, the application starts invoking setVisibilityNoCardDetectedToast(true) several times per second.
And when the application doesn't need this toast any more, it invokes setVisibilityNoCardDetectedToast(false).
Everything works fine, but my android device does not fall asleep, as long as the toast is visible.(I tested my application on Android 4.x and 5.0)
This behaviour looks strange for me. What do I do wrong here?

Cannot get LogCat to work

I'm trying to use logCat.
I have the following code that gets executed
Log.i("MyLog", "Test to see if it works");
But the Logcat on eclipse only shows
All messages (no filters)
Is there a setting or something in eclipse?
In the Logcat menu there is a Green plus above the All messages (no filters)
Either use "MyLog" at the Log Tag input-field to only see your log that is tagged with "MyLog",
or use your applications namespace (like com.example.your_app) at the by Application Name to show all logs of your application without the spam you got with all messages of Eclipse and the Emulator. (This does still include the dalvikvm that increases the heap size, Choreographer which warns you when you do too much work on the Main Thread, and similar app-related logs though.)
Add a filter (the green plus) with by Log Tag:MyLog and by Log Level:info.
You have to create a filter manually with that tag from the Log.i in the LogCat view. You can use the + icon next to the Saved filters label

Categories

Resources