Tuesday, 27 May 2014

ScheduledThreadPoolExecutor example

package mypackage;
import java.text.DateFormat;

import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ScheduledExample {
    final static DateFormat fmt = DateFormat.getTimeInstance(DateFormat.LONG);
    public static void main(String[] args) {
        // Create a scheduled thread pool with 5 core threads
        ScheduledThreadPoolExecutor sch = (ScheduledThreadPoolExecutor)
                Executors.newScheduledThreadPool(5);
        
        // Create a task for one-shot execution using schedule()
        Runnable oneShotTask = new Runnable(){
            @Override
            public void run() {
                System.out.println("\t oneShotTask Execution Time: "
                            + fmt.format(new Date()));
            }
        };
        
        // Create another task
        Runnable delayTask = new Runnable(){
            @Override
            public void run() {
                try{
                    System.out.println("\t delayTask Execution Time: "
                            + fmt.format(new Date()));
                    Thread.sleep(10 * 1000);
                    System.out.println("\t delayTask End Time: "
                            + fmt.format(new Date()));
                }catch(Exception e){
                    
                }
            }
        };
        
        // And yet another
        Runnable periodicTask = new Runnable(){
            @Override
            public void run() {
                try{
                    System.out.println("\t periodicTask Execution Time: "
                            + fmt.format(new Date()));
                    Thread.sleep(10 * 1000);
                    System.out.println("\t periodicTask End Time: "
                            + fmt.format(new Date()));
                }catch(Exception e){
                    
                }
            }
        };
        
        System.out.println("Submission Time: " + fmt.format(new Date()));
    //  ScheduledFuture<?> oneShotFuture = sch.schedule(oneShotTask, 5, TimeUnit.SECONDS);
      ScheduledFuture<?> delayFuture = sch.scheduleWithFixedDelay(delayTask, 5, 5, TimeUnit.SECONDS);
     //   ScheduledFuture<?> periodicFuture = sch.scheduleAtFixedRate(periodicTask, 5, 5, TimeUnit.SECONDS);
    }
}

Friday, 16 May 2014

How to generate Java Doc

Java Doc can be generated using Eclipse IDE.We should have Javadoc.exe in the bin folder of the Java

Following is the step

Go to Eclipse--------->Project Menu--------->Generate Java Doc--------->Here you will be prompted with the menu which contains all the projects present in IDE , select the project for which you want JavaDoc.

Above give the following location C:\Program Files\Java\jdk1.7.0_17\bin\javadoc.exe


Click on next.Select the location where uou want the java doc's to be extracted.

Done:)

Thursday, 27 February 2014

How to start development of html5 Apps using PhoneGap and Eclipse

Following are seven simple steps to write hello world project using HTML5

  • Download and install PhoneGap
  • Create a new Android App Project
  • Change the project from Java to Javascript
  • Prepare the Activity-Class to work with PhoneGap
  • Create a simple index.html file to run on the App
  • Prepare the Manifest-file before running it
  • To run the App 
Step 1 : Create Android  Project in Eclipse
Step 2 : First create a new folder called www and a new file called index.html. both in the project folder assets
Step 3 : Copy the Cordova.js file[Take from the phoneGap folder which we have installed] in assets folder and Cordova.jar[Take from the phoneGap folder which we have installed] file in the lib folder and xml [Take from the phoneGap folder which we have installed] folder in the values of our android project.
Step 4 : In the eclipse locate the src-folder and open the MainActivity.java class in it and change it that way you'll see bellow:

package com.example.phonegapexample;

import org.apache.cordova.DroidGap;


import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends DroidGap  {

//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);
//    }

     @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            super.loadUrl("file:///android_asset/www/index.html");
        }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

Step 5 : Content of Index.html

<!DOCTYPE HTML>
<html>
  <head>
    <title>First App</title>
  <script src="cordova-2.2.0.js"></script>
  <script>
     function onLoad(){
          document.addEventListener("deviceready", onDeviceReady, true);
     }
     function onDeviceReady(){ navigator.notification.alert("PhoneGap is working!!");
     }
  </script>
  </head>
  <body onload="onLoad();">
       <h1>Welcome to PhoneGap</h1>
       <h2>Edit assets/www/index.html</h2>
  </body>
</html>
 
Step 6 : Prepare the Manifest-File before launching
 
 <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:xlargeScreens="true"
        android:resizeable="true"
        android:anyDensity="true"
        />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.RECORD_VIDEO"/>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />   
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />   
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.BROADCAST_STICKY" /> 

Step 7 : Running the App[Same procedure of how we run usual android App like Rus as Android Application]
 

Wednesday, 26 February 2014

How to get App name from Manifest

final PackageManager pm = getApplicationContext().getPackageManager();
ApplicationInfo ai;
try {
    ai = pm.getApplicationInfo( this.getPackageName(), 0);
} catch (final NameNotFoundException e) {
    ai = null;
}
final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "(unknown)");

Tuesday, 25 February 2014

Read me Sample file

INTRODUCTION
------------
 - Step 1
 - Step 2
 - Step 3
 - Step 4
 
How It Works
------------
 - Step 1
 - Step 2
 - Step 3
 - Step 4

 +------------+++-----------------+
 |    Steps for Building the Code      |
 +------------+++-----------------+
 o Step 1
 o Step 2
 o Step 3
  - 3.1
    explanation
  - 3.2
    explanation
  - 3.3
    explanation


   










Sunday, 16 February 2014

Record screen action (capture video) on Android KitKat



Android KitKat provide a new feature to record screen action.

To record video on Android KitKat:

    Enable developer options on KitKat
    Connect your KitKat device to your PC.
    In your PC, run:
    $ adb shell screenrecord /sdcard/video.mp4

To stop recording:

    Press Control-C on your PC

Your recorded video will be in /sdcard/video.mp4 on your Android KitKat device.

Thursday, 13 February 2014

Reverse engineer your apk

You can also de-obfuscate  your apk using any of the available tools from google. What we demonstrate or work with is dex2jar. Please download this tool from http://code.google.com/p/dex2jar/. 

1.In command prompt navigate to dex2jar directory: Now type the following command. See the screen shot . This will change your apk file to .jar.

.Jar will be generated in your path where dex2jar software will be present
In this case (D:\sample\D-final\soft\dex2jar-0.0.9.15\dex2jar-0.0.9.15)

2. Once you have the .jar file, you need  jd-gui tool to view .jar . jd-gui is a graphical utility for viewing java source files. First download jd-gui here.
Open jd-gui.exe file-> click on open files. Now choose .jar file that you received from dex2jar tool. You are done, you can see following screen and browse through your java classes









In Command Prompt type the following

D:\Sample\D-final\soft\dex2jar-0.0.9.15\dex2jar-0.0.9.15>d2j-dex2jar.bat C:\Us
ers\sample\Desktop\All\BatteryUsage.apk




Automatically generates once you type enter
dex2jar C:\Users\KRN4BMH\Desktop\All\BatteryUsage.apk -> BatteryUsage-dex2jar.ja
r















Pass a HashMap from Angular Client to Spring boot API

This example is for the case where fileData is very huge and in json format   let map = new Map<string, string>()      map.set(this.ge...