Skip to main content

Posts

Showing posts from 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
De-obfuscate the stack trace using Proguard GUI  Store the Proguard mapping.txt file for each released APK, which will be useful to de-obfuscate crash or exception stack trace. Steps to retrace :- 1. Go to your SDK location -> Android_SDK\adt-bundle-windows-x86-20131030\sdk\tools\proguard\bin folder 2. Run retrace.bat file , choose "Retrace" option. 3. Add your proper mapping.txt 4. And paste the dumped stack trace , stack trace should be from "at" on each line 5. Proguard will replace all method and class names according to the mapping file.

Launching Android application from web browser

Steps to follow :- 1. Define an activity in android manifest file with below intent filters :-    <activity             android:name=".LaunchActivityFromBrowser"             android:configChanges="orientation|keyboardHidden|fontScale|locale|layoutDirection|screenSize|screenLayout|mnc|mcc|navigation"             android:launchMode="singleTask"             android:screenOrientation="portrait"             android:theme="@android:style/Theme.Black.NoTitleBar" >             <intent-filter>                <action android:name="android.intent.action.VIEW" />                 <category android:name="android.intent.category.DEFAULT" />                  <action android:name="customAction" />                 <category android:name="android.intent.category.BROWSABLE" />             </intent-filter>         </activity> adding CATEGORY_BROWSABLE