Tuesday, July 12, 2011
Intent.ACTION_SEND
Intent intent = new Intent(Intent.ACTION_SEND);
//intent.setType("application/octet-stream");
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, shareText);
intent.putExtra(Intent.EXTRA_TEXT, "Message: "+shareText+" - "+shareUrl);
Intent mailer = Intent.createChooser(intent, null);
startActivity(mailer);
//intent.setType("application/octet-stream");
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, shareText);
intent.putExtra(Intent.EXTRA_TEXT, "Message: "+shareText+" - "+shareUrl);
Intent mailer = Intent.createChooser(intent, null);
startActivity(mailer);
Monday, July 11, 2011
Prev and Next msg
onActivityResult:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode==202){
//Next
msg=msg_id1[++msg_cureentposition];
Intent i=new Intent(details.this,details1.class);
Bundle bundle = new Bundle();
if(msg_cureentposition==msg_length-1)
bundle.putBoolean("nextFlag",false);
else
bundle.putBoolean("nextFlag",true);
if(msg_cureentposition==0)
bundle.putBoolean("previousFlag",false);
else
bundle.putBoolean("previousFlag",true);
bundle.putString("ID",msg);
i.putExtras(bundle);
startActivityForResult(i,100);
}else if(resultCode==201){
//Previous
msg=msg_id1[--msg_cureentposition];
Intent i=new Intent(details.this,details1.class);
Bundle bundle = new Bundle();
if(msg_cureentposition==msg_length-1)
bundle.putBoolean("nextFlag",false);
else
bundle.putBoolean("nextFlag",true);
if(msg_cureentposition==0)
bundle.putBoolean("previousFlag",false);
else
bundle.putBoolean("previousFlag",true);
bundle.putString("ID",msg);
i.putExtras(bundle);
startActivityForResult(i,100);
}
}
LIstCiew onClickListner:
msg_length=msg_id1.length;
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView arg0, View arg1,
int pos, long arg3) {
// TODO Auto-generated method stub
Intent i=new Intent(details.this,details1.class);
msg_cureentposition=pos;
Bundle bundle = new Bundle();
if(msg_cureentposition==msg_length-1)
bundle.putBoolean("nextFlag",false);
else
bundle.putBoolean("nextFlag",true);
if(msg_cureentposition==0)
bundle.putBoolean("previousFlag",false);
else
bundle.putBoolean("previousFlag",true);
bundle.putString("ID",msg_id1[pos]);
i.putExtras(bundle);
startActivityForResult(i,100);
}
});
Prev ANd Next Button:
next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(next_flag)
{
previous.setVisibility(View.VISIBLE);
setResult(202);
finish();
}else{
next.setVisibility(View.INVISIBLE);
Toast.makeText(getApplicationContext(), "Last News", Toast.LENGTH_SHORT).show();
}
}
});
previous.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if( pre_flag)
{
next.setVisibility(View.VISIBLE);
setResult(201);
finish();
}else{
previous.setVisibility(View.INVISIBLE);
Toast.makeText(getApplicationContext(), "First News", Toast.LENGTH_SHORT).show();
}
}
});
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode==202){
//Next
msg=msg_id1[++msg_cureentposition];
Intent i=new Intent(details.this,details1.class);
Bundle bundle = new Bundle();
if(msg_cureentposition==msg_length-1)
bundle.putBoolean("nextFlag",false);
else
bundle.putBoolean("nextFlag",true);
if(msg_cureentposition==0)
bundle.putBoolean("previousFlag",false);
else
bundle.putBoolean("previousFlag",true);
bundle.putString("ID",msg);
i.putExtras(bundle);
startActivityForResult(i,100);
}else if(resultCode==201){
//Previous
msg=msg_id1[--msg_cureentposition];
Intent i=new Intent(details.this,details1.class);
Bundle bundle = new Bundle();
if(msg_cureentposition==msg_length-1)
bundle.putBoolean("nextFlag",false);
else
bundle.putBoolean("nextFlag",true);
if(msg_cureentposition==0)
bundle.putBoolean("previousFlag",false);
else
bundle.putBoolean("previousFlag",true);
bundle.putString("ID",msg);
i.putExtras(bundle);
startActivityForResult(i,100);
}
}
LIstCiew onClickListner:
msg_length=msg_id1.length;
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView arg0, View arg1,
int pos, long arg3) {
// TODO Auto-generated method stub
Intent i=new Intent(details.this,details1.class);
msg_cureentposition=pos;
Bundle bundle = new Bundle();
if(msg_cureentposition==msg_length-1)
bundle.putBoolean("nextFlag",false);
else
bundle.putBoolean("nextFlag",true);
if(msg_cureentposition==0)
bundle.putBoolean("previousFlag",false);
else
bundle.putBoolean("previousFlag",true);
bundle.putString("ID",msg_id1[pos]);
i.putExtras(bundle);
startActivityForResult(i,100);
}
});
Prev ANd Next Button:
next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(next_flag)
{
previous.setVisibility(View.VISIBLE);
setResult(202);
finish();
}else{
next.setVisibility(View.INVISIBLE);
Toast.makeText(getApplicationContext(), "Last News", Toast.LENGTH_SHORT).show();
}
}
});
previous.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if( pre_flag)
{
next.setVisibility(View.VISIBLE);
setResult(201);
finish();
}else{
previous.setVisibility(View.INVISIBLE);
Toast.makeText(getApplicationContext(), "First News", Toast.LENGTH_SHORT).show();
}
}
});
Thursday, July 7, 2011
UrlEncode
public class Extras {
public static String URLencode(String s){
if (s!=null) {
StringBuffer tmp = new StringBuffer();
int i=0;
try {
//s=java.net.URLEncoder.encode(s,"UTF-8");
while (true) {
int b = (int)s.charAt(i++);
if ((b>=0x30 && b<=0x39) || (b>=0x41 && b<=0x5A) || (b>=0x61 && b<=0x7A)) {
tmp.append((char)b);
}
else {
tmp.append("%");
if (b <= 0xf) tmp.append("0");
tmp.append(Integer.toHexString(b));
}
}
}
catch (Exception e) {
}
return tmp.toString();
}
return null;
}
public static String removecommas(String str)
{
try{
if(str.contains(","))
{
str=str.replace(",","");
return str;
}
else
return str;
}catch(Exception e){
return null;
}
}
public static String removeminus(String str)
{
try{
if(str.contains("-"))
{
str=str.replace("-","");
return str;
}
else
return str;
}catch(Exception e){
return null;
}
}
}
public static String URLencode(String s){
if (s!=null) {
StringBuffer tmp = new StringBuffer();
int i=0;
try {
//s=java.net.URLEncoder.encode(s,"UTF-8");
while (true) {
int b = (int)s.charAt(i++);
if ((b>=0x30 && b<=0x39) || (b>=0x41 && b<=0x5A) || (b>=0x61 && b<=0x7A)) {
tmp.append((char)b);
}
else {
tmp.append("%");
if (b <= 0xf) tmp.append("0");
tmp.append(Integer.toHexString(b));
}
}
}
catch (Exception e) {
}
return tmp.toString();
}
return null;
}
public static String removecommas(String str)
{
try{
if(str.contains(","))
{
str=str.replace(",","");
return str;
}
else
return str;
}catch(Exception e){
return null;
}
}
public static String removeminus(String str)
{
try{
if(str.contains("-"))
{
str=str.replace("-","");
return str;
}
else
return str;
}catch(Exception e){
return null;
}
}
}
Monday, July 4, 2011
Andriod get image from Url
ImageView iv = new ImageView(context);
try{
String url1 = "http:///test/abc.jpg";
URL ulrn = new URL(url1);
HttpURLConnection con = (HttpURLConnection)ulrn.openConnection();
InputStream is = con.getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(is);
if (null != bmp)
iv.setImageBitmap(bmp);
else
System.out.println("The Bitmap is NULL");
}catch(Exception e){}
}
try{
String url1 = "http://
URL ulrn = new URL(url1);
HttpURLConnection con = (HttpURLConnection)ulrn.openConnection();
InputStream is = con.getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(is);
if (null != bmp)
iv.setImageBitmap(bmp);
else
System.out.println("The Bitmap is NULL");
}catch(Exception e){}
}
Friday, July 1, 2011
Db to get ID
db=new DataHelper(EatOut_details.this);
db.open();
Cursor res=db.getFeed(Story_id);
if(res==null || res.getCount()<=0){
btn_favourite.setBackgroundResource(R.drawable.added);
try{
db.insert(Story_id,1,2,3,4,5,sub_6);
}catch (Exception e) {
Log.e("1", "Error while Querying - "+e);
}
Toast.makeText(this, " dded", Toast.LENGTH_SHORT).show();
res.close();
}else{
btn_favourite.setBackgroundResource(R.drawable.icon);
try{
db.deleteFeed(Story_id);
}catch (Exception e) {
Log.e("ram", "Error while Querying - "+e);
}
Toast.makeText(this, " Removed", Toast.LENGTH_SHORT).show();
res.close();
}
db.close();
db.open();
Cursor res=db.getFeed(Story_id);
if(res==null || res.getCount()<=0){
btn_favourite.setBackgroundResource(R.drawable.added);
try{
db.insert(Story_id,1,2,3,4,5,sub_6);
}catch (Exception e) {
Log.e("1", "Error while Querying - "+e);
}
Toast.makeText(this, " dded", Toast.LENGTH_SHORT).show();
res.close();
}else{
btn_favourite.setBackgroundResource(R.drawable.icon);
try{
db.deleteFeed(Story_id);
}catch (Exception e) {
Log.e("ram", "Error while Querying - "+e);
}
Toast.makeText(this, " Removed", Toast.LENGTH_SHORT).show();
res.close();
}
db.close();
remove db
DataHelper db=new DataHelper(this);
db.open();
try{
db.deleteFeed(Story_id[select_pos]);
}catch (Exception e) {
Log.e("BookUrTable", "Error while Querying - "+e);
}
db.close();
db.open();
try{
db.deleteFeed(Story_id[select_pos]);
}catch (Exception e) {
Log.e("BookUrTable", "Error while Querying - "+e);
}
db.close();
Subscribe to:
Posts (Atom)