Friday, 25 April 2014
Tuesday, 22 April 2014
Latitude and longitude finder
Java Class to Access longitude and latitude of device.
package com.example.locationmanager;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
double latitude = 0, longitude = 0;
LocationManager lman;
String provider =null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button traceme =(Button)findViewById(R.id.Trackme);
traceme.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
lman =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
if(lman.isProviderEnabled(LocationManager.GPS_PROVIDER))
provider=LocationManager.GPS_PROVIDER;
if (lman.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
provider=LocationManager.NETWORK_PROVIDER;
if (provider!=null) {
lman.requestLocationUpdates(provider, 10000, 10, listener);
Log.v(provider, "This is current provider");
} else {
Log.v(provider, "No provider");
}
}
});
}
@Override
protected void onDestroy() {
lman.removeUpdates(listener);
// TODO Auto-generated method stub
super.onDestroy();
}
LocationListener listener =new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onLocationChanged(Location location) {
longitude =location.getLatitude();
latitude =location.getLongitude();
Toast.makeText(MainActivity.this,
"longitude: "+longitude + " \n latitude: " + latitude,
Toast.LENGTH_SHORT).
show();
Log.v(longitude +"= Longitude" +latitude +" = latitude", "result");
}
};
@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;
}
}
( Copy DB file to /mnt/sdcard ) And ( Copy DB file From /mnt/sdcard )
// updated on 12-12-2016
public static void copyAppDbToDownloadFolder(Context ctx) { try { File backupDB = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "BK_NITHIN.db"); // for example "my_data_backup.db" File currentDB = ctx.getDatabasePath("NITHIN.db"); if (currentDB.exists()) { FileInputStream fis = new FileInputStream(currentDB); FileOutputStream fos = new FileOutputStream(backupDB); fos.getChannel().transferFrom(fis.getChannel(), 0, fis.getChannel().size()); fis.close(); fos.close(); System.out.println("Copying Database success, reason:"); } else System.out.println("Copying Database fail, reason:"); } catch (IOException e) { System.out.println("Copying Database fail, reason:"); } }
private static Context ctx;
private static String DB_PATH = "/data/data/<package name>./databases/";
private static String DB_NAME = "DbName-Here";
Copy DB file to /mnt/sdcard
public static void pullDB(Context ctx) {
File curDB = ctx.getDatabasePath("//DbName-Here");
File bakupDB = new File(Environment.getExternalStorageDirectory(),
"DbName-Here");
try {
FileChannel src = new FileInputStream(curDB).getChannel();
FileChannel dst = new FileOutputStream(bakupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
Toast.makeText(
ctx,
"DB copied to " + Environment.getExternalStorageDirectory(),
Toast.LENGTH_LONG).show();
}
}
Copy DB file From /mnt/sdcard
public static void pushDB(Context ctx) {
try {
InputStream mInputStream = ctx.getAssets()
.open("DbName-Here");
String outFileName = ctx.getDatabasePath("DbName-Here")
.toString();
OutputStream mOutputStream = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = mInputStream.read(buffer)) > 0) {
mOutputStream.write(buffer, 0, length);
}
mOutputStream.flush();
mOutputStream.close();
mInputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Sliding drawer with its Function
Sliding drawer with its Function
XML Layout
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bgtwo"
tools:ignore="MergeRootFrame" >
<SlidingDrawer
android:id="@+id/SlidingDrawer01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:content="@+id/LinearLayout01"
android:handle="@+id/Button05"
android:orientation="vertical"
android:padding="10dip" >
<Button
android:id="@+id/Button05"
android:layout_width="100dp"
android:layout_height="90dp"
android:background="@drawable/arrow_up" />
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/sendme"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="10dp"
android:background="@drawable/sendme" />
<Button
android:id="@+id/sendall"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="10dp"
android:background="@drawable/sendall" />
<Button
android:id="@+id/position"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginLeft="100dp"
android:background="@drawable/position" />
</LinearLayout>
</SlidingDrawer>
</FrameLayout>
Add caption |
Java Class
public class HomeActivity extends ActionBarActivity {
SlidingDrawer slidingDrawer;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
public void onDrawerOpened() {
Button05.setBackgroundResource(R.drawable.arrow_down);
}
});
slidingDrawer.setOnDrawerCloseListener(new nDrawerCloseListener() {
public void onDrawerClosed() {
Button05.setBackgroundResource(R.drawable.arrow_up);
}
});
}
}
Mobile Messaging Through Network (Integrated SlidingDrawer)
Framelayout with sliding drawer.
Sliding Menu has three option
1.custom message and send to one person.
2.custom/non-custom message and send to one person/multiple person.3.Send location (longitude/latitude).
Dashboard-XML
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bgtwo"
tools:ignore="MergeRootFrame" >
<SlidingDrawer
android:id="@+id/SlidingDrawer01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:content="@+id/LinearLayout01"
android:handle="@+id/Button05"
android:orientation="vertical"
android:padding="10dip" >
<Button
android:id="@+id/Button05"
android:layout_width="100dp"
android:layout_height="90dp"
android:background="@drawable/arrow_up" />
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/sendme"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="10dp"
android:background="@drawable/sendme" />
<Button
android:id="@+id/sendall"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="10dp"
android:background="@drawable/sendall" />
<Button
android:id="@+id/position"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginLeft="100dp"
android:background="@drawable/position" />
</LinearLayout>
</SlidingDrawer>
</FrameLayout>
========================================================================
Dashboard-Java Class
==========package com.example.mychoir;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import android.content.Context;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SlidingDrawer;
import android.widget.Toast;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;
@SuppressWarnings("deprecation")
public class HomeActivity extends ActionBarActivity {
Button slideButton,sendme,sendall,position;
SlidingDrawer slidingDrawer;
double latitude = 0, longitude = 0;
LocationManager lMan;
String phn ="9605252521";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
initilization();
lMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
String provider = null;
if ( lMan.isProviderEnabled(LocationManager.NETWORK_PROVIDER ) )
provider = LocationManager.NETWORK_PROVIDER;
else if (lMan.isProviderEnabled(LocationManager.GPS_PROVIDER ) )
provider = LocationManager.GPS_PROVIDER;
if(provider != null) {
Log.v("lMan", "listener REGISTERED");
lMan.requestLocationUpdates(provider, 10000, 10, lListener);
} else {
Log.e("lMan", "NO PROVIDERS!");
}
position.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Geocoder gcd = new Geocoder(getBaseContext(), Locale.getDefault());
List<Address> addresses = null;
try {
addresses = gcd.getFromLocation(latitude, longitude, 1);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
if (addresses != null & addresses.size() > 0){
System.out.println(addresses.get(0).getLocality());
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phn, null, " " +"Right now am in "+addresses.get(0).getLocality(), null, null);
Toast.makeText(getApplicationContext(),
" Message sent... "+addresses.get(0).getLocality(),
Toast.LENGTH_LONG).show();
}
else{
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phn, null, "Traced location via latitude= "+latitude +" longitude= "+longitude+"" , null, null);
Toast.makeText(getApplicationContext(),
"Message sent... = "+latitude +" longitude= "+longitude+"",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild !! LocationService in phone settings, is not configured ",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
sendme.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), SmsActivity.class);
intent.putExtra("MSGType","single");
startActivity(intent);
// TODO Auto-generated method stub
}
});
sendall.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), SmsActivity.class);
intent.putExtra("MSGType","multiple");
startActivity(intent);
// TODO Auto-generated method stub
}
});
slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
public void onDrawerOpened() {
slideButton.setBackgroundResource(R.drawable.arrow_down);
}
});
slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
public void onDrawerClosed() {
slideButton.setBackgroundResource(R.drawable.arrow_up);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home, menu);
return true;
}
public void initilization(){
slideButton=(Button)findViewById(R.id.Button05);
sendme=(Button)findViewById(R.id.sendme);
sendall=(Button)findViewById(R.id.sendall);
position=(Button)findViewById(R.id.position);
slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer01);
}
LocationListener lListener = new LocationListener() {
public void onLocationChanged(Location location) {
longitude = location.getLongitude();
latitude = location.getLatitude();
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
public void onProviderEnabled(String provider) {
}
public void onProviderDisabled(String provider) {
}
};
}
SMS Layout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="20dp"
android:background="@drawable/bgtwo"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/editTextSMS"
android:layout_width="fill_parent"
android:layout_height="135dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginTop="20dp"
android:background="@drawable/bgsix"
android:hint="Enter SMS Message "
android:inputType="textShortMessage"
android:singleLine="false"
android:text=" "
android:textColor="@color/white"
android:textSize="30dp"
android:textStyle="bold"
android:visibility="gone" >
</EditText>
<Spinner
android:id="@+id/spinnerSMS"
android:layout_width="531dp"
android:layout_height="50dp"
android:layout_margin="10dp"
android:layout_marginTop="20dp"
android:background="@drawable/bgfour"
android:gravity="center"
android:textSize="30dp"
android:visibility="visible" >
</Spinner>
<TimePicker
android:id="@+id/spinnerTime"
android:layout_width="531dp"
android:layout_height="100dp"
android:layout_margin="10dp"
android:layout_marginTop="20dp"
android:background="@drawable/bgfour"
android:gravity="center"
android:textSize="30dp"
android:visibility="visible"
/>
<Button
android:id="@+id/buttonSend"
android:layout_width="233dp"
android:layout_height="71dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="@drawable/bgsix"
android:text="Send Message Admin"
android:textColor="@color/white"
android:textStyle="bold" />
</LinearLayout>
</FrameLayout>
========================================================================
SmS Layout Java Class
========================================================================
package com.example.mychoir;
import java.util.Calendar;
import android.app.Activity;
import android.app.ActionBar.OnNavigationListener;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TimePicker;
import android.widget.Toast;
public class SmsActivity extends Activity{
String phn="9605252521";
Button buttonSend;
EditText editTextSMS;
Spinner spinnerSMS;
TimePicker spinnerTime;
String[]phns={"9605252521"};
String Days[] = {"MonDay", "TuesDay", "WedsDay", "ThursDay", "FriDay", "SaterDay", "SunDay"};
String MsgType="";
private int hour;
private int minute;
String slelectedtime="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.smslayout);
buttonSend=(Button)findViewById(R.id.buttonSend);
editTextSMS=(EditText)findViewById(R.id.editTextSMS);
spinnerSMS=(Spinner)findViewById(R.id.spinnerSMS);
spinnerTime=(TimePicker)findViewById(R.id.spinnerTime);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, Days);
spinnerArrayAdapter.setDropDownViewResource(R.drawable.spinneritem); // The drop down view
spinnerSMS.setAdapter(spinnerArrayAdapter);
final Calendar c = Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
spinnerTime.setCurrentHour(hour);
spinnerTime.setCurrentMinute(minute);
Bundle extras = getIntent().getExtras();
if (extras != null) {
MsgType = extras.getString("MSGType");
Log.v("MSGType", MsgType);
if (MsgType.equals("single")) {
spinnerSMS.setVisibility(View.GONE);
spinnerTime.setVisibility(View.GONE);
editTextSMS.setVisibility(View.VISIBLE);
}else {
buttonSend.setText("Send to All");
spinnerSMS.setVisibility(View.VISIBLE);
spinnerTime.setVisibility(View.VISIBLE);
editTextSMS.setVisibility(View.GONE);
}
}else {
}
buttonSend.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String message=editTextSMS.getText().toString();
if(MsgType.equals("multiple")){
if(message.equals("")|| message.equals(null)){
for(int i=0;i<phns.length;i++){
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phns[i], null, "", null, null);
Log.v("Sent to", phns[i]);
Toast.makeText(getApplicationContext(),
phns[i]+" Blank Message sent..." ,
Toast.LENGTH_LONG).show();
}
}
else{
for(int i=0;i<phns.length;i++){
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phns[i], null,"The next meeting of the Choir Committee will take place on "+ spinnerSMS.getSelectedItem().toString()+ " in St.Sebastian Church Puranattukara at ."(hour,minute), null, null);
Log.v("Sent to", phns[i]);
Toast.makeText(getApplicationContext(),
phns[i]+" Message sent ..." ,
Toast.LENGTH_LONG).show();
}
}
}
if (MsgType.equals("single")) {
if(message.equals("")|| message.equals(null)){
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phn, null, "", null, null);
Toast.makeText(getApplicationContext(),
phn+" Blank Message sent..." ,
Toast.LENGTH_LONG).show();
}
else{
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phn, null, message, null, null);
Toast.makeText(getApplicationContext(),
phn+" Message sent..." ,
Toast.LENGTH_LONG).show();
}
}
Intent intent = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(intent);
}
});
}
}
Subscribe to:
Posts (Atom)
How to do text writing animation? In Android Development we do not have the option to use any other custom font in our default Tex...
-
Smartphone notifications are pretty useful, there's no denying that. They make it hard to miss an important event, such as an upcom...
-
Microsoft Translator is a hosted service, accessed via an API that provides language translation. It can be used to build Android Applicat...
-
Text To Speech It is a great piece of technology that was developed to help individuals with visual impairments. However, dev...