Posts

Showing posts with the label Android 6.0 Marshmallow

Android Notification SetSound Is Not Working

Answer : below code will help you: String CHANNEL_ID="1234"; Uri soundUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://"+ getApplicationContext().getPackageName() + "/" + R.raw.mysound); NotificationManager mNotificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE); //For API 26+ you need to put some additional code like below: NotificationChannel mChannel; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { mChannel = new NotificationChannel(CHANNEL_ID, Utils.CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH); mChannel.setLightColor(Color.GRAY); mChannel.enableLights(true); mChannel.setDescription(Utils.CHANNEL_SIREN_DESCRIPTION); AudioAttributes audioAttributes = new AudioAttributes.Builder() .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATIO...

Android M Light And Dark Status Bar Programmatically - How To Make It Dark Again?

Answer : The solution posted by @Aracem is valid but, doesn't work if you try change also the background color of the status bar. In my case I do it in the following way. To enable windowLightStatusBar(programatically,inside a Utils class for example): public static void setLightStatusBar(View view,Activity activity){ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { int flags = view.getSystemUiVisibility(); flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; view.setSystemUiVisibility(flags); activity.getWindow().setStatusBarColor(Color.WHITE); } } To restore to StatusBar to the previous state: public static void clearLightStatusBar(Activity activity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Window window = activity.getWindow(); window.setStatusBarColor(ContextCompat .getColor(activity,R.color.colorPrimaryDa...

Android M Camera Intent + Permission Bug?

Answer : I had the same issue and find this doc from google: https://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE "Note: if you app targets M and above and declares as using the CAMERA permission which is not granted, then atempting to use this action will result in a SecurityException." This is really weird. Don't make sense at all. The app declares Camera permission using intent with action IMAGE_CAPTURE just run into SecurityException. But if your app doesn't declare Camera permission using intent with action IMAGE_CAPTURE can launch Camera app without issue. The workaround would be check is the app has camera permission included in the manifest, if it's , request camera permission before launching intent. Here is the way to check if the permission is included in the manifest, doesn't matter the permission is granted or not. public boolean hasPermissionInManifest(Context context, String permissionName)...