Wednesday, 27 December 2017

FireChat

The quick answer, YES, Firebase is the best and safest option for the majority of cases users will need it. Is FireChat the best chat API to use for chat? Maybe but I wouldn’t recommend any of those APIs.
I work for a bespoke app development company which specialises in instant chat, we use Firebase for many of our projects. Below I will put some of the advantages and disadvantages of FireChat, then I will add some additional points of the best implementation I see when using chat.
NOTE: Other services will include many of the same advantages and disadvantages, this answer will be trying to show that Firebase is better overall based on its strengths. I disagree that the other services you have mentioned are useless. In my experience they have all been excellent (great developers, documentation etc) but Firebase is exceptional.
Advantages of FireChat
  • Cost: As you mention in your question Firebase is great for starting developers. You can get a good level of users on your app before needing to start paying for the service. This level has been set well to mean that once you start paying you have enough users to be monetising your app.
  • Support: Firebase offer great support and also have a huge community to offer support for them. Due to the size and scale of their company Firebase is widely used. This means if you have problems there is a good chance others have found and solved it already, if not then there are lots of people willing to help on StackOverflow and other forums.
  • Documentation: Firebase has a huge and excellently written documentation base. Their documentation is also extremely complete spreading across almost every feature or function you might want to implement.
  • Security: Security is on both lists. Security is easy to set up and understand on your Firebase database. The fact they give you the freedom to set and modify is a real strength. This enables you to customise your functionality very well to your specific app.
  • Speed: Firebase is super quick which is a very important feature for a real time chat.
  • Quality: The Firebase code is extremely well written and excellently tested. In the 4 years I have been working with Firebase I have yet to find a bug with their provided code.
Disadvantages of FireChat:
  • Searching: Firebase is very bad for apps which require an accurate search. Basic search is possible but is not particularly sensitive or quick. If you need to search for characters stored in your database then you either need to write some tricky/slow code or need to use another framework for search (RIP Parse which had excellent search queries)
  • Push notifications: Firebase does have push notifications but these require a custom server. This is a shame as an in house feature would be incredibly convenient.
  • Data storage: Firebase is not the best database for storing large data files. It deals with text great but if you need to be uploading large images/videos regularly then there are probably better services you could use.
  • Security: Firebase is secure but not bullet proof. If your data is highly sensitive then it is worth having a service which specialises in data security.
From the points above you should be able to see that Firebase is a great product with its main disadvantages being in very specific areas. These might affect you depending on your project but can often be fixed with other frameworks.
I would argue that using an API for chat is itself very limiting. In this sense using FireChat is just as bad as using any of those other listed APIs. Below I have listed some of the main disadvantages I see of using any chat API:
Advantages of using Firebase for chat but not FireChat:
  • Flexibility: Firebase is extremely flexible, dumping the API will increase Firebase’s flexibility. Your imagination is the limit of ways in which it can be used.
  • Control: When using an API you are limited by their functions and structure. You are also limited when adding new features. Using FireChat reduces the control you have over the code as the structure is completely fixed.
  • Customisation: Similar to the points above, when using an API you give up a large amount of control in exchange for additional ease of use. In this case I don’t think it is worth it due to the way the Firebase code is currently written. Coding your chat using Firebase, but not through the API, will allow you to add new features and more easily modify current ones.
As you can see Firebase excels when it is being used for the majority of projects. Where it falls down is when a specific project has some very specific requirements which don’t quiet fit the Firebase model. This is why I would recommend it to 95% of developers - the other 5% will need to research what will be best for them.
The problem is not with SendBird, Layer or Sinch but the inherent problem with Chat APIs themselves. Although FireChat falls into all these pitfalls, Firebase provides code to enable you to code it yourself.
Our company has recently released an open source chat component, using Firebase, on Github. These are fully complete and compatible IOS and ANDROID chats which we have released on an MIT license. This means you can release and modify the code with no obligation to us. Both of these project use Firebase for message and data storage but use Backendless for push notifications. I would recommend these over the other chat APIs as it gives you the source code to modify instead of being reliant on a companies frameworks.
What else could we use?
One final disadvantage of Firebase (and all the frameworks you mentioned) is the fact that you are using someone else’s service meaning you are reliant on them. Obviously this is a problem with every chat solution as it requires you to use their API for your project. The solution to this could be XMPP which is what many professional chats have switched to using. The advantage is that you build your service and configure it directly to the service you offer. Our company also specialises in XMPP solutions.

Monday, 20 November 2017

Difference between an interface and abstract class



ABSTRACT 



A class has common behavior which repeatedly use for subclass then you should go with abstract class. You can override the method of parent class & if you want apply some extra modification as per your code needs.

Abstract classes may contain abstract declarations, concrete implementations, or both.

Abstract classes are best choice for re-implementation in future that to add more functionality without affecting of end user.


  • Abstract class can have abstract and non-abstract methods.
  • Abstract class doesn't support multiple inheritance.
  • Abstract class can have final, non-final, static and non-static variables.
  • Abstract class can provide the implementation of interface.
  • The abstract keyword is used to declare abstract class.
  • Comparatively fast.
  • We can't not create object of Abstract class.
  • We can create reference variable.

We choose an abstract class when there are some features for which we know what to do, and other features that we know how to perform.

Consider the following example:

public abstract class Burger{
   
    public void packing(){
        //some logic for packing a burger
    }
   
    public abstract void price(); //price is different for different categories of burgers

}

public class VegBerger extends Burger{
    public void price(){
         //set price for a veg burger.
    }
}

public class NonVegBerger extends Burger{
     public void price(){
         //set price for a non-veg burger.
     }
}

If we add methods (concrete/abstract) in the future to a given abstract class, then the implementation class will not need a change its code. However, if we add methods in an interface in the future, we must add implementations to all classes that implemented that interface, otherwise compile time errors occur.
            


INTERFACE

Interfaces are rules. That’s because rules you must give an implementation to them that you can't ignore or avoid, so that they are imposed like rules which common understanding among the developers.

In other words, Interfaces give the idea what is to be done but not how it will be done. So implementation completely depends on developer by following the given rules.

  • Interface can have only abstract methods. Since Java 8, it can have default and static methods also.
  • Interface supports multiple inheritance.
  • Interface has only static and final variables.
  • Interface can't provide the implementation of abstract class.
  • The interface keyword is used to declare interface.
  • Interface are slow as it requires extra indirection.

If user want to write different functionality that would be different functionality on objects. Interfaces are best choice that if not need to modify the requirements once interface has been published.

Consider a Payment class. Payment can be made in many ways, such as PayPal, credit card etc. So we normally take Payment as our interface which contains a makePayment() method and CreditCard and PayPal are the two implementation classes.

public interface Payment{
     void makePayment();//by default it is a abstract method
}

public class PayPal implements Payment{
     public void makePayment(){
         //some logic for PayPal payment
         //e.g. Paypal uses username and password for payment
     }
}

public class CreditCard implements Payment{
    public void makePayment(){
         //some logic for CreditCard payment
         //e.g. CreditCard uses card number, date of expiry etc...
     }
}

In the above example CreditCard and PayPal are two implementation classes /strategies. An Interface also allows us the concept of multiple inheritance in Java which cannot be accomplished by an abstract class.

I hope this will help!

Thursday, 27 November 2014

Use Of Meta-Data In An AndroidManifest

Sometimes you have the need to set up some app-wide configuration information in an Android app or need to create a class that can be used in multiple projects with a generic way of setting configuration values. This is particularly useful for things like API keys that will probably be different across apps but should be accessible in the same way. There are several ways to do it, but the one I’ve come to prefer is adding a Meta-Data to the AndroidManifest.xml file.

This field can be used to store a boolean, float, int, or String and is later accessed by the Bundle method for your data type (e.g., getInt()). Here is an example of how to define a value in your AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
  package="com.example.readmetadata"
  android:versionCode="1"
  android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MainMenu" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <meta-data android:name="my_api_key" android:value="mykey123" />
    </application>
    <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8" />
</manifest>

Reading this meta-data takes just a few lines of Java:

try {
    ApplicationInfo ai = getPackageManager().getApplicationInfo(activity.getPackageName(), PackageManager.GET_META_DATA);
    Bundle bundle = ai.metaData;
    String myApiKey = bundle.getString("my_api_key");
} catch (NameNotFoundException e) {
    Log.e(TAG, "Failed to load meta-data, NameNotFound: " + e.getMessage());
} catch (NullPointerException e) {
    Log.e(TAG, "Failed to load meta-data, NullPointer: " + e.getMessage());        
}

Activity extends ContextWrapper which has a getPackageManager() method. That method returns the PackageManager, which is used to fetch the ApplicationInfo, passing the package name and the meta-data flag. The returned ApplicationInfo contains a field, metaData, which is actually a Bundle containing all the meta data. Line 4 fetches a String that is the same as the “android:name” parameter in the XML.
That sounds more complicated than it really is. Basically, if you have an Activity, you can fetch the Bundle that has all your meta-data from the AndroidManifest and use it throughout the app.

Tuesday, 7 October 2014

Secure Your Domain & keys


As i believe we require to secure our domain & secure keys from users. I have R&D & found some solution/place where we can write these keys.

1) Values Folder [80% Security]: We can write these key in Values folder under the String.xml, as we have found when you use APK tool & de-compile the code then this folder is not visible to users but i have mentioned it's 80% Security because i have reviewed the some of thread & it's say we can retrieve the values folder too.

My Experience : Still i didn't found that it's accessible. you can use

2) C++ code[100% Security]: you can write your all the keys in C++ code & you can use. It will not accessible & de-compilable for other user.

Friday, 1 August 2014

Android Language Support & Tags

As we know there are lot's of changes for the languages to add with android version. Please refer below all the tags & language name which we can add for support 

Arabic, Egypt (ar_EG) [values-ar] DONE
Arabic, Israel (ar_IL)
Bulgarian, Bulgaria (bg_BG) [values-bg]
Catalan, Spain (ca_ES) [values-ca]
Czech, Czech Republic (cs_CZ) [values-cs]
Danish, Denmark(da_DK) [values-da]
German, Austria (de_AT) [values-de]
German, Switzerland (de_CH) 
German, Germany (de_DE)
German, Liechtenstein (de_LI)
Greek, Greece (el_GR) [values-el]
English, Australia (en_AU) 
English, Canada (en_CA)
English, Britain (en_GB)
English, Ireland (en_IE)
English, India (en_IN)
English, New Zealand (en_NZ)
English, Singapore(en_SG)
English, US (en_US)
English, South Africa (en_ZA)
Spanish (es_ES)  [values-es]
Spanish, US (es_US)
Finnish, Finland (fi_FI) [values-fi]
French, Belgium (fr_BE)
French, Canada (fr_CA)
French, Switzerland (fr_CH)
French, France (fr_FR) : DONE [values-fr]
Hebrew, Israel (he_IL) [values-he]
Hindi, India (hi_IN) [values-hi]
Croatian, Croatia (hr_HR) [values-hr]
Hungarian, Hungary (hu_HU) [values-hu]
Indonesian, Indonesia (id_ID) [values-id]
Italian, Switzerland (it_CH) [values-it]
Italian, Italy (it_IT)
Japanese (ja_JP) [values-ja]
Korean (ko_KR) [values-ko]
Lithuanian, Lithuania (lt_LT) [values-lt] 
Latvian, Latvia (lv_LV) [values-lv]
Norwegian bokmål, Norway (nb_NO) [values-nb]
Dutch, Belgium (nl_BE) [values-nl]
Dutch, Netherlands (nl_NL)
Polish (pl_PL) [values-pl]
Portuguese, Brazil (pt_BR) [values-pt]
Portuguese, Portugal (pt_PT)
Romanian, Romania (ro_RO) [values-ro]
Russian (ru_RU) [values-ru]
Slovak, Slovakia (sk_SK) [values-sk]
Slovenian, Slovenia (sl_SI) [values-sl]
Serbian (sr_RS)[values-sr]
Swedish, Sweden (sv_SE) [values-sv]
Thai, Thailand (th_TH) [values-th]
Tagalog, Philippines (tl_PH) [values-tl]
Turkish, Turkey (tr_TR) [values-tr]
Ukrainian, Ukraine (uk_UA) [values-uk]
Vietnamese, Vietnam (vi_VN) [values-vi]
Chinese, PRC (zh_CN) [values-zh]
Chinese, Taiwan (zh_TW)

Monday, 10 February 2014

Server Status Code


Successful Message & Code

This class of status code indicates that the client's request was successfully received, understood, and accepted.
1) 200 OK
The request has succeeded. The information returned with the response is dependent on the method used in the request, for example:
GET an entity corresponding to the requested resource is sent in the response;
HEAD the entity-header fields corresponding to the requested resource are sent in the response without any message-body;
POST an entity describing or containing the result of the action;
TRACE an entity containing the request message as received by the end server.
2) 201 Created
The request has been fulfilled and resulted in a new resource being created. The newly created resource can be referenced by the URI(s) returned in the entity of the response, with the most specific URI for the resource given by a Location header field. The response SHOULD include an entity containing a list of resource characteristics and location(s) from which the user or user agent can choose the one most appropriate. The entity format is specified by the media type given in the Content-Type header field. The origin server MUST create the resource before returning the 201 status code. If the action cannot be carried out immediately, the server SHOULD respond with 202 (Accepted) response instead.

3) 202 Accepted
The request has been accepted for processing, but the processing has not been completed. The request might or might not eventually be acted upon, as it might be disallowed when processing actually takes place. There is no facility for re-sending a status code from an asynchronous operation such as this.
The 202 response is intentionally non-committal. Its purpose is to allow a server to accept a request for some other process (perhaps a batch-oriented process that is only run once per day) without requiring that the user agent's connection to the server persist until the process is completed. The entity returned with this response SHOULD include an indication of the request's current status and either a pointer to a status monitor or some estimate of when the user can expect the request to be fulfilled.
4) 203 Non-Authoritative Information
The returned metainformation in the entity-header is not the definitive set as available from the origin server, but is gathered from a local or a third-party copy. The set presented MAY be a subset or superset of the original version. For example, including local annotation information about the resource might result in a superset of the metainformation known by the origin server. Use of this response code is not required and is only appropriate when the response would otherwise be 200 (OK).
5) 204 No Content
The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. The response MAY include new or updated metainformation in the form of entity-headers, which if present SHOULD be associated with the requested variant.
If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view.
The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.
6) 205 Reset Content
The server has fulfilled the request and the user agent SHOULD reset the document view which caused the request to be sent. This response is primarily intended to allow input for actions to take place via user input, followed by a clearing of the form in which the input is given so that the user can easily initiate another input action. The response MUST NOT include an entity.
7) 206 Partial Content
The server has fulfilled the partial GET request for the resource. The request MUST have included a Range header field (section 14.35) indicating the desired range, and MAY have included an If-Range header field (section 14.27) to make the request conditional.


400 Bad Request
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
1) 401 Unauthorized
The request requires user authentication. The response MUST include a WWW-Authenticate header field (section 14.47) containing a challenge applicable to the requested resource. The client MAY repeat the request with a suitable Authorization header field (section 14.8). If the request already included Authorization credentials, then the 401 response indicates that authorization has been refused for those credentials. If the 401 response contains the same challenge as the prior response, and the user agent has already attempted authentication at least once, then the user SHOULD be presented the entity that was given in the response, since that entity might include relevant diagnostic information. HTTP access authentication is explained in "HTTP Authentication: Basic and Digest Access Authentication" [43].
2) 402 Payment Required
This code is reserved for future use.
3) 403 Forbidden
The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. If the server does not wish to make this information available to the client, the status code 404 (Not Found) can be used instead.
4) 404 Not Found
The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable.
5) Method Not Allowed
The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response MUST include an Allow header containing a list of valid methods for the requested resource.
6) 406 Not Acceptable
The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.
Unless it was a HEAD request, the response SHOULD include an entity containing a list of available entity characteristics and location(s) from which the user or user agent can choose the one most appropriate. The entity format is specified by the media type given in the Content-Type header field. Depending upon the format and the capabilities of the user agent, selection of the most appropriate choice MAY be performed automatically. However, this specification does not define any standard for such automatic selection.
      Note: HTTP/1.1 servers are allowed to return responses which are
      not acceptable according to the accept headers sent in the
      request. In some cases, this may even be preferable to sending a
      406 response. User agents are encouraged to inspect the headers of
      an incoming response to determine if it is acceptable.

If the response could be unacceptable, a user agent SHOULD temporarily stop receipt of more data and query the user for a decision on further actions.
7) 407 Proxy Authentication Required
This code is similar to 401 (Unauthorized), but indicates that the client must first authenticate itself with the proxy.  
8) 408 Request Timeout
The client did not produce a request within the time that the server was prepared to wait. The client MAY repeat the request without modifications at any later time.
9) 409 Conflict
The request could not be completed due to a conflict with the current state of the resource. This code is only allowed in situations where it is expected that the user might be able to resolve the conflict and resubmit the request. The response body SHOULD include enough
information for the user to recognize the source of the conflict. Ideally, the response entity would include enough information for the user or user agent to fix the problem; however, that might not be possible and is not required.
Conflicts are most likely to occur in response to a PUT request. For example, if versioning were being used and the entity being PUT included changes to a resource which conflict with those made by an earlier (third-party) request, the server might use the 409 response to indicate that it can't complete the request. In this case, the response entity would likely contain a list of the differences between the two versions in a format defined by the response Content-Type.
10) 410 Gone
The requested resource is no longer available at the server and no forwarding address is known. This condition is expected to be considered permanent. Clients with link editing capabilities SHOULD delete references to the Request-URI after user approval. If the server does not know, or has no facility to determine, whether or not the condition is permanent, the status code 404 (Not Found) SHOULD be used instead. This response is cacheable unless indicated otherwise.
The 410 response is primarily intended to assist the task of web maintenance by notifying the recipient that the resource is intentionally unavailable and that the server owners desire that remote links to that resource be removed. Such an event is common for limited-time, promotional services and for resources belonging to individuals no longer working at the server's site. It is not necessary to mark all permanently unavailable resources as "gone" or to keep the mark for any length of time -- that is left to the discretion of the server owner.
11) 411 Length Required
The server refuses to accept the request without a defined Content- Length. The client MAY repeat the request if it adds a valid Content-Length header field containing the length of the message-body in the request message.
12) 412 Precondition Failed
The precondition given in one or more of the request-header fields evaluated to false when it was tested on the server. This response code allows the client to place preconditions on the current resource metainformation (header field data) and thus prevent the requested method from being applied to a resource other than the one intended.
13) 413 Request Entity Too Large
The server is refusing to process a request because the request entity is larger than the server is willing or able to process. The server MAY close the connection to prevent the client from continuing the request.
If the condition is temporary, the server SHOULD include a Retry- After header field to indicate that it is temporary and after what time the client MAY try again.
14) 414 Request-URI Too Long
The server is refusing to service the request because the Request-URI is longer than the server is willing to interpret. This rare condition is only likely to occur when a client has improperly converted a POST request to a GET request with long query information, when the client has descended into a URI "black hole" of redirection (e.g., a redirected URI prefix that points to a suffix of itself), or when the server is under attack by a client attempting to exploit security holes present in some servers using fixed-length buffers for reading or manipulating the Request-URI.
15) 415 Unsupported Media Type
The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method.
16) 416 Requested Range Not Satisfiable
A server SHOULD return a response with this status code if a request included a Range request-header field (section 14.35), and none of the range-specifier values in this field overlap the current extent of the selected resource, and the request did not include an If-Range request-header field. (For byte-ranges, this means that the first- byte-pos of all of the byte-range-spec values were greater than the current length of the selected resource.)
When this status code is returned for a byte-range request, the response SHOULD include a Content-Range entity-header field specifying the current length of the selected resource (see section 14.16). This response MUST NOT use the multipart/byteranges content- type.
17) 417 Expectation Failed
The expectation given in an Expect request-header field (see section 14.20) could not be met by this server, or, if the server is a proxy, the server has unambiguous evidence that the request could not be met by the next-hop server.


Server Error 5xx
Response status codes beginning with the digit "5" indicate cases in which the server is aware that it has erred or is incapable of performing the request. Except when responding to a HEAD request, the server SHOULD include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. User agents SHOULD display any included entity to the user. These response codes are applicable to any request method.
1) 500 Internal Server Error
The server encountered an unexpected condition which prevented it from fulfilling the request.
2) 501 Not Implemented
The server does not support the functionality required to fulfill the request. This is the appropriate response when the server does not recognize the request method and is not capable of supporting it for any resource.
3) 502 Bad Gateway
The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request.
4) 503 Service Unavailable
The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. If known, the length of the delay MAY be indicated in a Retry-After header. If no Retry-After is given, the client SHOULD handle the response as it would for a 500 response.
      Note: The existence of the 503 status code does not imply that a
      server must use it when becoming overloaded. Some servers may wish
      to simply refuse the connection.

5) 504 Gateway Timeout
The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server specified by the URI (e.g. HTTP, FTP, LDAP) or some other auxiliary server (e.g. DNS) it needed to access in attempting to complete the request.
      Note: Note to implementors: some deployed proxies are known to
      return 400 or 500 when DNS lookups time out.

6) 505 HTTP Version Not Supported
The server does not support, or refuses to support, the HTTP protocol version that was used in the request message. The server is indicating that it is unable or unwilling to complete the request using the same major version as the client, 

Thursday, 9 January 2014

AAPT Filing With Error Code -1073741819

You will get this error while you have written wrong in main.xml file in menu. 

Solution : 

Please correct the id/string in xml file & rebuild the application. It will resolved your problem 100%.