Skip to main content

Posts

Showing posts from October, 2016

Android Notification Manager - Creating Ongoing Notifications with Action buttons

// Cancel older notification with same id, NotificationManager notificationMgr = ( NotificationManager ) context . getSystemService ( Context . NOTIFICATION_SERVICE ); notificationMgr . cancel ( CALL_NOTIFY_ID ); // any constant value // Create Pending Intent, Intent notificationIntent = null ; PendingIntent contentIntent = null ; notificationIntent = new Intent ( context , YourActivityName ); contentIntent = PendingIntent . getActivity ( context , 0 , notificationIntent , PendingIntent . FLAG_UPDATE_CURRENT ); // Notification builder builder = new NotificationCompat . Builder ( context ); builder . setContentText ( "Ongoing Notification.." ); builder . setContentTitle ( "ongoing notification sample" ); builder . setSmallIcon ( R . drawable . notification_icon ); builder . setUsesChronometer ( true ); builder . setDefaults ( Notification . DEFAULT_LIGHTS ); builder . setContentIntent ( contentIntent ); bu

Adding Chat Heads in Android

Adding Chat Heads in Android // Get window Manager object, WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); // Initialize floating icon, ImageView chatHead = new ImageView(mContext); chatHead.setImageResource(R.drawable.chatHeadIcon);  //chat head Icon WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |       WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, PixelFormat.TRANSLUCENT); // Set the position on the screen, params.gravity = Gravity.TOP | Gravity.RIGHT; params.x = 0; params.y = 100; windowManager.addView(chatHead, params);

Whitelist an android application on android 6.0/Marshmallow

Whitelist wont disable doze mode for your app, however can use network and hold wake lock. Whitelist an android application through code, boolean isIgnoringBatteryOptimizations = pm.isIgnoringBatteryOptimizations(getPackageName()); if(!isIgnoringBatteryOptimizations){   Intent intent = new Intent();   intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);   intent.setData(Uri.parse("package:" + getPackageName()));   startActivityForResult(intent, MY_IGNORE_OPTIMIZATION_REQUEST);   }                             Check for the result, @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {     if (requestCode == MY_IGNORE_OPTIMIZATION_REQUEST) {          PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);          boolean isIgnoringBatteryOptimizations = pm.isIgnoringBatteryOptimizations(getPackageName());          if(isIgnoringBatteryOptimizations){             // Ignoring battery opti

Granting SYSTEM_ALERT_WINDOW on Android 6.0/Marshmallow

From android 6.0 this permission needs to grant dynamically, <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> Throwing below permission denied error on 6.0, Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@86fb55b -- permission denied for this window type Solution :- Requesting Overlay permission as below, if(!Settings.canDrawOverlays(this)){ // ask for setting Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); startActivityForResult(intent, REQUEST_OVERLAY_PERMISSION); } Check for the result, @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {     if (requestCode == REQUEST_OVERLAY_PERMISSION) {         if (Settings.canDrawOverlays(this)) {             // permission granted...         }else{             // permission not granted... }     } }

Useful ADB commands for Android developers

Useful  ADB commands for every android developer  :) 1. Clear the user data for your app using package name      adb shell pm clear <package> 2. Take screen shot :-     adb shell screencap /pathTofile/scr.png 3. Record the screen display    adb shell screenrecord /pathTofile/recordFilenName.mp4 4. WiFi On/off     Turn on the wifi:-      adb shell svc wifi enable    Turn off the wifi:-      adb shell svc wifi disable 5. Generate boot completed broadcast to test application behavior after reboot      adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c             android.intent.category.HOME -n my.app.name/myapp.BootListener 6. I nstall/ Re-install application      adb install path/app.apk     adb install -r path/app.apk     adb uninstall path/app.apk 7. Print your application info such as version num, name etc ...      adb shell dumpsys package <my.package.name> 8. Logcat with thread Id      adb logcat -v threadtime 9