我已经授予了其他应用程序的显示权限,但仍然获得"Unable to add window android.view.ViewRootImpl$W@8ab9bbf -- permission denied for window type 2010"
注意事项:如果将目标sdk更改为21,则应用正常运行,这意味着可能存在权限相关问题。
代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TelephonyManager telephonyManager = (TelephonyManager) getSystemService("phone");
this.db = new Database(this);
Cursor res = this.db.getData();
Cursor res2 = this.db.backUpGetData();
int totalResults = res.getCount();
int totalResultsBack = res2.getCount();
if ((totalResults == 0 && totalResultsBack == 0) || ((totalResults == 0 && totalResultsBack != 0) || (totalResults != 0 && totalResultsBack == 0))) {
finish();
}
LayoutParams localLayoutParams = new LayoutParams(2010, 4719904, -2);
this.winManager = (WindowManager) getApplicationContext().getSystemService("window");
this.wrapperView = new RelativeLayout(getBaseContext());
getWindow().setAttributes(localLayoutParams);
View.inflate(this, R.layout.activity_lock_screen, this.wrapperView);
this.buttonGifImage = (GifImageButton) this.wrapperView.findViewById(R.id.imagebuton);
this.buttonGifImage.setVisibility(0);
((GifDrawable) this.buttonGifImage.getDrawable()).stop();
this.textToSpeech = new TextToSpeech(this, this);
this.keywordField = (TextView) this.wrapperView.findViewById(R.id.unlockfiled);
this.keywordField.setVisibility(0);
this.switchToPincode = (ImageButton) this.wrapperView.findViewById(R.id.switchToPinCode);
this.switchToPincode.setVisibility(0);
this.switchPin = (TextView) this.wrapperView.findViewById(R.id.switchPin);
this.switchPin.setVisibility(0);
this.enterBackPassword = (EditText) this.wrapperView.findViewById(R.id.enterPassword);
this.enterBackPassword.setVisibility(8);
this.b1 = (Button) this.wrapperView.findViewById(R.id.n1);
this.b1.setVisibility(8);
this.b2 = (Button) this.wrapperView.findViewById(R.id.n2);
this.b2.setVisibility(8);
this.b3 = (Button) this.wrapperView.findViewById(R.id.n3);
this.b3.setVisibility(8);
this.b4 = (Button) this.wrapperView.findViewById(R.id.n4);
this.b4.setVisibility(8);
this.b5 = (Button) this.wrapperView.findViewById(R.id.n5);
this.b5.setVisibility(8);
this.b6 = (Button) this.wrapperView.findViewById(R.id.n6);
this.b6.setVisibility(8);
this.b7 = (Button) this.wrapperView.findViewById(R.id.n7);
this.b7.setVisibility(8);
this.b8 = (Button) this.wrapperView.findViewById(R.id.n8);
this.b8.setVisibility(8);
this.b9 = (Button) this.wrapperView.findViewById(R.id.n9);
this.b9.setVisibility(8);
this.b_Del = (Button) this.wrapperView.findViewById(R.id.del);
this.b_Del.setVisibility(8);
this.b0 = (Button) this.wrapperView.findViewById(R.id.n0);
this.b0.setVisibility(8);
this.b_OK = (Button) this.wrapperView.findViewById(R.id.okay);
this.b_OK.setVisibility(8);
this.imageLock = (ImageView) this.wrapperView.findViewById(R.id.lockImage);
this.imageLock.setVisibility(8);
this.enterPwd = (TextView) this.wrapperView.findViewById(R.id.enterPwd);
this.enterPwd.setVisibility(8);
this.speech = SpeechRecognizer.createSpeechRecognizer(this);
this.speech.setRecognitionListener(new listener());
makeFullScreen();
DateFormat dateFormat = new SimpleDateFormat("hh \nmm");
DateFormat datCurrent = new SimpleDateFormat("dd MMM,\n EEE");
String localTime = dateFormat.format(new Date());
String localDate = datCurrent.format(new Date());
this.timeCount = (TextView) this.wrapperView.findViewById(R.id.Date);
this.timeCount.setVisibility(0);
this.timeCount.setText(localTime);
this.view = this.wrapperView.findViewById(R.id.View06);
this.view.setVisibility(0);
this.currentDate = (TextView) this.wrapperView.findViewById(R.id.currentDate);
this.currentDate.setVisibility(0);
this.currentDate.setText(localDate);
this.touchOnMic = (TextView) this.wrapperView.findViewById(R.id.touchOnMic);
this.touchOnMic.setVisibility(0);
this.touchOnMic.setText("Tap on mic to speak voice password");
this.wrapperView.setFocusableInTouchMode(true);
this.wrapperView.requestFocus();
this.wrapperView.setOnKeyListener(new C01861());
switchPinCode();
this.backGroundPics = MainActivity.backgroundPics;
if (this.backGroundPics == 0) {
this.wrapperView.setBackgroundResource(R.drawable.hfull1);
} else if (this.backGroundPics == R.drawable.hfull1) {
this.wrapperView.setBackgroundResource(R.drawable.hfull1);
} else if (this.backGroundPics == R.drawable.hfull2) {
this.wrapperView.setBackgroundResource(R.drawable.hfull2);
} else if (this.backGroundPics == R.drawable.hfull3) {
this.wrapperView.setBackgroundResource(R.drawable.hfull3);
} else if (this.backGroundPics == R.drawable.hfull4) {
this.wrapperView.setBackgroundResource(R.drawable.hfull4);
} else if (this.backGroundPics == R.drawable.hfull5) {
this.wrapperView.setBackgroundResource(R.drawable.hfull5);
}
this.winManager.addView(this.wrapperView, localLayoutParams);
telephonyManager.listen(new C01872(), 32);
}
我反编译了应用https://play.google.com/store/apps/details?id=com.lock.admin.screenlock
此应用在最新的android版本中运行完全正常。