打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
andorid的一些知识
1.    理解 application的图标 和 桌面activity的图标 
<application
       //在设置→应用程序→管理应用程序 里面列出的图标
        android:icon="@drawable/icon5" 
        //在设置→应用程序→管理应用程序 里面列出的名字
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".ui.SplashActivity"
            //在手机桌面上生成的图标
            android:icon="@drawable/icon5"
            //在手机桌面上生成的名字
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        </application>
在清单文件中对应的节点配置.
2.    Splash全屏显示
// 取消标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
// 完成窗体的全屏显示 // 取消掉状态栏
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
Ps: 也可以通过主题设置窗体全屏显示 
  android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

3.    pull解析xml
/**
     * 把person.xml的输入流 解析 转化成list集合 
     * @param filename  assets目录下的文件名 
     * @return
     */
    public List<Person> getPersons(String filename){
        AssetManager manager = context.getAssets();
        try {
            InputStream  is = manager.open(filename);
            //在android下使用pull解析xml文件 
            //1.获取pull解析器的实例
            XmlPullParser  parser = Xml.newPullParser();
            //2.设置解析器的一些参数 
            parser.setInput(is, "utf-8");
            // 获取pull解析器对应的事件类型 
            int type = parser.getEventType();
            Person person = null;
            List<Person> persons = new ArrayList<Person>();
            while(type!=XmlPullParser.END_DOCUMENT){
    
                if(type==XmlPullParser.START_TAG){
                    if("person".equals(parser.getName())){
                        person = new Person();
                        int id =Integer.parseInt( parser.getAttributeValue(0));
                        person.setId(id);
                    }else if("name".equals(parser.getName())){
                        String name = parser.nextText();
                        person.setName(name);
                    }else if("age".equals(parser.getName())){
                        int age = Integer.parseInt( parser.nextText());
                        person.setAge(age);
                    }
                }
                if(type==XmlPullParser.END_TAG){
                    if("person".equals(parser.getName())){
                        persons.add(person);
                        person = null;
                    }
                }
                
                
                 type = parser.next();
            }
            
            return persons;
            
            
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(context, "获取person.xml失败", Toast.LENGTH_SHORT).show();
            return null;
        }
    }
4.    URL httpUrlConnection 
public UpdateInfo getUpdataInfo(int urlid) throws Exception {
String path = context.getResources().getString(urlid);
        URL url = new URL(path);//将路径解析成url
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();//打开连接
        conn.setConnectTimeout(2000);//设置超时时间
        conn.setRequestMethod("GET");//设置请求方法
        InputStream is = conn.getInputStream();//获取返回的流
        //pull解析器解析
        XmlPullParser parser = Xml.newPullParser();
        UpdateInfo info = new UpdateInfo();
        parser.setInput(is, "utf-8");
        int type = parser.getEventType();

        while (type!=XmlPullParser.END_DOCUMENT) {
            switch (type) {
            case XmlPullParser.START_TAG:
                if ("version".equals(parser.getName())) {
                    info.setVersion(parser.nextText());
                }else if ("description".equals(parser.getName())) {
                    info.setDescription(parser.nextText());
                }else if ("apkurl".equals(parser.getName())) {
                    info.setApkurl(parser.nextText());
                }
                break;
             
            }
            type = parser.next();
            
        }
        return info;

    }
    }

5.    获取当前客户端版本号
PackageInfo info = getPackageManager().getPackageInfo(
                    getPackageName(), 0);
            return info.versionName;

6.    安装新的apk
激活系统的安装的组件 intent();
设置数据 和数据的类型 
setDataAndType();
setData();
setType(); 

private void install(File file){
        Intent intent=new Intent();
        intent.setAction(Intent.ACTION_VIEW);//显示指定数据
        intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
        this.finish();
        startActivity(intent);
        
    }

7.    对话框 创建 AlertDialog.buidler 
Builder.create().show();

8.    Handler message 子线程里面通知主线程ui更新 
private TextView tv;
    //1 .创建出来handler 要求必须在主线程里面创建 
    private Handler handler = new Handler(){

        // 主线程处理消息 调用的方法 
        @Override
        public void handleMessage(Message msg) {
            int count  = (Integer) msg.obj;
            tv.setText("当前条目为 "+ count);
            super.handleMessage(msg);
        }
        
        
    };
    
    
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv = (TextView) this.findViewById(R.id.tv);
        
        //每隔2秒钟更新一下 tv的内容 
        new Thread(){

            @Override
            public void run() {
                for(int i = 0;i<100;i++){
        /*            tv.setText("当前为"+ i);*/
                    try {
                        sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    Message msg = new Message();
                    msg.obj = i;
                    handler.sendMessage(msg);
                    
                }
                super.run();
            }
        }.start();
    
    }

9.    GridView ListView  adapter  - > BaseAdapter
//将一个XML文件转化成一个view对象
View view=View.inflate(context, R.layout.mainscreen_item, null);

10.    Xml ->定义一个背景颜色  shape  (参考api文件) 


11.    Xml -> selector 颜色选择器 根据当前控件的状态显示不同颜色.

12.    Sharedpreference 的使用 
Sp.edit(); -> Editor editor 
Editor.put()…
Editor.commit(); // 真正的提交数据 

13.    自定义对话框的写法 
定义一个样式文件 重写了系统的一些默认配置 
name="android:windowBackground">@drawable/title_background
name="android:windowNoTitle">true</item>

dialog = new Dialog(this, R.style.MyDialog);//R.style.MyDialog 是自定义的一个xml文件
        dialog.setCancelable(false);

        View view = View.inflate(this, R.layout.normal_entry_dialog, null);
        et_pwd = (EditText) view.findViewById(R.id.et_normal_entry_pwd);
        Button bt_normal_ok = (Button) view
                .findViewById(R.id.bt_normal_dialog_ok);
        Button bt_normal_cancel = (Button) view
                .findViewById(R.id.bt_normal_dialog_cancel);
        bt_normal_ok.setOnClickListener(this);
        bt_normal_cancel.setOnClickListener(this);
        dialog.setContentView(view);
        dialog.show();



14.    Md5的编码和加密 (不可逆的加密算法) 


15.    style的使用 
可以把一些常用的样式定义为style,重复使用。
然后style="@style/text_content_style" 直接引用

16.    更改activity切换的动画效果 
overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);

17.    获取新打开的activity的返回值 
StartactivityforResult();
SetResultData();

OnActivityResult();


18.    DeviceAdmin的技术 2.2版本支持 -> wipedata() setpwd();
不能直接被卸载 在设备管理器里面取消激活 ;
主要步骤如下:
deviceadmin步骤
(1).创建 MyAdmin 的广播接受者 继承 DeviceAdminReceiver

        <receiver android:name=".MyAdmin">
            <meta-data android:name="android.app.device_admin"
                android:resource="@xml/my_admin" />
            <intent-filter>
                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
            </intent-filter>
        </receiver>


my_admin.xml

<?xml version="1.0" encoding="utf-8"?>
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
        <uses-policies>
                <limit-password />
                <watch-login />
                <reset-password />
                <force-lock />
                <wipe-data />
        </uses-policies>
</device-admin>

(2).获取IDevicePolicyManager



Method method = Class.forName("android.os.ServiceManager")
                    .getMethod("getService", String.class);
IBinder binder = (IBinder) method.invoke(null,
                    new Object[] { Context.DEVICE_POLICY_SERVICE });
mService = IDevicePolicyManager.Stub.asInterface(binder);

(3).注册广播接受者为admin设备
ComponentName mAdminName = new ComponentName(this, MyAdmin.class);
if (mService != null) {
        if (!mService.isAdminActive(mAdminName)) {
                    Intent intent = new Intent(
                    DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                    intent.putExtra                (DevicePolicyManager.EXTRA_DEVICE_ADMIN,
                            mAdminName);
                    startActivity(intent);
                }
}

19 .checkbox的状态 状态变更的监听器

20 .gps 单态类 , gps wifi 基站 
获取系统服务LOCATION_SERVICE  ->locationManager  
记得把权限加到清单文件 

21 .广播接受者 
有序广播 ->1.一般的有序广播 abortbroadcast()  (-1000~1000)
2.指定了接受者的有序广播setResult();

无序的广播

22. 短信内容的处理 
Object[] pdus = (Object[]) intent.getExtras().get("pdus");

// 获取短信的内容
        // #*location*#123456
        Bundle bundle = intent.getExtras();
        // 获取接收到的所有短信的信息
        Object[] pdus = (Object[]) bundle.get("pdus");
        // 遍历接收到的所有短信的信息
        for (Object pdu : pdus) {
            // 获取短信的综合信息
            SmsMessage sms = SmsMessage.createFromPdu((byte[]) pdu);
            // 取得短信内容
            String content = sms.getMessageBody();
            Log.i(TAG, "短信内容" + content);
            // 取得短信来源
            String sender = sms.getOriginatingAddress();
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Android Pull解析xml
Android使用Pull解析器解析XML文件
使用Pull方法生成一个XML?并解析
7.2.1 Android XML数据解析
xml解析
android:用Pull方法解析XML文件
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服