I need to pass unique no to server every time with updated user data. For that I think, first I need to generate random no and store in a variable. When ever I need to pass updated user data, I generate random no again and compare it with stored random no. If It is different I pass it with user data otherwise I genarete it again and again until I fond different no. This sceneraio is not good for me. For generate unique no I use Calender class and get the current time in millisecond. I did not need to compare just generate the no and pass with user data.
import java.util.Calendar;
import java.util.TimeZone;
Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis();
above code return the time in milliseconds from 1970.
Using "UTC" for getting accurate value from same time zone.
Please imports related file by pressing "CTRL+SHIFT+O" keys.
Android Tutorial
This Blog is related to Android. I am just sharing knowledge for increase my knowledge.
Friday, March 15, 2013
Thursday, March 14, 2013
Set transparent background in textbox / Remove backround of text box in android
You just need to set background property as nulll in xml file, like this
<EditText
android:id="@+id/mytext"
android:layout_width="30dp"
android:layout_height="56dp"
android:background="@null"
>
<EditText
android:id="@+id/mytext"
android:layout_width="30dp"
android:layout_height="56dp"
android:background="@null"
>
Monday, March 11, 2013
Lanuch Email available client in phone / Send Email from your application
Android application can send email from available email clients in your phone. For launching the email clients, simply pass the "ACTION_SEND" in intent constructor and add some extra to intents. You also have to set type of the contents.
Example:
Intent emailClient= new Intent(Intent.ACTION_SEND);
emailClient.putExtra(Intent.EXTRA_EMAIL, "email@domain.com");
emailClient.putExtra(Intent.EXTRA_SUBJECT, "Hi");
emailClient.putExtra(Intent.EXTRA_TEXT, "How r u!");
emailClient.setType("message/rfc822");
startActivity(Intent.createChooser(emailClient,"Title"));
You need to add Internet permission in manifest file like this
<uses-permission android:name="android.permission.INTERNET" />
Note: You can test this code only on phone. Emulator can not send email and will generate error.
Example:
Intent emailClient= new Intent(Intent.ACTION_SEND);
emailClient.putExtra(Intent.EXTRA_EMAIL, "email@domain.com");
emailClient.putExtra(Intent.EXTRA_SUBJECT, "Hi");
emailClient.putExtra(Intent.EXTRA_TEXT, "How r u!");
emailClient.setType("message/rfc822");
startActivity(Intent.createChooser(emailClient,"Title"));
You need to add Internet permission in manifest file like this
<uses-permission android:name="android.permission.INTERNET" />
Note: You can test this code only on phone. Emulator can not send email and will generate error.
Send SMS/lanuch SMS service for sending sms
You can send SMS by your android application. Simply create an Intent and pass ACTION_VIEW in constructor. Set type of intent as "vnd.android-dir/mms-sms". It will open you SMS editor with your custom text.
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.putExtra("sms_body","Hello, How r you !");
smsIntent.setType("vnd.android-dir/mms-sms");
startActivity(smsIntent);
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.putExtra("sms_body","Hello, How r you !");
smsIntent.setType("vnd.android-dir/mms-sms");
startActivity(smsIntent);
Sunday, March 10, 2013
Android: Hide title bar of window / activity programatically.
At run time, In onCreate() method we can request window feature for hiding the title of the activity/window.
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
Above line must be write before adding the content on the view.
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.my_activity);
for Importing the references press CTRL+SHIFT+O
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
Above line must be write before adding the content on the view.
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.my_activity);
for Importing the references press CTRL+SHIFT+O
Subscribe to:
Comments (Atom)