Thursday, 28 April 2016

Women safety and security android app

Download Link:

https://play.google.com/store/apps/details?id=comm.Kishlay.screamDetector&hl=en

"Chilla" is a personal safety & security app that can be triggered by just a shrill scream . It totally removes the hassles of unlocking the phone or opening the app. It has been found that in cases where someone follows a girl / women or eve-teases her , she generally doesn't calls out to parents or police and if they attack her , the app is of no use to her then. In that situation scream is a natural reaction and tapping that is the best possible way to bring her help.
The apps can be triggered by:
1. Scream
2.Pressing power Button 5 times
After Trigger, it does the following
1.Sends SMS with location
2.Sends Email with Audio Recording
3.Automatically places a call
If a scream is detected the app automatically unlocks the phone and places a call to the guardian.
The power button feature works even if the app is not on.
It virtually acts as your personal guardian angel when you are in distress and goes a long way in ensuring your personal safety so that With an elegant yet simple interface it is extremely simple to use.
Not just the safety of women, the safety mode can be additionally customized to cater to the safety 
of men too. Besides, the app can be used in case of emergencies too, for example during a heart 
attack, the victim’s location and recording can be immediately sent without unlocking the phone.
The best part is, Scream Alert is absolutely free, and it is made for the sole motive of helping women 
lead freer and safer lives. A revolution in field of personal security, Scream Alert is your ultimate 
safety app, install it today and put your safety in your own hands. Don’t just take our word for it, try 
it.
 This app has been acknowledged by Indian Government and they has put it on their website:
https://apps.mgov.gov.in/descp.do?appid=1065&param=citizenapps


Sunday, 31 January 2016

Monday, 30 November 2015

Sunday, 29 November 2015

schedule a repeating task

timer = new Timer();

    timer.scheduleAtFixedRate(new TimerTask() {

        synchronized public void run() {

            \\ here your todo;
            }

        }}, 60000, 60000);
 
 
http://stackoverflow.com/questions/14376470/scheduling-recurring-task-in-android
 
timer = new Timer();
TimerTask task = new TimerTask(){

    @Override    public void run() {
        new GetJson().execute(url);
    }

};
long whenToStart = 5*1000L; // 5 secondslong howOften = 5*1000L; // 5 secondstimer.scheduleAtFixedRate(task, whenToStart, howOften); 

heads up notification 2

private void showNotification(boolean showAsHeadsUp)
{
    final Intent intent = getIntent();
    intent.putExtra("launched_from_notification", true);

    final Notification.Builder nb = new Notification.Builder(this);
    nb.setContentTitle("Foobar");
    nb.setContentText("I am the content text");
    nb.setOngoing(true);
    nb.setSmallIcon(android.R.drawable.ic_dialog_info);
    nb.setContentIntent(PendingIntent.getActivity(
            this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));
    nb.setPriority(Notification.PRIORITY_HIGH);

    // Notifications without sound or vibrate will never be heads-up    nb.setDefaults(showAsHeadsUp ? Notification.DEFAULT_ALL : 0);

    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(0, nb.build());
}

heads up notification

private void showHeadsUpNotification()
{
    final Notification.Builder nb = new Notification.Builder(this);
    nb.setContentTitle("Foobar");
    nb.setContentText("I am the content text");
    nb.setDefaults(Notification.DEFAULT_ALL);
    nb.setOngoing(true);
    nb.setSmallIcon(android.R.drawable.ic_dialog_info);
    nb.setContentIntent(PendingIntent.getActivity(this, 0, getIntent(), 0));

    // Commenting this line 'fixes' it by not making it heads-up, but that's    // not what I want...    nb.setPriority(Notification.PRIORITY_HIGH);

    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(0, nb.build());
}

Saturday, 28 November 2015

delay any event in android

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
  @Override
  public void run() {
    //Do something after 100ms
  }
}, 100);

Thursday, 29 October 2015

php to send json

<?php
$servername = "localhost";
$username   = "root";
$password   = "";
$database   = "userdata";
$connect    = mysql_connect($servername, $username, $password);
$check      = mysql_select_db($database, $connect);
if (!$check) {
    echo"not connected bro";
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
   
    $name     = $_POST['name'];
   
    $username = $_POST['username'];
   
   
    $password = $_POST['password'];
   
   
    if ($name == '' || $username == '' || $password == '' ) {
        echo 'please fill all values';
    } else {
        $numrow = 0;
      
       
        if ($numrow > 0) {
            echo "values already exist";
        } else {
            $sql    = "INSERT INTO `uesr` (`id`, `username`, `password`) VALUES (NULL, '$username', '$password')";
           
            $result = mysql_query($sql);
            echo "successfully resgistered";
        }
    }
}
?>

Tuesday, 27 October 2015

login system registration

http://www.simplifiedcoding.net/android-login-and-registration-with-php-mysql/

http://stackoverflow.com/questions/22830251/refreshing-screen-which-uses-json-in-android

creating php script for json parsing
http://www.simplifiedcoding.net/android-json-parsing-retrieve-from-mysql-database/

Tuesday, 6 October 2015

programming with sensors

 class implements SensorEventListener





SensorManager sm=(SensorManager) getSystemService(Context.SENSOR_SERVICE);if(    sm.getSensorList(Sensor.TYPE_ACCELEROMETER).size()!=0)
{
    Sensor s=sm.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0);    sm.registerListener(this,s,SensorManager.SENSOR_DELAY_NORMAL);}
 
in the function public void onSensorChanged(SensorEvent event)
Sensor ss=event.sensor;
if(ss.getType()==Sensor.TYPE_ACCELEROMETER){
senx=event.values[0];seny=event.values[1];senz=event.values[2];  

update gallary after saving any image

Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, pictureUri);sendBroadcast(intent);

Save Photo from Camera in Android, Fix NullPointerException

https://www.youtube.com/watch?v=IMomzqwTuKA


package com.kishlay.raj.vbicam;
import android.content.Intent;import android.graphics.Bitmap;import android.media.MediaScannerConnection;import android.net.Uri;import android.os.Environment;import android.provider.MediaStore;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.util.Log;import android.view.Gravity;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.ImageView;import android.widget.Switch;import android.widget.TextView;import android.widget.Toast;
import java.io.File;import java.io.FileOutputStream;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Random;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    EditText name,emailId,lname;    public static final int MEDIA_TYPE_IMAGE = 1,MEDIA_TYPE_VIDEO=2;    Button button;    ImageView im;    Intent intent;    TextView tv1;    static final int cameraData=0;    private Uri fileUri;    Bitmap bm;    String First_name,Last_name,email;    Uri pictureUri;    private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        initialize();    }

    private void initialize() {
        name=(EditText)findViewById(R.id.name);        lname=(EditText)findViewById(R.id.last);        emailId=(EditText)findViewById(R.id.email);        button=(Button)findViewById(R.id.button);        im=(ImageView)findViewById(R.id.imageView);        button.setOnClickListener(this);    }


    @Override    public void onClick(View v) {
        switch(v.getId())
        {
            case R.id.button:
                /*i=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);                //File file = getOutputMediaFile(1); // create a file to save the image                 fileUri = Uri.fromFile(file);                i.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);                startActivityForResult(i,CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);*/
                intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);                First_name=name.getText().toString();                Last_name=lname.getText().toString();                email=emailId.getText().toString();                File pictureDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);                String pictureName=First_name+"_"+Last_name+"_"+email+".jpg";                File imgFile=new File(pictureDirectory,pictureName);                 pictureUri=Uri.fromFile(imgFile);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri); // set the image file name
                // start the image capture Intent                startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);                Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, pictureUri);                sendBroadcast(intent);
                break;        }


    }

    @Override    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);        if(requestCode==CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE)
        {
            if(resultCode==RESULT_OK)
            {
                //set text that image has been saved                Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, pictureUri);                sendBroadcast(intent);                Toast t= Toast.makeText(MainActivity.this,"Image Saved :)",5000);                t.setGravity(Gravity.CENTER, 0, 0);                t.show();            }
            else            {
                // try again message                Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, pictureUri);                sendBroadcast(intent);                Toast t= Toast.makeText(MainActivity.this,"Plz try again :(",5000);                t.setGravity(Gravity.CENTER, 0, 0);                t.show();            }
        }
    }
}

Friday, 2 October 2015

Splsh screen using handler

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.peace);
    new Handler().postDelayed(new Runnable() {
        @Override        public void run() {
            Intent mainIntent= new Intent(MainActivity.this,peace.class);
            MainActivity.this.startActivity(mainIntent);
        }
    },1000);
}

Wednesday, 30 September 2015

print a random number every second

package com.example.raj.testview;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.ThemedSpinnerAdapter;

import java.util.Random;
import java.util.TimerTask;



public class MainActivity extends AppCompatActivity {
    TextView tv;
    Handler handler;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         tv=(TextView)findViewById(R.id.tv);
        Thread th=new Thread(new MyThread());
        th.start();
        handler=new Handler(){
            @Override            public void handleMessage(Message msg) {
                //super.handleMessage(msg);                int k=msg.arg1;
                tv.setText(Integer.toString(k));
            }
        };


    }

    class MyThread implements Runnable{


        @Override        public void run() {

            for(int i=0;i<100;i++)
            {
                Message message=Message.obtain();
                Random r=new Random();
                int y=r.nextInt();
                message.arg1=y;
                handler.sendMessage(message);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    @Override    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will        // automatically handle clicks on the Home/Up button, so long        // as you specify a parent activity in AndroidManifest.xml.        int id = item.getItemId();

        //noinspection SimplifiableIfStatement        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

Saturday, 26 September 2015

custom button


Custom button
other than having a png image in drawable we also need a xml in drawable the will totally define the button that we have
xml example

<item android:state_presses="true" android:drawable="@drawable/plusselected"></item>
<item android:state_focused="true" android:drawable="@drawable/plushlight"></item>
<item android:drawable="@drawable/plus"></item>


now in the xml where the actual button resides , we should change the
layout width and height to wrap_content , so that the image remains to itself
and the background of the button should be @drawable/ourxml

Create a ListMenu for Android

Create a ListMenu for Android

unlike other classes our class for Listmenu will extend ListActivity not Activity

two methods need to be overrided here
1.onCreate like we did previously
2.onListItemClick

 Then we set up a String array (as instance varible bcz we want to use it in both the methods)
 String classes[]={"startingPoint","example1","example2","example3"};// we will name it exact same as the class name(case sensitive)

 we will not use any layout here,
 we will develop all in java here

 now we need to set setListAdapter(); // it takes a array adapter or a list adapter
 setListAdapter(new ArrayAdapter<String>(context,int,StringArray));//<> gives the type
 cotext= ClassName.this
 StringArray =classes
 int = android.R.layout.simple_list_item1

 for any of the list item when clicked it will call method onListItemClick

 WE need one more method now,
 3.onListItemClick
 the function has a parameter called position which will tell us about the item clicked
 we now set up a local string there
 String cheese= classes[position];// classes was our global string array containing the names of all the classes
 so now we can setup our class for intent according to the list item that was clicked

 Class ourclass- Class.forName("com.thenewboston.travis."+cheese);// will return the class name of particular class which has the intent filter in the manifest

 Intent ourIntent= new Intent(Menu.this, ourClass);
 startActivity(ourIntent);


 

onClick function

declaring a single onClick function for all instead of using all innerClass stuff

first we need to implements View.OnClickListener

then in the onClick funtion which recives View as parameter
we need to setup swich Case to know which element has been clicked
so in the the switch case we need to write

switch(view.getId())
{
case R.id.b1: .......;break;
case R.id.b2: .......;break;
}

email

Sending email from android
using android email Intent

Intent emailIntent= new Intent(android.content.Intent,ACTION_SEND);
emailIntent.putExtra(messsage,value);
emailIntent.putExtra(android.content.Intent.Extra_EMAIL, String array value of email address(emailAdress));//adding email array

//adding subject
emailIntent.putExtra(android.content.Intent.Extra_SUBJECT, "this is my subject area");

//adding message
emailIntent.putExtra(android.content.Intent.Extra_TEXT, message);

//we can also setup text as plain type in case we are using encoding as /n and all
emailIntent.setType("plain/text");

finally start the intent
startActivity(emailIntent);