有关屏幕方向的切换
首先在清单文件中设置好,
<activity
android:name="com.example.androidsdk.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
再而,在Java代码中实现
bt = (Button) findViewById(R.id.bt);
Log.d("huang", "HAHA");// 每次切换屏幕的方向都会onCreate一次
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);最好不要在此设置屏幕的方向,应该在清单文件中通过android:screenOrientation="portrait"设置,因为每次切换方向都onCreate,那就意味者每次都会调用这个方法来设置屏幕的方向,无法达到想要的效果。
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (getRequestedOrientation() == -1) {
Toast.makeText(MainActivity.this,
"Sorry,I can't help you change the orientation!",
Toast.LENGTH_SHORT).show();
} else {
if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
}
});
}
getRequestedOrientation():获取屏幕方向
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT):设置屏幕方向
Android上模拟Shell脚本运行命令
public class MainActivity extends Activity {
private Button btRun = null;
private EditText etInputCommand = null;
private TextView evShow = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etInputCommand = (EditText) findViewById(R.id.input_command);
btRun = (Button) findViewById(R.id.run);
evShow = (TextView) findViewById(R.id.show);
btRun.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
runRootCommand(etInputCommand.getText().toString());
etInputCommand.setText("");
}
});
}
protected void runRootCommand(String string) {
Process process = null;
try {
process = Runtime.getRuntime().exec(string);
StringBuffer output = new StringBuffer();
// Get the result data
DataInputStream dis = new DataInputStream(process.getInputStream());
String line;
while ((line = dis.readLine()) != null) {
output.append(line).append("\n");
}
process.waitFor();
evShow.setText(output.toString());
} catch (Exception e) {
evShow.setText("You don't have enough permission.");
} finally {
try {
process.destroy();
} catch (Exception e) {
evShow.setText("You don't have enough permission.");
}
}
}
}
获取手机已经安装的程序信息
List<PackageInfo> listPackageInfo = getPackageManager()
.getInstalledPackages(PackageManager.GET_ACTIVITIES);
output = new StringBuffer();
for (PackageInfo packageInfo : listPackageInfo) {
String name = packageInfo.packageName;
long firstTime = packageInfo.firstInstallTime;
long lastTime = packageInfo.lastUpdateTime;
output.append(name).append("\t").append(firstTime).append("\t")
.append(lastTime);
}
在自定义的控件中添加动画???????????
在程序中运行浏览网页:WebView.loadUrl()