禁用通知还会禁用该应用程序的吐司消息 [英] Disabling notification also disables toast messages of the app
问题描述
在我的android应用程序中,我已经实现了推送通知.如果我禁用了该应用程序的通知消息,即使Toast消息被禁用,我的问题也出在我的设备上.这是常见现象还是我需要进行任何更改?请让我知道我该如何克服这个问题.
In my android app , I have implemented push notification.My problem is from my device if I disable notification messages for the app, even the toast messages get disabled. Is this a usual phenomenon or do I need to change anything ? Please let me know how can I overcome this.
推荐答案
是的,这是常见现象.单击在这里,但是它是中文.希望可以为您提供帮助.
Yes,it's a usual phenomenon.Click here but it's in Chinese.Hope this can help you.
在这种情况下,需要自己编写一个Toast.我可以提供一个演示,但它并不完整.您可以进行一些修改以使其更好.
In such case,it is need to write a Toast by your self.I can provide a demo but it is not complete.You can do some modification to make it better.
public class MToast {
private Context mContext;
private WindowManager wm;
private int mDuration;
private View mNextView;
public static final int LENGTH_SHORT = 1500;
public static final int LENGTH_LONG = 3000;
public MToast(Context context) {
mContext = context.getApplicationContext();
wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
}
public static MToast makeText(Context context, CharSequence text,
int duration) {
MToast result = new MToast(context);
LayoutInflater inflate = (LayoutInflater) context
.getApplicationContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
View v = inflate.inflate(R.layout.dialog_toast,null);
TextView tv = (TextView) v.findViewById(R.id.tvMsg);
tv.setText(text);
result.mNextView = v;
result.mDuration = duration;
return result;
}
public static MToast makeText(Context context, int resId, int duration)
throws Resources.NotFoundException {
return makeText(context, context.getResources().getText(resId), duration);
}
public void show() {
if (mNextView != null) {
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.gravity = Gravity.CENTER | Gravity.CENTER_HORIZONTAL;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
params.format = PixelFormat.TRANSLUCENT;
params.y = dip2px(mContext, 64);
params.type = WindowManager.LayoutParams.TYPE_TOAST;
wm.addView(mNextView, params);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (mNextView != null) {
wm.removeView(mNextView);
mNextView = null;
wm = null;
}
}
}, mDuration);
}
}
/**
* transfer dp into px
*
* @param context
* @param dipValue
* @return int
*/
private int dip2px(Context context, float dipValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dipValue * scale + 0.5f);
}
}
这是布局文件.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/waiting_bg"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/tvMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="15sp"
android:textColor="@color/mColor_white"
/>
我是markdown的新手,很抱歉.
I am new at markdown.Sorry for the format.
这篇关于禁用通知还会禁用该应用程序的吐司消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!