谷歌似乎最终关闭了获取当前前台应用程序包的所有大门.
在Lollipop更新之后,getRunningTasks(int maxNum)由于这个答案,我使用此代码从Lollipop获取前台应用程序包:
final int PROCESS_STATE_TOP = 2;
RunningAppProcessInfo currentInfo = null;
Field field = null;
try {
field = RunningAppProcessInfo.class.getDeclaredField("processState");
} catch (Exception ignored) {
}
ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> appList = am.getRunningAppProcesses();
for (RunningAppProcessInfo app : appList) {
if (app.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND &&
app.importanceReasonCode == 0 ) {
Integer state = null;
try {
state = field.getInt( app );
} catch (Exception ignored) {
}
if (state != null && state == …Run Code Online (Sandbox Code Playgroud) 在Android Marshmallow中,应在运行时在需要时请求权限,而不是在安装应用程序时立即请求权限.但是,我似乎只能从Activity请求权限,这是一个问题,因为我的应用程序只包含服务.(为什么会这样,你可能会问?该应用程序内部捆绑了一个Android Wear手表,所有手机都会查看附近的照片以发送到手表 - 无需任何活动.但它确实需要位置权限.)
那么,有没有办法从服务请求权限?或者以某种方式强制在安装时授予权限,就像过去一样?
如前所述这里,Android的M将不支持的Apache HTTP API.文档声明:
请改用HttpURLConnection类.
要么
要继续使用Apache HTTP API,必须首先在build.gradle文件中声明以下编译时依赖项:
android {useLibrary'org.apache.http.legacy'}
我已经将我项目的大部分HttpClient用法转换为HttpURLConnection,但是,我仍然需要在一些领域使用HttpClient.因此,我试图将'org.apache.http.legacy'声明为编译时依赖项,但在build.gradle中出现错误:
找不到Gradle DSL方法:'useLibrary()'
我的问题是:如何在项目中将'org.apache.http.legacy'声明为编译时依赖项?
任何帮助深表感谢.谢谢
apache android httpclient build.gradle android-6.0-marshmallow
我正在使用新的Android Marshmallow SDK,方法FloatMath.sqrt()已经消失.我现在该怎么用?
我在Marshmallow上尝试AppCompat.我希望有一个透明的状态栏,但它会变成白色.我已经尝试了几个解决方案,但它们对我不起作用(透明状态栏不能使用windowTranslucentNavigation ="false",Lollipop:绘制后面的statusBar,其颜色设置为透明).这是相关的代码.
我的styles.xml
<style name="Bacon" parent="Theme.Bacon"/>
<style name="Theme.Bacon" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/theme_primary</item>
<item name="colorPrimaryDark">@color/theme_primary_dark</item>
<item name="colorAccent">@color/theme_accent</item>
<item name="windowActionBar">false</item>
<item name="windowActionBarOverlay">true</item>
<item name="windowNoTitle">true</item>
<item name="android:windowBackground">@color/background_material_light</item>
</style>
<style name="Theme.Bacon.Detail" parent="Bacon"/>
Run Code Online (Sandbox Code Playgroud)
V21
<style name="Bacon" parent="Theme.Bacon">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
<style name="Theme.Bacon.Detail" parent="Bacon">
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
活动
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
分段
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="192dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginBottom="32dp"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed" …Run Code Online (Sandbox Code Playgroud) android android-appcompat android-support-library androiddesignsupport android-6.0-marshmallow
升级到Android版本6.0后,只有在设备上启用了位置服务时,蓝牙低功耗(BLE)扫描才有效.请参阅此处以供参考:Android 6.0上的蓝牙低功耗startScan无法找到设备
基本上,您需要为应用程序以及手机启用权限.这是一个错误吗?是否可以在没有实际启用位置服务的情况下扫描?我不想拥有所有应用的位置.
编辑
我没有提到我正在使用该startScan()方法BluetoothLeScanner API 21提供.我可以使用此方法所需的清单中的课程和良好的位置权限.我只是不希望我的应用程序的用户必须在他们的设备(GPS等)上启用位置服务才能使用我的应用程序.
以前,该startScan()方法将在手机上禁用位置服务的情况下运行并返回结果.但是,在Marshmallow上,相同的应用程序将"扫描"但是静默失败并且在手机上未启用位置服务且课程/精确位置权限仍在清单中时未返回任何结果.
android bluetooth bluetooth-lowenergy android-6.0-marshmallow
我在Nexus 6上安装了Android Marshmallow.我正在尝试解决以下问题:
如果用户在显示通知时尝试授予权限,则会显示"检测到屏幕覆盖"消息,并且"请求权限"对话框消失 - 当然,应用程序未获得所请求的权限.(查看截图)
我尝试通过添加"DRAW OVER OTHER APPS"权限来解决问题 - android.permission.SYSTEM_ALERT_WINDOW到清单但没有运气.
PS:我确定问题是由通知引起的.我没有安装任何覆盖其他应用程序的应用程序,我甚至在设置中使用"Draw over other apps"权限关闭了所有应用程序.没有帮助..
有人知道这个问题的解决方案吗?
当我在Android M Preview 3上有一个23的目标API时,我似乎无法获得Manifest.permission.WRITE_SETTTINGS权限.
requestPermissions(new String[]{Manifest.permission.WRITE_SETTINGS},
101);
Run Code Online (Sandbox Code Playgroud)
请求权限不会显示我期望的对话框,但如果我未经此许可进行以下调用,
RingtoneManager.setActualDefaultRingtoneUri(activity, RingtoneManager.TYPE_RINGTONE, ringUri);
Run Code Online (Sandbox Code Playgroud)
电话会议除外,因为我没有这个权限.
我不知道从哪里开始.23有新的铃声API吗?或者这个权限更改只是让任何非系统应用程序无法更改铃声?
在Android Marshmallow上,Google完全取消了对Apache HTTP客户端的支持(链接在这里),因为与替代方案相比,它没有良好的性能.
这可能也是Android Marshmallow上如此多应用程序崩溃的原因.
通过将此行添加到gradle文件,Google允许您仍然使用此API,而不是内置的API:
useLibrary 'org.apache.http.legacy'
Run Code Online (Sandbox Code Playgroud)
所以,这就是我做的:
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
Run Code Online (Sandbox Code Playgroud)
和:
android {
compileSdkVersion 'android-MNC'
buildToolsVersion "23.0.0 rc3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example.user.androidmtest"
minSdkVersion 'MNC'
targetSdkVersion 'MNC'
versionCode 1
versionName "1.0"
}
Run Code Online (Sandbox Code Playgroud)
当我尝试它时,它编译得很好(没有显示错误,我可以运行概念验证应用程序,因为它没有任何特殊代码),但当我尝试使用我知道的一些类时是旧API的一部分(如"HttpClient"类),我看到它不允许我这样做.
我知道不建议使用此解决方案,但我们必须让应用程序准备好至少暂时在那里工作,直到我们100%完成Android Marshmallow应该改变的所有事情,我们不希望出现意外情况.崩溃的形式.
这是一个截图:
它为什么会发生?我使用得当吗?
编辑:这里报告了这个问题:
Facebook,Evernote,Pocket - 所有应用程序都会自动在Android 6.0上获得此权限,即使它们的目标是23(targetSdkVersion=23).
关于新的Marshmallow权限模型有很多文档.其中一个SYSTEM_ALERT_WINDOW被"提升"为"高于危险"的权限级别,因此需要特殊的用户干预才能授予应用程序这些权限.如果应用程序有targetSdkVersion22或更低,app会自动获得此权限(如果在清单中请求).
但是,我注意到一些获得此权限的应用程序,无需将用户发送到设置特殊页面的Draw over other apps权限.我看到Facebook,Evernote,Pocket - 也许还有更多.
任何人都知道在没有用户通过的情况下如何授予应用程序此权限Settings -> Apps -> Draw over other apps?
谢谢
android android-permissions target-sdk system-alert-window android-6.0-marshmallow
android ×10
apache ×1
bluetooth ×1
build.gradle ×1
httpclient ×1
java ×1
permissions ×1
target-sdk ×1
wear-os ×1