Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Sunday, 2 March 2014

Android Notification example



final NotificationManager mgr =(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification note = new Notification(R.drawable.phone,"Vacant Class Notification..!", System.currentTimeMillis());
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

// This pending intent will open after notification click
PendingIntent i = PendingIntent.getActivity(this, 0,new Intent(this, NotificationReceiver.class), 0);
note.setLatestEventInfo(getApplicationContext(), "Vacant Class Notification..!",message, i);
note.sound = soundUri;

mgr.notify(0, note);

Sunday, 16 February 2014

Android Dynamic Check-box Example

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.Toast;

public class Attendance extends Activity {
CheckBox checkBox;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.stud_attendence);
LinearLayout my_layout = (LinearLayout) findViewById(R.id.my_layout);
LinkedHashMap<String, String> alphabet = new LinkedHashMap<String, String>();
// int Array_Count = 0;
String[] Str_Array = new String[] { "12111447:Arun Kumar",
"12111448:Aneesh", "12111449:Binoy shyam" };


for (int i = 0; i < Str_Array.length; i++) {
String[] std= Str_Array[i].split(":");
alphabet.put(std[0],std[1]);

}

Set<?> set = alphabet.entrySet();

Iterator<?> i = set.iterator();
while (i.hasNext()) {
@SuppressWarnings("rawtypes")
Map.Entry me = (Map.Entry) i.next();
checkBox = new CheckBox(this);
checkBox.setId(Integer.parseInt(me.getKey().toString()));
checkBox.setText(me.getKey().toString()+" : "+me.getValue().toString());
checkBox.setOnClickListener(getOnClickDoSomething(checkBox));
my_layout.addView(checkBox);
}

}

View.OnClickListener getOnClickDoSomething(final Button button) {
return new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(
getApplicationContext(),
"Id:" + button.getId() + " and text: "
+ button.getText().toString(), 2000).show();

}
};
}

}

Output:





Wednesday, 12 February 2014

Android Reading Inbox SMS

import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;

public class SMSRead extends Activity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      TextView view = new TextView(this);
      Uri uriSMSURI = Uri.parse("content://sms/inbox");
      Cursor cur = getContentResolver().query(uriSMSURI, null, null, null,null);
      String sms = "";
      while (cur.moveToNext()) {
          sms += "From :" + cur.getString(2) + " : " + cur.getString(11)+"\n";         
      }
      view.setText(sms);
      setContentView(view);
  }
}
Add below permission to AndroidManifest.xml
   
<uses-permission android:name="android.permission.READ_SMS" />