Articles of android 7.0 nougat

Android 7.0和7.1 getApplication()ClassCastException

在Developer Console中,我看到很多像这样的堆栈跟踪崩溃 java.lang.RuntimeException: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045) at android.app.ActivityThread.-wrap14(ActivityThread.java:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6776) at java.lang.reflect.Method.invoke(Native Method:0) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) Caused by: java.lang.ClassCastException: at com.myapp.ui.BaseActivity.getApp(BaseActivity.java:193) at com.myapp.ui.BaseActivity.onCreate(BaseActivity.java:275) at com.myapp.ui.CastActivity.onCreate(CastActivity.java:39) at com.myapp.ui.MainActivity.onCreate(MainActivity.java:268) at android.app.Activity.performCreate(Activity.java:6955) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927) BaseActivity的getApp方法是 public App getApp() { return (App) getApplication(); } App类是 public class App extends […]

无法在Android api> = 24上使用java.lang.IllegalArgumentException恢复活动

我的应用程序在运行版本7.1.1和8.0.0设备上发生崩溃,并带有以下堆栈跟踪: Fatal Exception: java.lang.RuntimeException: Unable to resume activity {xxx/xxx.views.activities.HomeActivity}: java.lang.IllegalArgumentException at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3788) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3828) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2991) at android.app.ActivityThread.-wrap14(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6692) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358) Caused by java.lang.IllegalArgumentException at android.os.Parcel.readException(Parcel.java:1697) at android.os.Parcel.readException(Parcel.java:1646) at android.app.ActivityManagerProxy.isTopOfTask(ActivityManagerNative.java:6600) at android.app.Activity.isTopOfTask(Activity.java:6142) at android.app.Activity.onResume(Activity.java:1331) at android.support.v4.app.FragmentActivity.onResume(FragmentActivity.java:485) at xxx.views.activities.BaseActivity.onResume(BaseActivity.java:50) at xxx.views.activities.HomeActivity.onResume(HomeActivity.java:364) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1277) at android.app.Activity.performResume(Activity.java:7058) […]

AlertDialog上缺少按钮| Android 7.0(Nexus 5x)

我正在尝试创建一个AlertDialog但按钮没有显示。 只在Android 7.0中看到此问题: final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(“This app needs location access”); builder.setMessage(“Please grant location access so this app can detect beacons.”); builder.setPositiveButton(android.R.string.ok, null); builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override @TargetApi(Build.VERSION_CODES.M) public void onDismiss(final DialogInterface dialog) { requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_COARSE_LOCATION); } }); builder.show();

在Android 7.0和Samsung设备上使用Dagger 2运行RuntimeException

在我的Google Play控制台上,自从我开始使用Dagger 2以来,我看到了很多崩溃报告,但仅限于Android 7.0,主要是三星设备,一些Huawai和Motorola设备以及一些罕见的Xperia设备: java.lang.RuntimeException: at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2984) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3045) at android.app.ActivityThread.-wrap14 (ActivityThread.java) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1642) at android.os.Handler.dispatchMessage (Handler.java:102) at android.os.Looper.loop (Looper.java:154) at android.app.ActivityThread.main (ActivityThread.java:6776) at java.lang.reflect.Method.invoke (Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1518) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1408) Caused by: java.lang.RuntimeException: at dagger.android.AndroidInjection.inject (AndroidInjection.java:48) at dagger.android.support.DaggerAppCompatActivity.onCreate (DaggerAppCompatActivity.java:43) at com.package.MainActivity.onCreate (MainActivity.java:83) at android.app.Activity.performCreate (Activity.java:6956) at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1126) at android.app.ActivityThread.performLaunchActivity […]

在Android 7(API级别24)中,我的应用程序不允许静音手机(将铃声模式设置为静音)

我有一个应用程序通过使用AudioManager将手机静音并使用此代码将铃声模式设置为静音: AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); try { audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT) } catch (Exception e) { e.printStackTrace(); } 这适用于Android 6,但现在使用Android 7,我收到以下错误: System.err: java.lang.SecurityException: Not allowed to change Do Not Disturb state System.err: at android.os.Parcel.readException(Parcel.java:1683) System.err: at android.os.Parcel.readException(Parcel.java:1636) System.err: at android.media.IAudioService$Stub$Proxy.setRingerModeExternal(IAudioService.java:962) System.err: at android.media.AudioManager.setRingerMode(AudioManager.java:1022) System.err: at controllers.SearchResultController.mutePhone(SearchResultController.java:185) 有什么新的权限我需要要求才能使这项工作? 我查看了Android权限列表,但找不到任何相似的内容。

Notification.bigContentView在API 24(牛轧糖)中被弃用了。

我刚刚从API 23升级编译SDK版本到API 24,似乎不赞成Notification.bigContentView 。 所以问题什么是API 24中的等效方法设置Android API 24(牛轧糖)bigContentView?

datepicker对话框不能swick旋转在Android 7.0设备上

在Android N之前,我可以使用下面的代码实例一个spnnier模式的spnnier datepicker dialog : new DatePickerDialog(getContext(), AlertDialog.THEME_HOLO_LIGHT, null, 2016, 9, 18); 但上面的代码是不是在Android N设备上工作,它总是显示calander mode ,在Android N有什么不同? 我怎样才能实例spinner模式datepicker dialog ?

禁用Android N的多窗口function不适用于某个活动

我想在我的应用程序中禁用多窗口支持。 我已经在我的Manifest中将resizeableActivity设置为false,但是当我长按最近的应用程序图标时,应用程序仍然以多窗口模式进入。 以下是我的清单: <activity android:name=".MainActivity" android:resizeableActivity="false" android:excludeFromRecents="true" android:icon="@drawable/ic_launcher_home" android:theme="@style/AppThemeV3.CustomToolbar"> </activity> 每个文档 : android:resizeableActivity=["true" | "false"] 如果该属性设置为false,则该活动不支持多窗口模式。 如果此值为false,并且用户尝试以多窗口模式启动活动,则活动将占用整个屏幕。 我也尝试在清单中的应用程序级别将此属性设置为false,但它仍以多窗口模式启动。 任何指针,我在做什么错将高度赞赏?

在Android Nougat拍摄照片后,BitmapFactory无法解码来自Uri的位图

我试图拍照,然后使用照片。 这是我做的。 我的设备是Nexus 6P(Android 7.1.1) 。 首先,我创build了一个Uri : Uri mPicPath = UriUtil.fromFile(this, UriUtil.createTmpFileForPic()); //Uri mPicPath = UriUtil.fromFile(this, UriUtil.createFileForPic()); 然后,我开始Intent : Intent intent = ActivityUtils.getTakePicIntent(mPicPath); if (intent.resolveActivity(getPackageManager()) != null) { startActivityForResult(intent, RequestCode.TAKE_PIC); } 最后,我在onActivityResult上处理了这个Uri : if (requestCode == RequestCode.TAKE_PIC) { if (resultCode == RESULT_OK && mPicPath != null) { Bitmap requireBitmap = BitmapFactory.decodeFile(mPicPath.getPath()); //path is like […]

Android插孔工具链不能识别stream中的java.util.function.Predicate

我正在尝试更新我的现有项目以支持Java 8.我有一个使用Java 8stream的依赖项。 return map == null || map.keySet().stream().allMatch(key -> !key.contains(".")); 当我尝试运行应用程序时出现以下错误: Error:ValidKeysValidator.java:17: Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.util.function.Predicate com.android.jack.api.v01.CompilationException at com.android.jack.api.v01.impl.Api01ConfigImpl$Api01CompilationTaskImpl.run(Api01ConfigImpl.java:113) at com.android.builder.core.AndroidBuilder.convertByteCodeUsingJackApis(AndroidBuilder.java:1852) at com.android.builder.core.AndroidBuilder.convertByteCodeUsingJack(AndroidBuilder.java:1679) at com.android.builder.internal.compiler.JackConversionCache.convertLibrary(JackConversionCache.java:99) at com.android.build.gradle.tasks.JackPreDexTransform.runJack(JackPreDexTransform.java:174) at com.android.build.gradle.tasks.JackPreDexTransform.transform(JackPreDexTransform.java:119) at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:178) at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:174) at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:156) at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:173) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) […]