Tuesday, March 27, 2012

RSA demo / example

This is the implementation of RSA tutorial given at http://www.javamex.com/tutorials/cryptography/rsa_encryption.shtml with little bit of additions so you can use it right out of the box.

CLASS:  RSAKeyGenerator
Method: void generateKeyPair("<public key file name>","<private key file name>")

CLASS: RSAEncDec
Method: String encrypt("your plane string message", "<location of public key file>")
              [Returns the base64 encoded string that you can send easily]

Method: String decrtpt("<above base64 encoded string>", "<location of private key file>")
              [Returns original plane string message]

For details see "readme.txt" and main() methods avaliable in each class
Download project at : https://github.com/meamit/rsa-demo

Friday, March 23, 2012

Showing notificaiton, passing parameter from Intent to activity

//my activity is under com.hello
//my activity class name is HelloAndroidActivity


In your IntentService class or Service class do following:

private void showNotification() {

        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
        int icon = R.drawable.icon;
        CharSequence tickerText = "some ticket text";
        long when = System.currentTimeMillis();

        Notification notification = new Notification(icon, tickerText, when);
       
        Context context = getApplicationContext();
        CharSequence contentTitle = "Some title";
        CharSequence contentText = "Some content";
        Intent notificationIntent = new Intent(this, HelloAndroidActivity.class);
       
        notificationIntent.setAction("com.hello"+System.currentTimeMillis());//notice : com.hello
   
        notificationIntent.putExtra("extra0", "some xtra message");
        notificationIntent.putExtra("extra1", "extra message");
       
       
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | Notification.FLAG_AUTO_CANCEL);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        mNotificationManager.notify(1, notification);//where 1 is the id,, different id will have different notification
   
    }
   
   
    in your activity class override onNewIntent method as shown below for example
   
    public void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Bundle extras = intent.getExtras();
        String extra0 = extras.getString("extra0");
        String extra1 = extras.getString("extra1");
    }

acess internet from android simulator connected to sim card in card reader

When sim card is present normally emulator [here i am referring to 2.3.3 version] will try to connect internet via sim card so internet do not work. One trick is to do following:
When the emulator starts, do following:
 menu->Setting->Wireless-> enable airplane mode
After this disable airplane mode.

[make sure that adb emulator is allowed in firewall]

Monday, March 12, 2012

Triple Graph Grammar

They are the techniques for defining the correspondence between source and target model in a declarative way [declarative: specifying what instead of how]. In TGG we can do bi-directional transformation namely Forward Transformation and Backward Transformation. However there is no distinct differentiation on that due to bidirectional nature of TGG. TGG also can be used for model synchronization. 3 parts of TGG are
source model  <------ trace/correspondence model -----> Target model
[note in the similarity with QVT]