Wednesday, 22 July 2015

Send SMS from Android Application


Program to send SMS is very simple to develope. You hardly have to write two lines of code. For writing a code for sending SMS we need to understand SMSManager class

SMSManager

This class manages android SMS such as sending text, We need to create object by calling the static method.

android.telephony.SmsManager.getDefault();

This method will give you default instance of SmsManager .

Using this instance we need to call sendTextMessage(destinationAddress, scAddress, text, sentIntent, deliveryIntent);

scAddress - This is used to specify the SMS service center to use. If you enter null, the default service center for the device carrier will be used.
destinationAddress - is the target phone number you wish to text
text - message to be send

android.telephony.SmsManager smsManager = android.telephony.SmsManager.getDefault();
smsManager.sendTextMessage(destinationAddress, scAddress, text, sentIntent, deliveryIntent);


That's it, simple it is..

Permission

Another critical part is to update Androidmanifest.xml, by adding this code to it

 <uses-permission android:name="android.permission.SEND_SMS" />

This grants permission for Android application to send sms.

Code

EditText editText;
Button btnSend;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText=(EditText) findViewById(R.id.editText1);
btnSend=(Button) findViewById(R.id.button1);
btnSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
android.telephony.SmsManager smsManager = android.telephony.SmsManager.getDefault();
smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);
}
});
}

Tuesday, 7 July 2015

Android Interview Question Part-3


1. What is the APK format?
The APK file is compressed AndroidManifest.xml file with extension .apk. It also includes the application code (.dex files), resource files, and other files which are compressed into a single .apk file.

2. What is a resource?
A user defined JSON, XML, bitmap, or other file, injected into the application build process, which can later be loaded from code.

3. What is an Intent?
A class (Intent) which describes what a caller desires to do. The caller will send this intent to Android’s intent resolver, which finds the most suitable activity for the intent. E.g. opening a PDF document is an intent, and the Adobe Reader apps will be the perfect activity for that intent (class).

4.What is a Sticky Intent?
sendStickyBroadcast() performs a sendBroadcast(Intent) known as sticky, i.e. the Intent you are sending stays around after the broadcast is complete, so that others can quickly retrieve that data through the return value of registerReceiver(BroadcastReceiver, IntentFilter). In all other ways, this behaves the same as sendBroadcast(Intent). One example of a sticky broadcast sent via the operating system is ACTION_BATTERY_CHANGED. When you call registerReceiver() for that action — even with a null BroadcastReceiver — you get the Intent that was last broadcast for that action. Hence, you can use this to find the state of the battery without necessarily registering for all future state changes in the battery.

5. What are the life cycle methods of android activity?
There are 7 life-cycle methods of activity. They are as follows:
  1. onCreate()
  2. onStart()
  3. onResume()
  4. onPause()
  5. onStop()
  6. onRestart()
  7. onDestroy()

6. What is implicit intent in android?

Implicit intent is used to invoke the system components.

7. What is explicit intent in android?

Explicit intent is used to invoke the activity class.

Thursday, 2 July 2015

Android Interview Question Part-2


11. When does onResume() method called?

onResume() method is an activity lifecycle method. This is called when the activity come to foreground. You can override this method in your activity to execute code when activity is started, restarted or comes to foreground.

12. How to launch an activity in your application?

For launching an activity, we need to create an explicit intent that defines the activity that we wish to start. In the below code snippet, the first parameter to Intent constructor is the current activity context and the second parameter is your new activity class.startActivity() method can be called on Activity context.
Intent intent = new Intent(this,
SecondActivity.class);
startActivity(intent);
If you want to start an activity from fragment
Intent intent = new Intent(getActivity(),
SecondActivity.class);
getActivity().startActivity(intent);

13. How to define an Activity as launcher activity in application Manifest file?

All the activities used in the application should be defined in application manifest file. For launcher activity you need to define intent filter as shown in the below code snippets.
<activity android:name=".MyActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action
android:name="android.intent.action.MAIN" />
            <category
android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

14. What is a ANR ?

ANR is short for Application Not Responding. Android systems shows this dialog, if application is performing too much of task on main thread and been unresponsive for a long period of time.

15. What are the measures to avoid application ANR?

ANR in application is annoying to user. It can be caused due to various reasons. Below are some of the tips to avoid ANR
  • Perform all you long running network or database operation in separate thread
  • If you have too much of background tasks, then take it off the UI thread. You may use IntentService
  • Server not responding for longer period can be guilt for ANR. To avoid always define HTTP time out for your all your webs service calls.
  • Be watchful of infinite loops during your complex calculations

16. What is the difference between a regular .png and a nine-patch image?

The nine patch images are extension with .9.png. Nine-patch image allows resizing that can be used as background or other image size requirements for the target device. The Nine-patch refers to the way you can resize the image: 4 corners that are unscaled, 4 edges that are scaled in 1 axis, and the middle one that can be scaled into both axes.

17. How to share text using android share Intent ?

Share intent is an easy and convenient way of sharing content of your application with other apps.
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This
is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);

18. What is the use of WebView in android?

A WebView is an android UI component that displays webpages. It can either display a remote webpage or can also load static HTML data. This encompasses the functionality of a browser that can be integrated to application. WebView uses the WebKit rendering engine to display web pages and includes methods to navigate forward and backward through a history, zoom in and out, etc.

19. Define different kind of context in android

Context defines the current state of application or object. Context provides access to things such as creating new activity instance, access databases, start a service, etc. You can get the context by invoking getApplicationContext(), getContext(), getBaseContext() or this when in the activity class.
//Creating ui instance
ImageButton button = new
ImageButton(getContext());

//creating adapter
ListAdapter adapter = new
SimpleCursorAdapter(getApplicationContext(), ...);

//querying content provider
getApplicationContext().getContentResolver().query(uri,
...);

//start activity. Here this means activity
context
Intent intent = new
Intent(this, SecondActivity.class);

20. What are the different storage methods in android

Android offers several different options for data persistence.
  1. Shared Preferences – Store private primitive data in key-value pairs. This sometimes gets limited as it offers only key value pairs. You cannot save your own java types.
  2. Internal Storage – Store private data on the device memory
  3. External Storage – Store public data on the shared external storage
  4. SQLite Databases – Store structured data in a private database. You can define many number of tables and can store data like other RDBMS.

Monday, 29 June 2015

Android Interview Question Part-1


 

1. What is an Explicit Intent?

- Explicit intent specifies the particular activity that should respond to the intent.
- They are used for application internal messages.

2. What is an Implicit Intent?

- In case of Implicit Intent, an intent is just declared.
- It is for the platform to find an activity that can respond to it.
- Since the target component is not declared, it is used for activating components of other applications.

3. What do intent filters do?

- There can be more than one intents, depending on the services and activities that are going to use them.
- Each component needs to tell which intents they want to respond to.
- Intent filters filter out the intents that these components are willing to respond to.

4. Where are lay out details placed? Why?

- Layout details are placed in XML files
- XML-based layouts provide a consistent and standard means of setting GUI definition format.
5. What is Android?
an open-source operating system used for smartphones and tablet computers.
6. ADT stand for?
Android Developer Tools
7. SDK stand for ?
Software Development Kit
8. Language Know to develop android apps?
Java
XML
9. What is Intent?
An Intent is exactly what it describes. It's an "intention" to do an action.

An Intent is basically a message to say you did or want something to happen. Depending on the intent, apps or the OS might be listening for it and will react accordingly.

There are two types of intents in android:
  • Implicit Intent
  • Explicit Intent

10. What is AVD?
AVD Stand for Android Virtual Device (emulator), The Android SDK includes a mobile device emulator - a virtual mobile device that runs on your computer.

Sunday, 21 June 2015

Windows Phone Interview Questions Part1

1. Style:
A Style is basically a collection of property settings applied to multiple instances of the same type. AStyle contains a collection of one or more Setter objects. Each Setter has a Property and a Value. TheProperty is the name of the property of the element the style is applied to. The Value is the value that is applied to the property.
Implicit Styles: For example, if you create a style implicitly for all the ToggleButton controls in your application, and your application has ToggleButton and CheckBox controls (CheckBox derives from ToggleButton), the style is applied only to the ToggleButton controls.
BasedOn Styles: It is possible to build a new style based on an existing style. You can do this using the BasedOnproperty. This reduces the duplication of code and makes it easier to manage resources. Each style supports only one BasedOn style. 
2. UserControl:
Provides the base class for defining a new control that encapsulates related existing controls and provides its own logic.

3. LifeCycle Of WindowsPhone:
  App Launching=>Running=> OnNavigatedFrom(NavigationEventArgs)=>deactivated=>dormanent (stopped and no processing takes place)=>tombstoned(app has been terminated and it will be relaunched and the application can use the preserved data to restore state) =>Activated=> OnNavigatedTo(NavigationEventArgs) =>Closing=>raised when the user navigates backwards past the first page of an app
4. ContentTemplate:
Gets or sets the data template used to display the content of the ContentControl
ControlTemplate: Specifies the visual structure and behavioral aspects of a Control that can be shared across multiple instances of the control..
Control: Represents the base class for UI elements that use a ControlTemplate to define their appearance.
5. DataTemplate:
Describes the visual structure of a data object.
6. ItemTemplate:
·         Gets or sets the custom content for the data item in a control.ex:listbox
·         ItemsControl: Represents a control that can be used to present a collection of items.
·         ItemsPresenter: Specifies where items are placed in a control, usually an ItemsControl.
·          ItemPanelTemplate:specify the panel used to arrange the children of your ListBox.
·         ItemSource: Gets or sets a collection used to generate the content of the ItemsControl.
7. Layouts:
Windows Phone provides a flexible layout system that enables you to specify how controls are positioned on the screen.
i)Absolute layout(Canvas): you arrange child elements in a layout panel by specifying their exact locations relative to their parent element
ii)Dynamic Layout(Stack Panel,Grid): To use automatic or proportional sizing, you must assign special values to the Height andWidth properties.
8. StackPanel Vs Grid Vs Canvas Vs WrapPanel:
StackPanel: The StackPanel is a simple layout panel that arranges its child elements into a single line that can be oriented horizontally or vertically. 
Grid: The Grid control is the most flexible layout panel, and supports arranging controls in multi-row and multi-column layouts.
Canvas:  Canvas is useful for scenarios where the UI elements contained within it never move.
WrapPanel or WrapGrid : Positions child elements sequentially from left to right or top to bottom. When elements extend beyond the container edge, elements are positioned in the next row or column. In Windows Phone 8, consider using the WrapPanel available in the Windows Phone Toolkit.
9. What is  Diff B/W Grid column_2  2* and column_4  2*:
Suppose there  4 columns in grid
Column _2  2*: After the Auto columns are calculated, the column gets part of the remaining width. Column 2 will be one-half as wide as Column 4.
Column _4  2*: After the Auto columns are calculated, the column gets part of the remaining width. Column 4 will be two times as wide as Column 2.
10. Panel:
Provides a base class for all Panel elements. Use Panel elements to position and arrange child objects in Windows Phone applications.

Thursday, 18 June 2015

Java Decompiler installation in LINUX



Download jd-gui from here.

Then install few libraries as show in this tutorial.


$ sudo apt-get install libgtk2.0-0:i386
$ sudo apt-get install libxxf86vm1:i386
$ sudo apt-get install libsm6:i386
$ sudo apt-get install lib32stdc++6
$ ./jd-gui 
 
 
And it works..,

How to install Android Studio on Windows Operating System



  1. First you need to install latest version of JDK. you will get the latest version of jdk here. Download it,
  2. Install latest jdk on your Computer.
  3. Set path of jdk to the system variable as 
  4. Go to computer properties
  5. Advance option
  6. go to system variable and add new variable as "JAVA_HOME"
  7. add set the path of the jdk excluding bin.
  8. Download and install Android Studio from here