Wednesday, March 5, 2014

PhoneGap set-up with Eclipse for Android

  1. Install latest version of NodeJs from here - http://nodejs.org/.
  2. Update Android ADT with latest one.Eclipse->Help-> Check for updates or install new software.and provide this link and update http://dl-ssl.google.com/android/eclipse/

    1. Update Android SDK. Eclipse-> window-> Android SDK Manager.
    2. Install PhoneGap. Refer following Link: http://docs.phonegap.com/en/edge/guide_cli_index.md.html#The%20Command-Line%20Interface.
    3. Install Cordova and create a new project. Refer following Link :          http://codingsquare.blogspot.in/2013/08/creating-cordova-3-android-project.html.
    4. Once project is created Import project to Eclipse. Refer Link: http://docs.phonegap.com/en/edge/guide_platforms_android_index.md.html#Android%20Platform%20Guide.
    5. Once you have imported project in eclipse, Error will show in the Hello Project saying "Andrdoid Reference library is missing/ Hello-Cordova-lib.jar is missing ". Then Clean the library project and rebuild it and your are done, that error will go off.



    Tuesday, February 25, 2014

    Data sharing between two apps.. Android



    Moreover, making any file MODE_WORLD_READABLE or (worse) MODE_WORLD_WRITEABLE is a bad idea. You lose any hope of security.
    If you wish to share data between two applications, there are a myriad of solutions, such as:
    • service with an API exposed by AIDL
    • service with an API exposed via commands sent via startService() and responses sent via aMessenger or createPendingResult() PendingIntent or something
    • content provider
    • broadcast Intents
    All of those allow you to define permissions for integration and let you control the granularity of access.

    Friday, February 21, 2014

    Jboss 5.1.0 Startup Error-AttachmentStore MC bean (org.jboss.system.server.profileservice.repository.AbstractAttachmentStore) configuration does not specify the parameter type for constructor

    Go to path - \server\default\conf\bootstrap  edit Profile.xml file as below:

    <bean name="AttachmentStore" class="org.jboss.system.server.profileservice.repository.AbstractAttachmentStore">
    <constructor><parameter><inject bean="BootstrapProfileFactory" property="attachmentStoreRoot" /></parameter></constructor>

    Maven Eclipse Plugin(M2Eclipse)

    Eclipse- Help-Install New Software- Add following Url for Eclipse Indigo

    http://download.eclipse.org/technology/m2e/releases-for-indigo/1.4/

    For lower versiong use following URL
    http://download.eclipse.org/technology/m2e/releases

    Wednesday, February 12, 2014

    Add Java Docs Eclipse

    To use offline Java API Documentation in Eclipse, you need to download it first. The link for Java docs are (last updated on 2013-10-21):
    1. Extract the zip file in your local directory.
    2. From ecliplse --> Window --> Preferences --> Java --> "Installed JREs" select available JRE (jre6 C:\Program Files (x86)\Java\jre6 for instance) and click Edit.
    3. Select all the "JRE System libraries" using CTRL key.
    4. Click "Javadoc Location"
    5. Change "Javadoc location path:" from "http://download.oracle.com/javase/6/docs/api/" to "file:/E:/Java/docs/api/".

    Alternatively:

    To view the standard Java JDK API documentation for all the classes that come with Java open up the tree in the "Package Explorer" for the JRE System Library, select rt.jar (the runtime library)
    From the "Navigate" menu select "Open External Javadoc" and you will see the Java API documentation. The default location of the documentation is Sun's website so the URL in the browser will be something like
    http://java.sun.com/j2se/1.7.0/docs/api/index.html
    
    To use our own local version of the documentation in
    file:/C:/Program Files/Java/jdk1.7.0_04/docs/api/
    
    so that we don't need to connect to the internet each time we want to view the documentation.
    To make the change right click on the rt.jar entry in the "Package Explorer" and select "Properties" to get the dialog box
    We need to change the URL in the "Javadoc location path". You can either type in the local value directly or use its browse button to navigate to
    Click "OK" and you should have the dialog box
    showing the local URL
    file:/C:/Program Files/Java/jdk1.5.0_04/docs/api/
    
    Click "Apply" and then "OK".
    Now to see the API documentation select rt.jar and choose "Open External Javadoc" from the "Navigate" menu (shortcut is Shift F2). Your local URL will now be shown in the browser address bar.

    Wednesday, February 5, 2014

    Tomcat Eclipse Configuration

    http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.stardust.docs.wst%2Fhtml%2Fwst-integration%2Fconfiguration.html...

    http://stackoverflow.com/questions/1012378/eclipse-server-locations-section-disabled-and-need-to-change-to-use-tomcat-ins

    Will be posting detail soon.....

    Sunday, September 22, 2013

    Pending Intent

    https://allaudin.github.io/pending-intent/- A good reference

    A PendingIntent is a token that you give to another application (e.g. Notification Manager, Alarm Manager or other 3rd party applications), which allows this other application to use the permissions of your application to execute a predefined piece of code.

    For Example, if we want to start our Service(which requires some special  permission like gps, action battery change etc), through AlarmManager which will trigger that service some-point in future at regular interval.
    Then we create a pending intent for our service and we give this intent to other application viz. in this case is AlarmManager Now AlarmManager will use the permission(gps, vibrate, etc) of our service to execute code.
    Intent intent = new Intent(this, MyService.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 234324243, intent, 0);
        AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
        alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
            + (i * 1000), pendingIntent);
    If you give the foreign application an Intent, and that application sends/broadcasts the Intent you gave, they will execute the Intent with their own permissions. But if you instead give the foreign application a PendingIntent you created using your own permission, that application will execute the contained Intent using your application's permission.
    A PendingIntent has defined Activity, Broadcast or Service  within it, and those can be sent to other applications to use it.
    I can define my Intent (Activity, BroadcastReceiver or Service) and can send to other application to use it. 

    Why PendingIntent is required ?

    If I create Intent,
    Intent bIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);

    and sending "bIntent" to other application , which is not having permission (android.permission.BLUETOOTH_ADMIN).

    So, When I do, 
    startActivity(bIntent);

    It will never launch bluetooth enabling Activity.

    If we use PendingIntent, the application (which use PendingIntent) no need to have permission. But the application which creates PendingIntent must have required permission for Intents.

    PendingIntent can be created using it's static methods getActivity(), getBroadcast() and getService().

    Let's see sample for PendingIntent,

    public class IParcel implements Parcelable
    {

        PendingIntent pIntent = null;
       
        public IParcel(PendingIntent pi)
        {
            pIntent = pi;
        }
       
        public IParcel(Parcel in)
        {
            pIntent = (PendingIntent)in.readValue(null);
        }
       
        public static Parcelable.Creator<IParcel> CREATOR = new Parcelable.Creator<IParcel>(){

            @Override
            public IParcel createFromParcel(Parcel source) {
                // TODO Auto-generated method stub
                return new IParcel(source);
            }

            @Override
            public IParcel[] newArray(int size) {
                // TODO Auto-generated method stub
                return null;
            }
           
        };
      
        @Override
        public int describeContents() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            // TODO Auto-generated method stub
            dest.writeValue(pIntent);
           
        }
       
    }

    public class FirstApp extends Activity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
        
            Intent myIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            PendingIntent pIntent = PendingIntent.getActivity(this, 0, myIntent,PendingIntent.FLAG_ONE_SHOT);//FLAG_ONE_SHOT - only once pIntent can use the myIntent
         
            IParcel ip = new IParcel(pIntent);
        
            Intent sndApp = new Intent();
            sndApp.setComponent(new ComponentName("com.myapp", "com.myapp.SecondApp"));
            sndApp.putExtra("obj",ip);
            startActivity(sndApp);
            }

    }

    public class SecondApp extends Activity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);

           IParcel pc = getIntent().getExtras().getParcelable("obj");
           if(pc != null){
                   pc.pIntent.send(); // this will launch the bluetooth enabling activity
           } 
           }
    }