2011年3月11日金曜日

android tips

http://www.androidsnippets.com/

//open browser to web page URL via intent
Button b1=(Button)findViewById(R.id.Button01);
b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String url = "url";
setTitle(url);
Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.novoda.com"));
startActivity(viewIntent);
}
});


//Display an alert box
protected void alertbox(String title, String mymessage)
{
new AlertDialog.Builder(this)
.setMessage(mymessage)
.setTitle(title)
.setCancelable(true)
.setNeutralButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){}
})
.show();
}

//Text Notification Pop-Up (using Toast)
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();

//Check if the network is available
public boolean isNetworkAvailable() {
Context context = getApplicationContext();
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
boitealerte(this.getString(R.string.alert),"getSystemService rend null");
} else {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}

//have Internet?
//Correct logging
//Non-Blocking Web-Request

0 件のコメント: