Suppressing toast from package in Android - android

I'm developing an Android app and I'm trying to show some information with a Toast.
I used Toasts in other projects and everything works, but in this app, when the Toast should appear, it doesn't do it and Logcat shows the next message:
Suppressing toast from package com.xxxxxxx by user request.
I'm creating the toast with the next code:
Context context = xxxxxxx.this;
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
I tried to set the context with getApplicationContext() and getBaseContext() too, but doesn't work.
Anyone knows how to solve this problem?
Thank you very much.

Go to the App-Info Screen of your application ( long click on the app and drag it to the top in Android 4.0) and make sure the "Show notification" checkbox is selected. Otherwise your Toasts will be suppressed.

Related

How to hide toast message from TalkBack for some reason

For accessibility demo purpose, I’m creating android example app.
By the way, during creating bad example accessibility, I have a question about toast issue. By default, every time toast is showing, TalkBack read the toast and it is very good.
But sometimes I want to hide toast from TalkBack so that TalkBack won’t read the toast message. Of course TalkBack must read all toast messages in order to give same information with none screen reader users. But sometimes in some apps, too many toast messages are appeared on screen and even the same message is stayed on screen.
So in that case TalkBack says too much and even TalkBack won’t read the toast, blind users can read the message that toasted through swiping.
Also the toast message is not alert text. So in some cases, I think hiding toast from TalkBack is needed.
But I don’t know how to do this. I set one view in java and added toast message. And then I set importantForAccessibility to NO, but it doesn’t work.
My code is below.
Lastly, I referred as the stack that customizing TalkBack toast.
Thank you.
imgClick2 = (ImageView)findViewById(R.id.imageView2);
imgClick2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast toast = new Toast(MainActivity.this);
TextView messageView = new TextView(MainActivity.this);
messageView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
messageView.setText("visible text");
toast.setView(messageView);
toast.show();
}
});

Image icon within Toast maketext message

I am beginning learning some android mobile development and have created a notepad app through some tutorials and am now wanting to customise it a little.
I currently have a Toast maketext message that displays when a user saves a new note. The code is as follows:
if(Utilities.saveNote(this, new Note(mNoteCreationTime, title, content)))
Toast.makeText(this, "Swag Note has been saved", Toast.LENGTH_SHORT).show();
What I am wanting to do is add a small icon at both ends of this toast message.
Is there a relatively simple way of achieving this?
Toasts cannot have icons. You can create a custom Toast with ImageViews in it (example). However, there might be an unicode symbol that suits your purpose: in that case, you can just paste it.
Edit:
To make the linked example work, you'd just have to add a View for the image with id "toast_image", which will be invoked this way:
ImageView image = (ImageView) layout.findViewById(R.id.toast_image);
Show Toast as you do it now:
Toast.makeText(this, "Swag Note has been saved", Toast.LENGTH_SHORT).show();
Show MyToast from linked example:
MyToast.show(this, "Swag Note has been saved", false);

Android avoid closing Toast when click on it

This is how i show my Toast message.
Toast.makeText(getActivity(), "This is my Toast message!",Toast.LENGTH_LONG).show();
When i click on Toast it will disappear.
How can I avoid sudden disappear of Toast when i click on it.
Toast doesn't disappear for sudden clicks . , it will disappear on with duration u set
I suggest you to use Snackbar.
Snackbar has LENGTH_INDEFINITE attribute on the duration so I think it is pretty much what you wanted.
Toasts doesn't close on interactions it depends on the duration you set which are
LENGTH_SHORT and LENGTH_LONG are 0 and 1. If you want something that stays longer use actionbar notifications
Andorid Toast can be used to display information for the short period of time. A toast contains message to be displayed quickly and disappears after sometime.
You can also create custom toast as well
//Creating the LayoutInflater instance
LayoutInflater li = getLayoutInflater();
//Getting the View object as defined in the customtoast.xml file
View layout = li.inflate(R.layout.customtoast,
(ViewGroup) findViewById(R.id.custom_toast_layout));
//Creating the Toast object
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setView(layout);//setting the view of custom toast layout
toast.show();
OR ..
Toast toast=Toast.makeText(getApplicationContext(),"Hello Javatpoint",Toast.LENGTH_SHORT);
toast.setMargin(50,50);
toast.show();
You can use the for loops for duration

Android Toast moves around on screen

My android app displays several Toast messages. I recently installed it on a Galaxy S6, running Android 5.1.1 and noticed that the messages are displayed initially around the center of the screen, then they move to proper position (near bottom, if no Gravity is specified), then back to the initial position before fading away.
Context context = getApplicationContext();
String newMsg = getString(R.string.wild_card_msg);
Toast mToast = Toast.makeText(context, newMsg, Toast.LENGTH_LONG);
mToast.setGravity(Gravity.CENTER, 0, 0);
mToast.show();
Update:
I have upgraded support libraries as well as set compile-sdk and target sdk to the latest API. That did not fix the issue
I have removed all .setGravity() calls. No change.
I have noticed that Toast messages behave properly at the first execution after installation (be it in USB debug mode or via download from PlayStore), but the issue reoccurs at (all) subsequent runs.
I have also discovered that my Toast messages disappear immediately if I touch the screen (anywhere). I thought Toast displays cannot be influenced by user interaction.
Anyone else having this issue, know how to fix it or know a workaround?
Please note that I have accepted Nick's answer, proposing snackBar as a workaround.
Your question asked for a fix or workaround. The simplest workaround is (in my opinion) also the best option, because it moves you to using the more modern components: Switch to a snackbar.
Simple Snackbar:
//on a fragment you can simply use getView(), otherwise give it the root view of your
//layout so that the snackbar can use it to find context
Snackbar.make(getView(), "The toast text", Snackbar.LENGTH_SHORT).show();
It's in the support design library for compatibility.
This is a snackbar:
And some of the support / design libraries that can be included in gradle are
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
It is because of the customized version of Android that vendors deploy with their products, It is true for Activity animations too,
You can achieve the desired behavior on all devices by extending the Toast class and providing your own animation and style or using an open source library for showing toast messages, for activities setting a custom animation for activities creates a constant animation on all devices.
try this simple Toast
Toast.makeText(getApplicationContext(),"Your message", Toast.LENGTH_SHORT).show();

Animating a toast in android?

Am trying to animate my toast but have been unsuccessful so far. This is what I have in my onCreate():
ImageView image = new ImageView(this);
image.setImageResource(R.drawable.icon);
Animation move = new TranslateAnimation(0,100, 0, 100);
move.setDuration(2000);
move.setFillEnabled(true);
move.setFillAfter(true);
image.startAnimation(move);
Toast toast = new Toast(this);
toast.setView(image);
toast.show();
Have tried placing startAnimation() after displaying the toast, but that doesn't work either.
Toast notifications use a system template to determine how they are displayed. Short of modifying the Android source code, you can not create a special animation for your Toast message.
However, if possible you might be able to create a normal view and use that instead. One common method is to create a new Activity that has a transparent background with your modal toast message animated and displayed however you want.

Categories

Resources