Thursday, February 19, 2015

Asterisk Uninstallation

 ASTERISK UNINSTALLATION


It is sometimes necessary to completely remove Asterisk for one machine, for example because you need to install a newer version.

Stop Asterisk and unload its modules
The first thing you have to do is to stop Asterisk and unload the modules it may be using, e.g Zaptel's.

The following lines will brutally terminate Asterisk and kill all ongoing conversation. You have to kill safe_asterisk first, otherwise it will respawn Asterisk.

killall -9 safe_asterisk
killall -9 asterisk

Then you'll have to unload the Zaptel drivers; check which ones are loaded by issuing a:

[root@zebru]# lsmod | grep zaptel
zaptel 214820 2 wcfxo,wctdm
crc_ccitt 2113 1 zaptel

This means that the submodules wcfxo and wctdm are loaded for zaptel. We'll have to remove them in reverse order:

modprobe -r wcfxo
modprobe -r wctdm
..repeat for all zaptel submodules....
modprobe -r zaptel

If you repeat the lsmod | grep zaptel command now, it should find nothing.

Delete Asterisk files
By running the commands below, you will delete with no possible recovery an Asterisk system. First make a backup of things you'd like to keep, lik ethe log files or the configuration files.
star Remember: once you run these commands, there's no turning back!

rm -rf /etc/asterisk
rm -f /etc/zaptel.conf
rm -rf /var/log/asterisk
rm -rf /var/lib/asterisk
rm -rf /var/spool/asterisk
rm -rf /usr/lib/asterisk

Now your Asterisk system has been completely removed.


Freepbx Uninstallation

FREEPBX UNINSTALLATION

These Steps will completely erase your FreePBX settings. There is NO going back. Please make note of this and make the required backups

To uninstall FreePBX 2.11 from a machine, access the machine using the Linux command prompt:
  1. Find and locate the ./install_amp file. Or redownload from SVN. And simply run this command.
 ./install_amp --uninstall

Alternatively To Manually uninstall FreePBX from a CentOS machine follow the below steps, access the machine using the Linux command prompt:
1.  Drop the tables from MySQL.  Access the MySQL command line interface by typing:
mysql -u root
Then instruct MySQL to drop the asterisk and asteriskcdr databases by typing:
DROP DATABASE asterisk;
and then
DROP DATABASE asteriskcdr;
and then type
exit;
to exit from the MySQL command line.
2.  Delete the FreePBX related files by issuing the following commands:
rm /usr/sbin/amportal
rm -rf /var/lib/asterisk/bin/*
rm -rf /var/www/html/*
rm /etc/amportal.conf
rm /etc/asterisk/amportal.conf
rm /etc/freepbx.conf
rm /etc/asterisk/freepbx.conf
rm -f /etc/asterisk/*.conf

Wednesday, February 18, 2015

Accessing Resources in Android

Accessing Resources
During your application development you will need to access defined resources either in your code, or in your layout XML files. Following section explains how to access your resources in both the scenarios:
ACCESSING RESOURCES IN CODE:
When your Android application is compiled, a R class gets generated, which contains resource IDs for all the resources available in your res/ directory. You can use R class to access that resource using sub-directory and resource name or directly resource ID.
EXAMPLE:
To access res/drawable/myimage.png and set an ImageView you will use following code:
ImageView imageView = (ImageView) findViewById(R.id.myimageview);
imageView.setImageResource(R.drawable.myimage);
Here first line of the code makes use of R.id.myimageview to get ImageView defined with idmyimageview in a Layout file. Second line of code makes use of R.drawable.myimage to get an image with name myimage available in drawable sub-directory under /res.
EXAMPLE:
Consider next example where res/values/strings.xml has following definition:
< ?xml version="1.0" encoding="utf-8"? >
< resources >
< string name="hello" > Hello, World! < /string >
< /resources >


Accessing Resources using xml in Android

Accessing Resources in xml
Consider the following resource XML res/values/strings.xml file that includes a color resource and a string resource:
< ?xml version="1.0" encoding="utf-8"? >
< resources >
< color name="opaque_red" > #f00 < /color >
< string name="hello" > Hello! < /string >
< /resources >
Now you can use these resources in the following layout file to set the text color and text string as follows:
< ?xml version="1.0" encoding="utf-8"? >
< EditText xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="@color/opaque_red"
android:text="@string/hello" / >
Now if you will go through previous chapter once again where I have explained Hello World! Example, and I ' m sure you will have better understanding on all the concepts explained in this chapter. So I highly recommend to check previous chapter for working example and check how I have used various resources at very basic level.


Android Alert Dialog

Android Alert Dialog
Some times in your application , if you wanted to ask the user about taking a decision between yes or no in response of any particular action taken by the user, by remaining in the same activity and without changing the screen, you can use Alert Dialog.

In order to make an alert dialog, you need to make an object of AlertDialogBuilder which an inner class of AlertDialog. Its syntax is given below
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
Now you have to set the positive (yes) or negative (no) button using the object of the AlertDialogBuilder class. Its syntax is
alertDialogBuilder.setPositiveButton(CharSequence text, DialogInterface.OnClickListener listener)
alertDialogBuilder.setNegativeButton(CharSequence text, DialogInterface.OnClickListener listener)
Apart from this, you can use other functions provided by the builder class to customize the alert dialog. These are listed below
Sr.No
Method type & description
1
setIcon(Drawable icon)
This method set the icon of the alert dialog box.
2
setCancelable(boolean cancelable)
This method sets the property that the dialog can be cancelled or not
3
setMessage(CharSequence message)
This method sets the message to be displayed in the alert dialog
4
setMultiChoiceItems(CharSequence[] items, boolean[] checkedItems, DialogInterface.OnMultiChoiceClickListener listener)
This method sets list of items to be displayed in the dialog as the content. The selected option will be notified by the listener
5
setOnCancelListener(DialogInterface.OnCancelListener onCancelListener)
This method Sets the callback that will be called if the dialog is canceled.
6
setTitle(CharSequence title)
This method set the title to be appear in the dialog
After creating and setting the dialog builder, you will create an alert dialog by calling the create() method of the builder class. Its syntax is
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
This will create the alert dialog and will show it on the screen.
Example:
The following example demonstrates the use of AlertDialog in android. It uses three different activities to demonstrate it. The dialog asks you to jump to positive activity or negative activity or cancel it.

To experiment with this example, you need to run this on an emulator or an actual device.
Steps
Description
1
You will use Eclipse IDE to create an Android application and name it as AlertDialog under a package com.example.alertdialog. While creating this project, make sure you Target SDK and Compile With at the latest version of Android SDK to use higher levels of APIs.
2
Modify src/MainActivity.java file to add alert dialog code to launch the dialog.
3
Modify layout XML file res/layout/activity_main.xml add any GUI component if required.
4
Create a new activity called PositiveActivity and confim it by visiting src/PositiveActivity.java.
5
Modify layout XML file of the newly created activity res/layout/activity_positive.xml add any GUI component if required.
6
Create a new activity called NegativeActivity and confim it by visiting src/NegativeActivity.java.
7
Modify layout XML file of the newly created activity res/layout/activity_negative.xml add any GUI component if required.
8
Modify res/values/strings.xml to define required constant values
9
Run the application and choose a running android device and install the application on it and verify the results.
Here is the modified code of src/com.example.alertdialog/MainActivity.java
package com.example.alertdialog;
import com.example.alertdialog.*;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void open(View view)
{
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage(R.string.decision);
alertDialogBuilder.setPositiveButton(R.string.positive_button,
new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface arg0, int arg1)
{
Intent positveActivity = new Intent(getApplicationContext(),com.example.alertdialog.PositiveActivity.class);
startActivity(positveActivity);
}
});
alertDialogBuilder.setNegativeButton(R.string.negative_button,
new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Intent negativeActivity = new Intent(getApplicationContext(),com.example.alertdialog.NegativeActivity.class);
startActivity(negativeActivity);
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
@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;
}
}
Here is the default code of src/com.example.alertdialog/PositiveActivity.java
package com.example.alertdialog;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class PositiveActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_positive);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.positive, menu);
return true;
}
}
Here is the default code of src/com.example.alertdialog/NegativeActivity.java
package com.example.alertdialog;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class NegativeActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_negative);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.negative, menu);
return true;
}
}
Here is the modified code of res / layout / activity _ main.xml
< RelativeLayout xmlns:android= " http: / / schemas.android.com / apk / res / android "
xmlns:tools= " http: / / schemas.android.com / tools "
android:layout _ width= " match _ parent "
android:layout _ height= " match _ parent "
android:paddingBottom= " @dimen / activity _ vertical _ margin "
android:paddingLeft= " @dimen / activity _ horizontal _ margin "
android:paddingRight= " @dimen / activity _ horizontal _ margin "
android:paddingTop= " @dimen / activity _ vertical _ margin "
tools:context= " .MainActivity " >
< Button android:id= " @+id / button1 "
android:layout _ width= " wrap _ content "
android:layout _ height= " wrap _ content "
android:layout _ alignParentTop= " true "
android:layout _ centerHorizontal= " true "
android:layout _ marginTop= " 170dp "
android:onClick= " open "
android:text= " @string / hello _ world " / >
< / RelativeLayout >
Here is the modified code of res / layout / activity _ positive.xml
< RelativeLayout xmlns:android= " http: / / schemas.android.com / apk / res / android "
xmlns:tools= " http: / / schemas.android.com / tools "
android:layout _ width= " match _ parent "
android:layout _ height= " match _ parent "
android:paddingBottom= " @dimen / activity _ vertical _ margin "
android:paddingLeft= " @dimen / activity _ horizontal _ margin "
android:paddingRight= " @dimen / activity _ horizontal _ margin "
android:paddingTop= " @dimen / activity _ vertical _ margin "
tools:context= " .PositiveActivity " >
< TextView android:id= " @+id / textView1 "
android:layout _ width= " wrap _ content "
android:layout _ height= " wrap _ content "
android:layout _ alignParentLeft= " true "
android:layout _ alignParentTop= " true "
android:layout _ marginLeft= " 14dp "
android:layout _ marginTop= " 20dp "
android:text= " @string / positive "
android:textAppearance= " ?android:attr / textAppearanceLarge " / >
< / RelativeLayout >
Here is the modified code of res / layout / activity _ negative.xml
< RelativeLayout xmlns:android= " http: / / schemas.android.com / apk / res / android "
xmlns:tools= " http: / / schemas.android.com / tools "
android:layout _ width= " match _ parent "
android:layout _ height= " match _ parent "
android:paddingBottom= " @dimen / activity _ vertical _ margin "
android:paddingLeft= " @dimen / activity _ horizontal _ margin "
android:paddingRight= " @dimen / activity _ horizontal _ margin "
android:paddingTop= " @dimen / activity _ vertical _ margin "
tools:context= " .NegativeActivity " >
< TextView android:id= " @ + id / textView1 "
android:layout _ width= " wrap _ content "
android:layout _ height= " wrap _ content "
android:layout _ alignParentLeft= " true "
android:layout _ alignParentTop= " true "
android:layout _ marginLeft= " 14dp "
android:layout _ marginTop= " 17dp "
android:text= " @string / negative "
android:textAppearance= " ?android:attr / textAppearanceLarge " / >
< / RelativeLayout >
Here is the modified code ofStrings.xml
< ?xml version= " 1.0 " encoding= " utf-8 " ? >
< resources >
< string name= " app _ name " > AlertDialog < / string >
< string name= " action _ settings " > Settings < / string >
< string name= " hello _ world " > Hello world! < / string >
< string name= " title _ activity _ positive " > PositiveActivity < / string >
< string name= " title _ activity _ negative " > NegativeActivity < / string >
< string name= " positive " > Positive Activity < / string >
< string name= " negative " > Negative Activity < / string >
< string name= " decision " > Are you sure, you wanted to make this decision < / string >
< string name= " positive _ button " > + ive < / string >
< string name= " negative _ button " > -ive < / string >
< / resources >
Here is the default code of AndroidManifest.xml
< ?xml version= " 1.0 " encoding= " utf-8 " ? > < manifest xmlns:android= " http: / / schemas.android.com / apk / res / android "
package= " com.example.alertdialog "
android:versionCode= " 1 "
android:versionName= " 1.0 " >
< uses-sdk android:minSdkVersion= " 8 "
android:targetSdkVersion= " 17 " / >
< application android:allowBackup= " true "
android:icon= " @drawable / ic _ launcher "
android:label= " @string / app _ name "
android:theme= " @style / AppTheme " >
< activity android:name= " com.example.alertdialog.MainActivity "
android:label= " @string / app _ name " >
< intent-filter >
< action android:name= " android.intent.action.MAIN " / >
< category android:name= " android.intent.category.LAUNCHER " / >
< / intent-filter >
< / activity >
< activity android:name= " com.example.alertdialog.PositiveActivity "
android:label= " @string / title _ activity _ positive " >
< / activity >
< activity
android:name= " com.example.alertdialog.NegativeActivity "
android:label= " @string / title _ activity _ negative " >
< / activity >
< / application >
< / manifest >
Let ' s try to run your Camera application. I assume you have connected your actual Android Mobile device with your computer. To run the app from Eclipse, open one of your project ' s activity files and click Run icon from the toolbar. Before starting your application, Eclipse will display following window to select an option where you want to run your Android application.
Select your mobile device as an option and then check your mobile device which will display following screen:
Now just press the button hello world to see the alert box , which would be something like this


Now select any of the two buttons and see the respective activity loading up. In case you select positve button , this screen would appear
Now press back button on your device , and this time select negative from your alert dialog. The following screen would appear this time.








Easy Way to Handle Android Notifications

Android Notifications Android Toast class provides a handy way to show users alerts but problem is that these alerts are not persist...