Tuesday, November 5, 2019

Unknown failure (at android.os.Binder.execTransact(Binder.java:674)) Error while Installing APKs



I had this issue when I was trying to run the android application from android studio.

Unknown failure (at android.os.Binder.execTransact(Binder.java:674))
Error while Installing APKs


This issue occurs because of android's Instant run feature. You need to disable this feature to overcome this issue.

To disable Instant Run:


  1. Open the Settings or Preferences dialog. (For Mac, Android Studio -> Preferences)
  2. Navigate to Build, Execution, Deployment > Instant Run.
  3. Uncheck the box next to Enable Instant Run.


Saturday, November 2, 2019

Python AttributeError: 'module' object has no attribute 'strptime'

This type of error occurs when the strptime method called on module instead of class:

If your import statement is like below :

import datetime
Then you need to access strptime method like below:
datetime.datetime.strptime(date, "%Y-%m-%d")
to access the strptime method. Or, you could change the import statement to this:
from datetime import datetime
and access it as you are.
The people who made the datetime module also named their class datetime:
#module  class    method
datetime.datetime.strptime(date, "%Y-%m-%d")
Ref: https://stackoverflow.com/questions/19480028/attributeerror-datetime-module-has-no-attribute-strptime

Wednesday, January 3, 2018

Android Open Phone Dialer from Code


There are Two ways to achieve it.

 1) Have to start the dialer via code, without user interaction. 

 You need Action_Dial, use below code it will open Dialer with number specified.

Intent intent = new Intent(Intent.ACTION_DIAL); 
intent.setData(Uri.parse("tel:0123456789")); 
startActivity(intent);

The 'tel:' prefix is required, otherwhise the following exception will be thrown:

java.lang.IllegalStateException: Could not execute method of the activity. Action_Dial doesn't require any permission. If you want to initiate the call directly without user's interaction , You can use action Intent.ACTION_CALL.

In this case, you must add the following permission in your AndroidManifest.xml:

<uses-permission android:name="android.permission.CALL_PHONE">
</uses-permission>

2) Have user to click on Phone_Number string and start the call. 

android:autoLink="phone" 

You need to use TextView with below property.
android:autoLink="phone" android:linksClickable="true"

This is how you can open EditText label assigned number on dialer directly.
<TextView
 android:id="@+id/phoneNumber"
 android:autoLink="phone"
 android:linksClickable="true"
 android:text="+91 22 2222 2222"
 />
Ref: https://stackoverflow.com/questions/11699819/how-do-i-get-the-dialer-to-open-with-phone-number-displayed

Saturday, December 23, 2017

Apply Border color to button on Android


Use the <stroke> element. Add this xml file in res/drawable folder as button_border.xml:



<?xml version="1.0" encoding="utf-8"?>
  <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="#FFFFFF" 
       android:endColor="#00FF00"
       android:angle="270" />
    <corners android:radius="3dp" />
    <stroke android:width="5px" android:color="#ffffff" />
 </shape>

then call this by in layout file

 
<Button
   android:id="@+id/button1"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_margin="10dp"
   android:background="@drawable/button_border"
   android:text="Button" 
/>

Forcing “portrait” orientation mode for android application

Adding following code segment in AndroidManifest file for each activity, we can force the android application to work only in portrait mode.

Note: Don't apply the orientation to the application element, instead you should apply the attribute to the activity element, and you must also set configChanges as noted below.


<activity
   android:screenOrientation="portrait"
   android:configChanges="orientation|keyboardHidden">
</activity>

Monday, December 18, 2017

Java Interview Question: HashSet vs HashMap

HashSet

  1. HashSet class implements the Set interface
  2. In HashSet, we store objects(elements or values) e.g. If we have a HashSet of string elements then it could depict a set of HashSet elements: {“Hello”, “Hi”, “Bye”, “Run”}
  3. HashSet does not allow duplicate elements that mean you can not store duplicate values in HashSet.
  4. HashSet permits to have a single null value.
  5. HashSet is not synchronized which means they are not suitable for thread-safe operations until unless synchronized explicitly. 

HashMap


  1. HashMap class implements the Map interface
  2. HashMap is used for storing key & value pairs. In short, it maintains the mapping of key & value (The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.) This is how you could represent HashMap elements if it has integer key and value of String type: e.g. {1->”Hello”, 2->”Hi”, 3->”Bye”, 4->”Run”}
  3. HashMap does not allow duplicate keys however it allows having duplicate values.
  4. HashMap permits single null key and any number of null values.
  5. HashMap is not synchronized which means they are not suitable for thread-safe operations until unless synchronized explicitly. 

Friday, December 15, 2017

How to handle HTTP Header related issue in Apache


By following below steps you can suppress following HTTP Header related security issues in web applications those are hosted in apache web server.
  • Web Browser XSS Protection Not Enabled
  • X-Frame option Header not set
  • X-Content-Type-Options header missing  
  • Incomplete or No Cache-control and Pragma HTTP Header Set


These issues can be handled by placing following lines in httpd.conf of apache web server.

Header set X-XSS-Protection “1; mode=block”
Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
Header always append X-Frame-Options DENY
Header set X-Content-Type-Options nosniff
Header set Content-Security-Policy "default-src 'self';"



For this mod_hedaers module also need to be enabled. so uncomment the following Load Module line:

LoadModule headers_module modules/mod_headers.so


Now doing security audit test again, you can see these issues are handled properly.