0
我在来的AsyncTask的方法onProgressUpdate创建警报对话框,我已经在把权限来体现:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
应用程序时显示警告对话框我收到此异常:
android.view.WindowManager$BadTokenException: Unable to add window [email protected] -- permission denied for this window type
代码是:
@Override
protected void onProgressUpdate(Object[] values) {
this.holder.itemView.setBackgroundColor(Color.WHITE);
if(messaggio){
// Toast.makeText(context, testoMessaggio, Toast.LENGTH_SHORT).show();
final AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle(nameFile);
alertDialog.setMessage(testoMessaggio);
alertDialog.setCancelable(true);
alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//alertDialog.cancel();
}
});
alertDialog.show();
}
super.onProgressUpdate(values);
}
为什么我有这个例外?
如果我删除此:
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//alertDialog.cancel();
}
});
它的工作原理是为什么?
onProgressUpdate我已经尝试建立通知,但它不工作:
@Override
protected void onProgressUpdate(Object[] values) {
this.holder.itemView.setBackgroundColor(Color.WHITE);
if(messaggio){
PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(context, EUDroid_Main_Activity.class), 0);
Notification notification = new NotificationCompat.Builder(context)
.setTicker("Ticker")
.setContentTitle("Title")
.setContentText("Hello")
.setContentIntent(pi)
.setAutoCancel(true)
.build();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, notification);
}
super.onProgressUpdate(values);
}
为什么呢?
检查此问题http://stackoverflow.com/questions/32224452/android-unable-to-add-window-permission-denied-for-this-window-type – Raghavendra
我已尝试通知(查找),但不'为什么? – Fra87