Android开发笔记#3

ERROR:

Unable to ad d window android.view.ViewRoot$W@44da9bc0 — permission denied for this window type

原因:API等级过高 (level 23)

@ceph3us do you know how to achieve it for >=M? ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SYSTEM_ALERT_WINDOW}…”

  1. SYSTEM_ALERT_WINDOW PERMISSION on API >= 23 (Draw over other apps etc):
    • no longer appears in App’s Permissions screen.
    • it doesn’t even appear in the strangely confusing new “All permissions” screen
  2. Calling Activity.requestPermissions() with this permission,
    • will not show any dialog for the user to Allow/Deny.
    • instead, the Activity.onRequestPermissionsResult() callback will be called immediately with a denied flag.

暂未使用文中方法,选择在低版本API中运行。

 

Android开发笔记#2

ERROR: You need to use a Theme.AppCompat theme (or descendant) with this activity

环境:虚拟机 API 23 AppCompatActivity

答案1:

The reason you are having this problem is because the activity you are trying to apply the dialog theme to is extending ActionBarActivity which requires the AppCompat theme to be applied.

Change the Java inheritance from ActionBarActivity to Activity and leave the dialog theme in the manifest as it is.

问题:不同在于,这个alertdialog 是在广播接收对象中直接创建的,并没有直接继承ActionBarActivity,而是继承AppCompatDialog;

答案2:

All you need to do is add android:theme="@style/Theme.AppCompat.Light" to your application tag in the AndroidManifest.xml file.

问题:实际上,mainfest文件中的theme本身就是继承自Appcompat;

最后没办法,选择使用旧版本android.app.AlertDialog

而非android.support.v7.app.AlertDialog;

解决。(同时需要解决#3的问题)