1、在标题栏中加入进度条:

//明确进度条

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);
setProgressBarIndeterminateVisibility(true);
// 明确进度条
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
setProgress(5000);
2、设置全屏
//设置全屏模式
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// 去除标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
3、锁定屏幕方向
<activity android:name=”.EX01″
android:label=”@string/app_name”
android:screenOrientation=”portrait”>
</activity>
4、创建快捷方式
OPhone上的方法

Android上的实现方法

Java代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://fonter.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" invokeurls="false" quality="high" wmode="transparent" flashvars="clipboard=private%20static%20final%20String%20ACTION_INSTALL_SHORTCUT%20%3D%20%22com.android.launcher.action.INSTALL_SHORTCUT%22%3B" allownetworking="internal" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer">
private static final String ACTION_INSTALL_SHORTCUT = “com.android.launcher.action.INSTALL_SHORTCUT”;
Java代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://fonter.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" invokeurls="false" quality="high" wmode="transparent" flashvars="clipboard=%09%09Intent%20shortcutIntent%20%3D%20new%20Intent(ACTION_INSTALL_SHORTCUT)%3B%0A%09%09shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME%2C%0A%09%09%09%09getString(R.string.app_name))%3B%0A%09%09shortcutIntent.putExtra(EXTRA_SHORTCUT_DUPLICATE%2C%20false)%3B%0A%09%09Intent%20intent%20%3D%20new%20Intent()%3B%0A%09%09intent.setComponent(new%20ComponentName(this.getPackageName()%2C%0A%09%09%09%09%22.Splash%22))%3B%0A%0A%09%09shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT%2C%20intent)%3B%0A%09%09shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE%2C%0A%09%09%09%09Intent.ShortcutIconResource.fromContext(this%2C%0A%09%09%09%09%09%09R.drawable.icon))%3B%0A%09%09sendBroadcast(shortcutIntent)%3B" allownetworking="internal" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer">
Intent shortcutIntent = new Intent(ACTION_INSTALL_SHORTCUT);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
getString(R.string.app_name));
shortcutIntent.putExtra(EXTRA_SHORTCUT_DUPLICATE, false);
Intent intent = new Intent();
intent.setComponent(new ComponentName(this.getPackageName(),
“.Splash”));

shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this,
R.drawable.icon));
sendBroadcast(shortcutIntent);
Uses permission

Xml代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://fonter.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" invokeurls="false" quality="high" wmode="transparent" flashvars="clipboard=%3Cuses-permission%20android%3Aname%3D%22com.android.launcher.permission.INSTALL_SHORTCUT%22%2F%3E" allownetworking="internal" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer">
<uses-permission android:name=“com.android.launcher.permission.INSTALL_SHORTCUT”/>
删除快捷方式试了很久没测试成功过,不知那位同学贡献一下代码?

5、判断网络是否可用

函数用于判断网络是否可用

Java代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://fonter.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" invokeurls="false" quality="high" wmode="transparent" flashvars="clipboard=%2F*%20%20%0A*%40return%20boolean%20return%20true%20if%20the%20application%20can%20access%20the%20internet%20%20%0A*%2F%20%20%0Aprivate%20boolean%20haveInternet()%7B%20%20%20%0A%20%20%20%20NetworkInfo%20info%3D(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE).getActiveNetworkInfo()%3B%20%20%20%0A%20%20%20%20if(info%3D%3Dnull%20%7C%7C%20!info.isConnected())%7B%20%20%20%0A%20%20%20%20%20%20%20%20return%20false%3B%20%20%20%0A%20%20%20%20%7D%20%20%20%0A%20%20%20%20if(info.isRoaming())%7B%20%20%20%0A%20%20%20%20%20%20%20%20%2F%2Fhere%20is%20the%20roaming%20option%20you%20can%20change%20it%20if%20you%20want%20to%20disable%20internet%20while%20roaming%2C%20just%20return%20false%20%20%20%0A%20%20%20%20%20%20%20%20return%20true%3B%20%20%20%0A%20%20%20%20%7D%20%20%20%0A%20%20%20%20return%20true%3B%20%20%20%0A%7D%20%20%0A" allownetworking="internal" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer">
/*
*@return boolean return true if the application can access the internet
*/
private boolean haveInternet(){
NetworkInfo info=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE).getActiveNetworkInfo();
if(info==null || !info.isConnected()){
return false;
}
if(info.isRoaming()){
//here is the roaming option you can change it if you want to disable internet while roaming, just return false
return true;
}
return true;
}
另一种方法

Java代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://fonter.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" invokeurls="false" quality="high" wmode="transparent" flashvars="clipboard=public%20boolean%20isNetworkAvailable()%20%7B%20%20%20%0A%20%20%20Context%20context%20%3D%20getApplicationContext()%3B%20%20%20%0A%20%20%20ConnectivityManager%20connectivity%20%3D%20(ConnectivityManager)%20context.getSystemService(Context.CONNECTIVITY_SERVICE)%3B%20%20%20%0A%20%20%20if%20(connectivity%20%3D%3D%20null)%20%7B%20%20%20%0A%20%20%20%20%20%20boitealerte(this.getString(R.string.alert)%2C%22getSystemService%20rend%20null%22)%3B%20%20%20%0A%20%20%20%7D%20else%20%7B%20%20%20%0A%20%20%20%20%20%20NetworkInfo%5B%5D%20info%20%3D%20connectivity.getAllNetworkInfo()%3B%20%20%20%0A%20%20%20%20%20%20if%20(info%20!%3D%20null)%20%7B%20%20%20%0A%20%20%20%20%20%20%20%20%20for%20(int%20i%20%3D%200%3B%20i%20%3C%20info.length%3B%20i%2B%2B)%20%7B%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(info%5Bi%5D.getState()%20%3D%3D%20NetworkInfo.State.CONNECTED)%20%7B%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20true%3B%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%20%20%20%0A%20%20%20%20%20%20%20%20%20%7D%20%20%20%0A%20%20%20%20%20%20%7D%20%20%20%0A%20%20%20%7D%20%20%20%0A%20%20%20return%20false%3B%20%20%20%0A%7D%20%20%0A" allownetworking="internal" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer">
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;
}
6、在启动时自动启动一个应用程序:

1、AndroidManifest.xml

Xml代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://fonter.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" invokeurls="false" quality="high" wmode="transparent" flashvars="clipboard=%3Creceiver%20android%3Aenabled%3D%22true%22%20android%3Aname%3D%22.BootUpReceiver%22%20%20%0A%20%20%20%20android%3Apermission%3D%22android.permission.RECEIVE_BOOT_COMPLETED%22%3E%20%20%20%0A%20%20%0A%20%20%20%20%3Cintent-filter%3E%20%20%20%0A%20%20%20%20%20%20%20%20%3Caction%20android%3Aname%3D%22android.intent.action.BOOT_COMPLETED%22%20%2F%3E%20%20%20%0A%20%20%20%20%20%20%20%20%3Ccategory%20android%3Aname%3D%22android.intent.category.DEFAULT%22%20%2F%3E%20%20%20%0A%20%20%20%20%3C%2Fintent-filter%3E%20%20%20%0A%3C%2Freceiver%3E%20" allownetworking="internal" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer">
<receiver android:enabled=“true” android:name=“.BootUpReceiver”
android:permission=“android.permission.RECEIVE_BOOT_COMPLETED”>

<intent-filter>
<action android:name=“android.intent.action.BOOT_COMPLETED” />
<category android:name=“android.intent.category.DEFAULT” />
</intent-filter>
</receiver>
2、permission

Java代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://fonter.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" invokeurls="false" quality="high" wmode="transparent" flashvars="clipboard=%3Cuses-permission%20android%3Aname%3D%22android.permission.RECEIVE_BOOT_COMPLETED%22%20%2F%3E" allownetworking="internal" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer">
<uses-permission android:name=“android.permission.RECEIVE_BOOT_COMPLETED” />
3、BroadcastReceiver实现

Java代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://fonter.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" invokeurls="false" quality="high" wmode="transparent" flashvars="clipboard=public%20class%20BootUpReceiver%20extends%20BroadcastReceiver%7B%20%20%20%0A%20%20%0A%20%20%20%20%40Override%20%20%0A%20%20%20%20public%20void%20onReceive(Context%20context%2C%20Intent%20intent)%20%7B%20%20%20%0A%20%20%20%20%20%20%20%20Intent%20i%20%3D%20new%20Intent(context%2C%20MyActivity.class)%3B%20%20%20%20%20%0A%20%20%20%20%20%20%20%20i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)%3B%20%20%20%0A%20%20%20%20%20%20%20%20context.startActivity(i)%3B%20%20%20%20%20%0A%20%20%20%20%7D%20%20%20%0A%20%20%0A%7D%20%20%0A" allownetworking="internal" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer">
public class BootUpReceiver extends BroadcastReceiver{

@Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, MyActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}

}
7、
Android Kill App
两种方法

第一种:

Java代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://fonter.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" invokeurls="false" quality="high" wmode="transparent" flashvars="clipboard=android.os.Process.killProcess(android.os.Process.myPid())%20%20%20%0ASystem.exit(0)%3B%20" allownetworking="internal" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer">
android.os.Process.killProcess(android.os.Process.myPid())
System.exit(0);
第二种:

Java代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://fonter.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" invokeurls="false" quality="high" wmode="transparent" flashvars="clipboard=ActivityManager.restartPackage(packageName)%3B%0A" allownetworking="internal" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer">
ActivityManager.restartPackage(packageName);
8、转换Bitmap to Drawable
Java代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://fonter.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" invokeurls="false" quality="high" wmode="transparent" flashvars="clipboard=BitmapDrawable%20bitmapDrawable%20%3D%20(BitmapDrawable)bitmap%3B%20%20%20%0ADrawable%20drawable%20%3D%20(Drawable)bitmapDrawable%3B%20%20%20%0A%20%20%0A%20%20%0ABitmap%20bitmap%20%3D%20new%20Bitmap%20(...)%3B%20%20%20%0ADrawable%20drawable%20%3D%20new%20BitmapDrawable(bitmap)%3B" allownetworking="internal" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer">
BitmapDrawable bitmapDrawable = (BitmapDrawable)bitmap;
Drawable drawable = (Drawable)bitmapDrawable;


Bitmap bitmap = new Bitmap (…);
Drawable drawable = new BitmapDrawable(bitmap);
转换Drawable to Bitmap

Java代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://fonter.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" invokeurls="false" quality="high" wmode="transparent" flashvars="clipboard=Drawable%20d%20%3D%20ImagesList.get(0)%3B%0ABitmap%20bitmap%20%3D%20((BitmapDrawable)d).getBitmap()%3B" allownetworking="internal" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer">
Drawable d = ImagesList.get(0);
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
9、获取当前设备的IP地址

Java代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://fonter.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" invokeurls="false" quality="high" wmode="transparent" flashvars="clipboard=WifiManager%20wifiManager%20%3D%20(WifiManager)%20getSystemService(WIFI_SERVICE)%3B%20%20%20%0AWifiInfo%20wifiInfo%20%3D%20wifiManager.getConnectionInfo()%3B%20%20%20%0Aint%20ipAddress%20%3D%20wifiInfo.getIpAddress()%3B%20%20%20%0AString%20ip%20%3D%20intToIp(ipAddress)%3B%20%20%20%0A%20%20%0Apublic%20String%20intToIp(int%20i)%20%7B%20%20%20%0A%20%20%0A%20%20%20return%20((i%20%3E%3E%2024%20)%20%26%200xFF%20)%20%2B%20%22.%22%20%2B%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20((i%20%3E%3E%2016%20)%20%26%200xFF)%20%2B%20%22.%22%20%2B%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20((i%20%3E%3E%208%20)%20%26%200xFF)%20%2B%20%22.%22%20%2B%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20(%20i%20%26%200xFF)%20%3B%20%20%20%0A%7D%20%20" allownetworking="internal" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer">

WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
String ip = intToIp(ipAddress);

public String intToIp(int i) {

return ((i >> 24 ) & 0xFF ) + “.” +
((i >> 16 ) & 0xFF) + “.” +
((i >> 8 ) & 0xFF) + “.” +
( i & 0xFF) ;
}
10、程序控制屏幕变亮:

WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 100 / 100.0f;
getWindow().setAttributes(lp);

11、一个图片透明:
Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);buffer.eraseColor(Color.TRANSPARENT);

12、过滤特定文本
Filter filter = myAdapter.getFilter();
filter.filter(mySearchText);


13、拖放控制
Button1.setOnTouchListener(new Button.OnTouchListener() {
int index[] = new int[]{0,0};
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
int x = (int)event.getRawX();
int y = (int)event.getRawY();
switch(action)
{
case MotionEvent.ACTION_DOWN:
Log.i(“taohaibing”, “move down”);
index[0] = (int)event.getX();
index[1] = y-v.getTop();
break;
case MotionEvent.ACTION_MOVE:
Log.i(“taohaibing”, “ACTION_MOVE”);
v.layout(x-index[0], y-index[1], x+v.getWidth()-index[0],y-index[1]+v.getHeight());
v.postInvalidate();
break;
case MotionEvent.ACTION_UP:
Log.i(“taohaibing”, “ACTION_UP”);
break;
}
return false;
}
});


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xinke87/archive/2011/01/07/6121782.aspx 2011-04-22

更多相关文章

  1. 浅谈Java中Collections.sort对List排序的两种方法
  2. Python list sort方法的具体使用
  3. python list.sort()根据多个关键字排序的方法实现
  4. android上一些方法的区别和用法的注意事项
  5. android EditText设置不可写
  6. android 使用html5作布局文件: webview跟javascript交互
  7. android实现字体闪烁动画的方法
  8. android studio调试c/c++代码
  9. Android中dispatchDraw分析

随机推荐

  1. android Frame动画基础
  2. Android(安卓)Dex文件格式(一)
  3. Android Studio 检测不到 Genymotion 模
  4. 设置背景图时防止图片拉伸的解决方法
  5. 调试过程中的堆栈打印
  6. Android(安卓)Kotlin(2)之《函数和Lambda表
  7. Android Studio经验积累之常见问题以及解
  8. android 获得手机信息
  9. Android问题与解决
  10. Android(安卓)-- 读取assets文件夹下的资