Wednesday, April 2, 2014

Phonegap and setting Android using command line on mac

It's work cordova Android for MAC 1000000000%. I fought solution and now i'm working try this . 
STEPS:
Open Your Terminal and followed by,
  1. touch ~/.bash_profile;
  2. open ~/.bash_profile
  3. PATH="/Users/System-Name/Documents/android-sdk-macosx/tools:/Development/android-sdk-macosx/platform-tools:$PATH" (This is Android SDK Location to stored in My system )
enter image description here
4.Save the file and quit the text editor.
5.Execute your .bash_profile to update your PATH.
6.source ~/.bash_profile
if You want to see your Environment path:
7.In your Terminal Type: set
After you can see like
enter image description here
8.As far as your made it very correct. After your enter command like cordova platform add android. you get following error. because Java SDK doesn't too set environment PATH.
enter image description here
9.open ~/.bash_profile. Add JAVA SDK PATH


Decompiling an Android App on MAC

If you have an apk, there are several tools for reverse engineering it.

First of all you know how to download apk file from play store. There are planty of ways to you can do it. here i tell you very simple and optimized way.

1. http://apps.evozi.com/apk-downloader/#guide

or 

2.  Chrome Extension - Download APK with your own account directly

This is more conventional, and goes back all the way to the java code . It’s works based on two tools:
  • dex2jar,  which converts Android’s Dalvik executables into a Java jar files.
  • JD-GUI,  which decompiles jar files into java source files (any jar, not just android stuff).
Download Tool from here

Tuesday, April 1, 2014

Android System Bar Tint

How to apply android status bar Tint color ?

You must first enable translucency in your Activity - either by using or inheriting from one of the various *.TranslucentDecor themes, by setting the android:windowTranslucentNavigation or android:windowTranslucentStatus theme attributes to true or by applying the FLAG_TRANSLUCENT_NAVIGATIONor FLAG_TRANSLUCENT_STATUS flags to your Activity window in code.

https://github.com/jgilfelt/SystemBarTint


Android Studio Gradle issue upgrading to new version


The most simple Android project has the following build.gradle:

    buildscript {
        repositories {
            mavenCentral()
        }
 
        dependencies {
            classpath 'com.android.tools.build:gradle:0.9.0'
        }
    }
 
    apply plugin: 'android'
 
    android {
        compileSdkVersion 19
        buildToolsVersion "19.0.0"
    }

There are 3 main areas to this Android build file:



Note:

Still the problem cannot solved after made changes above in the your project. Save the changes and close your project then again import to Android Studio 




Android webservcie with PHP code

Create a new project in your Android Studio by filling the required details.
Here the sample project was created by Eclipse IDE.


Facing issue on project import in Android Studio visit this Android Studio issues 

Step by Steps

1. Create new project in Eclipse IDE by going to File ⇒ New ⇒ Android Project and name the Activity class name as MainActivity.
2. Open your AndroidManifest.xml file and add following code. First i am adding all the classes i am creating to manifest file. Also i am adding INTERNET Connect permission. This connection is required must.

<!--  Internet Permissions -->
    <uses-permission android:name="android.permission.INTERNET" />

3. Now create a new xml file under res ⇒ layout folder and name it as main.xml This layout file contains two simple buttons to view all products and add a new product.

4. Open you main activity class which is MainActivity.java and write click events for two button which are mentioned in main.xml layout.

5. Now we need an Activity display all the products in list view format. As we know list view needs two xml files, one for listview and other is for single list row. Create two xml files under res ⇒ layout folder and name it as all_products.xml and list_item.xml


6. Create a new class file and name it as AllActivity.java. In the following code
    6.1 First a request is send to get_products.php file using a Background Async task thread.
    6.2 After getting JSON from get_all_products.php, i parsed it and displayed in a listview.
    6.3 If there are no products found AddNewAcivity is launched.

7. Create a new view and activity to add a new product into mysql database. Create a simple form which contains EditText for product name, price and description.
Create a new xml file and name it as add_product.xml and paste the following code to create a simple form.

8. Now create new Activity to insert a new product into mysql database. Create a class file and name it asNewtActivity.java and type the following code. In the following code
8.1 First new product data is read from the EditText form and formatted into a basic params.
8.2 A request is made to create_product.php to create a new product through HTTP post.
8.3 After getting json response from create_product.php, If success bit is 1 then list view is refreshed with newly added product.

Sample Project:

https://github.com/iDevAndroid/MySQLPHP

Sunday, March 16, 2014

Android Tutorial : Passing object by Intent using Parcelable

According to google engineers, this code will run significantly faster. One of the reasons for this is that we are being explicit about the serialization process instead of using reflection to infer it. It also stands to reason that the code has been heavily optimized for this purpose.
However, it is obvious here that implementing Parcelable is not free. There is a significant amount of boilerplate code and it makes the classes harder to read and maintain.
package  com.cocoalibrary.objectPass;  
 import android.os.Parcel;  
 import android.os.Parcelable;  
 public class Library implements Parcelable {  
     private String bookName;  
     private String author;  
     private int publishTime;  

     public String getBookName() {  
  return bookName;  
     }  
     public void setBookName(String bookName) {  
  this.bookName = bookName;  
     }  
     public String getAuthor() {  
  return author;  
     }  
     public void setAuthor(String author) {  
  this.author = author;  
     }  
     public int getPublishTime() {  
  return publishTime;  
     }  
     public void setPublishTime(int publishTime) {  
  this.publishTime = publishTime;  
     }  

     public static final Parcelable.Creator<Book> CREATOR = new Creator<Book>() {  
  public Book createFromParcel(Parcel source) {  
      Library mBook = new Library();  
      mBook.bookName = source.readString();  
      mBook.author = source.readString();  
      mBook.publishTime = source.readInt();  
      return mBook;  
  }  
  public Book[] newArray(int size) {  
      return new Book[size];  
  }  
     };  

     public int describeContents() {  
  return 0;  
     }  
     public void writeToParcel(Parcel parcel, int flags) {  
  parcel.writeString(bookName);  
  parcel.writeString(author);  
  parcel.writeInt(publishTime);  
     }  
 }

package com.cocoalibrary.objectPass;  
import android.app.Activity;  
import android.content.Intent;  
import android.os.Bundle;  
import android.view.View;  
import android.view.View.OnClickListener;  
import android.widget.Button;  
public class ParcelableDemo extends Activity implements OnClickListener {  

    private Button button;  
     
    public  final static String PAR_KEY = "com.cocoalibrary.parcelableKey";  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);     
        setupViews();  

    }  

    public void setupViews(){  
       
        button = (Button)findViewById(R.id.button);  
        
        button.setOnClickListener(this);  
    }  
 

    public void PacelableMethod(){  
        Library mBook = new Library();  
        mBook.setBookName("Pacelable Tutorial");  
        mBook.setAuthor("Raja");  
        mBook.setPublishTime(2014);  
        Intent mIntent = new Intent(this, PacelableDemo.class);  
        Bundle mBundle = new Bundle();  
        mBundle.putParcelable(PAR_KEY, mBook);  
        mIntent.putExtras(mBundle);  

        startActivity(mIntent);  
    }  

    public void onClick(View v) {   
            PacelableMethod();  
          
    }  
}

package com.cocoaLibrary.objectPass;  
 import android.app.Activity;  
 import android.os.Bundle;  
 import android.widget.TextView;  
 public class DetailDataView extends Activity {  

     public void onCreate(Bundle savedInstanceState) {  
  super.onCreate(savedInstanceState);  
  TextView mTextView = new TextView(this);  
  Book mBook = (Book)getIntent().getParcelableExtra(PacelableDemo.PAR_KEY);  
  mTextView.setText("Library name is: " + mBook.getBookName()+"/n"+  
      "Author is: " + mBook.getAuthor() + "/n" +  
      "PublishTime is: " + mBook.getPublishTime());  
  setContentView(mTextView);  
     }  
 }

If you want to be a good citizen, take the extra time to implement Parcelable since it will perform 10 times faster and use less resources.
However, in most cases, the slowness of Serializable won’t be noticeable. Feel free to use it  but  remember that serialization is an expensive operation so keep it to a minimum.
If you are trying to pass a list with thousands of serialized objects, it is possible that the whole process will take more than a second. It can make transitions or rotation from portrait to lanscape feel very sluggish.





Friday, March 14, 2014

JSON Object Simple Example Read And Write by Android

1. Write JSON to file

In below example, it write JSON data via JSONObject and JSONArray, and save it into a file named “sample.json“.
import java.io.FileWriter;
import java.io.IOException;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
 
public class JsonSimpleExample {
     public static void main(String[] args) {
 
 JSONObject obj = new JSONObject();
 obj.put("name", "cocoalibrary.com");
 obj.put("age", new Integer(50));
 
 JSONArray list = new JSONArray();
 list.add("value 1");
 list.add("value 2");
 list.add("value 3");
 
 obj.put("messages", list);
 
 try {
 
  FileWriter file = new FileWriter("c:\\sample.json");
  file.write(obj.toJSONString());
  file.flush();
  file.close();
 
 } catch (IOException e) {
  e.printStackTrace();
 }
 
 System.out.print(obj);
 
     }
 
}
Output – See content of file named “sample.json“.
{
 "age":100,
 "name":"cocoalibrary.com",
 "messages":["Name 1","Name 2","Name 3"]
}

3. Read JSON from file

Use JSONParser to read above generated JSON file “simple.json“, and display each of the values.
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;
import org.json.cocoalibrary.JSONArray;
import org.json.cocoalibrary.JSONObject;
import org.json.cocoalibrary.parser.JSONParser;
import org.json.cocoalibrary.parser.ParseException;
 
public class JsonExample {
     public static void main(String[] args) {
 
 JSONParser parser = new JSONParser();
 
 try {
 
  Object obj = parser.parse(new FileReader("c:\\sample.json"));
 
  JSONObject jsonObject = (JSONObject) obj;
 
  String name = (String) jsonObject.get("name");
  System.out.println(name);
 
  long age = (Long) jsonObject.get("age");
  System.out.println(age);
 
  // loop array
  JSONArray msg = (JSONArray) jsonObject.get("messages");
  Iterator<String> iterator = msg.iterator();
  while (iterator.hasNext()) {
   System.out.println(iterator.next());
  }
 
 } catch (FileNotFoundException e) {
  e.printStackTrace();
 } catch (IOException e) {
  e.printStackTrace();
 } catch (ParseException e) {
  e.printStackTrace();
 }
 
     }
 
}
Output
cocoalibrary.com
100
Name 1
Name 2
Name 3