标签: android-6.0-marshmallow

如何确定应用程序是否在Android M上运行(开发者预览版)

注意:这个问题是针对Android M开发者预览而不是官方Android 6.0.

android.os.Build.VERSION.SDK_INT在Android M上返回22(22是LOLLIPOP_MR1的api级别).我们如何检查应用程序是否在Android M上运行?我有这样的想法,但显然不起作用:

public boolean isAndroidMOrHigher() {
    return android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.MNC;
}
Run Code Online (Sandbox Code Playgroud)

我为什么需要这个?例如,检查我是否需要请求权限,因为Android M有一个新的权限模型.

我能做到这一点:

public boolean isAndroidMOrHigher() {
    return "M".equalsIgnoreCase(Build.VERSION.RELEASE);
}
Run Code Online (Sandbox Code Playgroud)

但这似乎是一个黑客IMO.

真的有两个问题:

  • 最干净的方法是什么?
  • 这是一个错误还是应该是这样的?

android android-6.0-marshmallow

2
推荐指数
1
解决办法
3025
查看次数

在运行时授予WRITE_EXTERNAL_STORAGE权限时,应用程序无法访问SD卡

android M 中访问sdcard必须在运行时授予权限时强制停止并启动app,如何以编程方式实现?

但是,如果应用程序强制停止并重新启动,则可以访问sdcard.

AndroidManifest.xml:

uses-permission-sdk-m android:name="android.permission.WRITE_EXTERNAL_STORAGE


     /* **Checking permission **
        if doesn't have request
         else
         browse file directory       
    */

    String[] perm = { Manifest.permission.WRITE_EXTERNAL_STORAGE };
    if (checkSelfPermission(perm[0]) == PackageManager.PERMISSION_DENIED) {


                    requestPermissions(perm, REQ);

                } else {

                    Explore(); //method to browse file directory
                }
Run Code Online (Sandbox Code Playgroud)

onRequestPermissionsResult

   @Override
public void onRequestPermissionsResult(int requestCode,
        String[] permissions, int[] grantResults) {
    // TODO Auto-generated method stub

    if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {  

   //Not able to browse SD card until restart application


       Explore(); //method to browse file directory …
Run Code Online (Sandbox Code Playgroud)

android android-permissions android-6.0-marshmallow

2
推荐指数
1
解决办法
2688
查看次数

什么在Android M中被弃用?

我知道getResources()正在被弃用.所以在我们可以做以下事情之前:

getResources().getColor(R.color.primary_color)
getResources().getColorStateList(R.color.selector_color_list)
getResources().getDrawable(R.drawable.icon)
Run Code Online (Sandbox Code Playgroud)

我们现在必须这样做:

ContextCompat.getColor(context, R.color.primary_color)
ContextCompat.getColorStateList(getContext(), R.color.selector_color_list)
ContextCompat.getDrawable(context, R.drawable.icon)
Run Code Online (Sandbox Code Playgroud)

我知道提到了不推荐使用的HTTP类

我的问题是,在即将发布的版本中我们应该注意哪些内容已被弃用?

android android-6.0-marshmallow

2
推荐指数
1
解决办法
841
查看次数

Screenrecord在Android Marshmallow中无效

刚刚将Nexus 5设备从Android Lollipop升级到Marshmallow.我正在尝试使用Android Studio的录制功能以及使用命令行adb shell命令来录制应用程序导航.

两种方式都显示错误,即文件(需要创建的视频文件)无法访问或只读.

我无法录制任何内容.单击RECORD或按enter开始录制时出现错误.

我需要在6.0中启用任何选项吗?

命令行 :

Abhinavs-MacBook-Pro:platform-tools abhinavtyagi$ ./adb shell screenrecord /test.mp4
Unable to open '/test.mp4': Read-only file system
Run Code Online (Sandbox Code Playgroud)

Android Studio: 在此输入图像描述

android screen-recording android-studio android-6.0-marshmallow

2
推荐指数
1
解决办法
1898
查看次数

Android检查权限

我正在SDK版本23中开发我的项目,其中新引入了应用程序权限.在某些指导原则中,他们使用以下代码来读取电话状态权限是否被授予

if (ContextCompat.checkSelfPermission(serviceContext, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
    //Read Phone state
   }else{
}
Run Code Online (Sandbox Code Playgroud)

但我直接访问checkSelfPermission如下

if(serviceContext.checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
      //Read Phone state
   }else{
}
Run Code Online (Sandbox Code Playgroud)

它工作正常.我的问题是上面这些代码之间的区别是什么?.这是检查是否授予许可的正确方法?

android android-permissions android-6.0-marshmallow

2
推荐指数
1
解决办法
2万
查看次数

在Android 6.0 marshmallow中获取用户的Gmail ID

我通过使用android.permission.GET_ACCOUNTS权限获取电子邮件ID .

 try {
            Account[] accounts = AccountManager.get(this).getAccountsByType("com.google");
            for (Account account : accounts) {
                emailid = account.name;
                Log.e("account",emailid);
            }
        } catch (Exception e) {
            Log.i("Exception", "Exception:" + e);
        }
Run Code Online (Sandbox Code Playgroud)

此代码适用于Lollipop 5.1之前的所有设备.但它不适用于Marshmallow 6.0.

任何人都可以帮我解决这个问题.我甚至没有在logcat中收到任何错误.

android android-account android-6.0-marshmallow

2
推荐指数
1
解决办法
4974
查看次数

Android Marshmallow,api 23,在Cordova应用程序上打破了权限

我继承了一个Cordova混合应用程序,其清单文件中有错误.targetSdkVersion设置为24,就我而言尚不存在.

该应用未在Android 6设备上进行测试,因此上传到Play商店时出现该错误.由于Android 6上的权限模型已更改了这些设备上的应用程序崩溃.

03-12 21:10:05.991  24366-24475/? E/PluginManager? Uncaught exception from plugin
    java.lang.SecurityException: getDeviceId: Neither user 10111 nor current process has android.permission.READ_PHONE_STATE.
            at android.os.Parcel.readException(Parcel.java:1620)
            at android.os.Parcel.readException(Parcel.java:1573)
            at com.android.internal.telephony.ITelephony$Stub$Proxy.getDeviceId(ITelephony.java:4207)
            at android.telephony.TelephonyManager.getDeviceId(TelephonyManager.java:706)
            at org.pgsqlite.SQLitePlugin.getAppKey(SQLitePlugin.java:783)
            at org.pgsqlite.SQLitePlugin.executeSqlBatch(SQLitePlugin.java:347)
            at org.pgsqlite.SQLitePlugin.executeAndPossiblyThrow(SQLitePlugin.java:195)
            at org.pgsqlite.SQLitePlugin.execute(SQLitePlugin.java:93)
            at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:95)
            at org.apache.cordova.PluginManager.exec(PluginManager.java:130)
            at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59)
            at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
            at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
            at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:39)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:148)
Run Code Online (Sandbox Code Playgroud)

感谢这个博客,我发现如果我将targetSdkVersion更改为22,则应用程序的工作方式与以前一样 http://inthecheesefactory.com/blog/things-you-need-to-know-about-android-m-permission-developer-edition/EN

和文档演示了如何在运行时问权限: http://developer.android.com/intl/es/training/permissions/requesting.html

关于这个问题,我有几个问题.

  1. 如果我将targetSdkVersion降级为22(或23)并将应用程序上传到Play商店,如果我增加版本,应用会更新吗?我真的不知道会发生什么.
  2. 我应该如何使用Cordova应用程序上的Android Marshmallow权限?我是否应该要求在安装后覆盖Cordova创建的默认活动的活动?
  3. 还有其他想法可以解决这个问题吗?

这是我的manifest.xml文件.

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0" android:windowSoftInputMode="adjustResize" package="com.myorg.myapp" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" …
Run Code Online (Sandbox Code Playgroud)

permissions android cordova android-6.0-marshmallow

2
推荐指数
1
解决办法
5174
查看次数

是否可以检查是否已向其他应用授予Android 6.0+的权限?

我想检查另一个应用程序是否已被授予“危险”或“系统”级别的权限。

我尝试加载另一个应用程序的上下文并调用packageContext.checkCallingPermission(permission)。但是,文档说它返回

如果允许调用pid / uid的权限为PERMISSION_GRANTED,否则为PERMISSION_DENIED。

是否可以检查是否已授予另一个应用程序许可?

这是我的尝试(我在意识到它检查调用的pid / uid之前似乎写过它,而且似乎没有考虑上下文):

void checkAllGrantedPermissions(Context context) {
  PackageManager pm = context.getPackageManager();

  // get all installed apps with info about what permissions they requested.
  List<PackageInfo> packageInfos = pm.getInstalledPackages(PackageManager.GET_PERMISSIONS);

  // Get the hidden method PermissionInfo#protectionToString(int) so we can log info about the requested permission
  Method protectionToString;
  try {
    protectionToString = PermissionInfo.class.getDeclaredMethod("protectionToString", int.class);
    if (!protectionToString.isAccessible()) protectionToString.setAccessible(true);
  } catch (NoSuchMethodException e) {
    throw new RuntimeException(e);
  }

  // loop through all installed apps
  for (PackageInfo packageInfo : …
Run Code Online (Sandbox Code Playgroud)

android android-permissions android-6.0-marshmallow

2
推荐指数
1
解决办法
2721
查看次数

Android Recycler查看notifyItemRemoved动画切断

我目前正在为Android 6编写一个用Java编写的学校成绩经理.我刚开始使用Android,所以我不是专家.

问题:
如果我notifyItemRemoved()在我的RecycleView适配器上调用该方法并且最后一个CardView从左下角移动到右上角,则调整视图大小并剪切动画.

现在我不知道为什么该视图被调整大小,因为RecycleView的layout_height属性是match_parent.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".SemesterActivity"
    tools:showIn="@layout/activity_semester">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/subject_list_view"
        android:padding="20dp"
        android:layout_below="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"/>

</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

GridLayoutManager为RecycleView 采用了一个LayoutManager.

subjectListView.setLayoutManager(new GridLayoutManager(ActivityContext, 2));
Run Code Online (Sandbox Code Playgroud)

我如何更新RecycleView:

SubjectAdapterObj.notifyItemRemoved(viewHolder.getAdapterPosition());
Run Code Online (Sandbox Code Playgroud)

动画是默认动画.

可能GridLayoutManager是问题吗?

视频示例:

动画切断了

抱歉.英语不是我的母语.

java xml animation android android-6.0-marshmallow

2
推荐指数
1
解决办法
720
查看次数

将Centos 7连接到Android手机

我正在尝试将Centos 7操作系统连接到Moto3G Android手机(运行Android v6 - marshmallow)

已安装libmtp

Package libmtp-1.1.6-5.el7.x86_64 already installed and latest version
Nothing to do
Run Code Online (Sandbox Code Playgroud)

互联网上的大多数搜索建议使用mtp-detect但在我的情况下:

bash: mtp-detect: command not found
Run Code Online (Sandbox Code Playgroud)

我可以看到使用dmesg的手机

[ 6446.771306] usb 1-1.2: Product: XT1039
[ 6446.771309] usb 1-1.2: Manufacturer: motorola
Run Code Online (Sandbox Code Playgroud)

我安装了jmtpfs(使用yum),它给了我以下内容

jmtpfs
No mtp devices found.
Run Code Online (Sandbox Code Playgroud)

我尝试使用GO 安装go-mtpfs,但得到以下内容

$ ./gopath/bin/go-mtpfs bob &
[1] 21633
$ 2017/05/03 13:06:18 detect failed: no MTP devices found

[1]+  Exit 1                  ./gopath/bin/go-mtpfs bob
Run Code Online (Sandbox Code Playgroud)

如果有人对此进展有任何意见或建议,我将不胜感激.

mtp centos7 android-6.0-marshmallow

2
推荐指数
1
解决办法
7467
查看次数