Android 实例篇二

有关屏幕方向的切换

首先在清单文件中设置好,

<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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值