• Android应用案例--广告查查看


    产品功能介绍:

    1、应用查找

    2、广告应用分析

    3、广告应该卸载

    4、白名单设置

    开始从头来介绍代码: 

    欢迎界面:WelComeActivity.java

    package com.eoe.adskiller;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.animation.AlphaAnimation;
    import android.view.animation.Animation;
    import android.view.animation.Animation.AnimationListener;
    import android.widget.ImageView;
    
    public class WelComeActivity extends Activity {
    
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.welcome_layout);  
          
            ImageView image=(ImageView)findViewById(R.id.imageView551);    
    //        AlphaAnimation类是Android系统中的透明度变化动画类
    //        [基本语法】public AlphaAnimation (float fromAlpha, float toAlpha)
    //        参数说明:fromAlpha:开始时刻的透明度,取值范围0~1。toAlpha:结束时刻的透明度,取值范围0~1。
            AlphaAnimation alphaAnimation=new AlphaAnimation(1, 1);  
            alphaAnimation.setDuration(1000);   //设置持续时间 
            alphaAnimation.setAnimationListener(new AnimationListener() {        
            @Override
            public void onAnimationStart(Animation animation) {
                // TODO 自动生成的方法存根            
            }    
            @Override
            public void onAnimationRepeat(Animation animation) {
                // TODO 自动生成的方法存根            
            }
            
            @Override
            public void onAnimationEnd(Animation animation) {
                        
                // TODO 自动生成的方法存根
                   Intent intent = new Intent();
                   intent.setClass(WelComeActivity.this, MainActivity.class);
                   startActivity(intent);
                   finish();            
                
            }
        });
          image.startAnimation(alphaAnimation);  
        }
        
      
        
    }

    显示效果图:

    让后接入主机面:

    MainActivity.java代码如下:

    package com.eoe.adskiller;
    
    import java.util.List;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.Menu;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.ViewGroup.LayoutParams;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.LinearLayout;
    
    
    
    public class MainActivity extends Activity {
    
        private static final String TAG = "com.eoe.adskiller.MainActivity";
        private Button scanbtn,setbtn;
        private ImageView myimg;
        
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            scanbtn = (Button)findViewById(R.id.check);
            setbtn = (Button)findViewById(R.id.setting);
            myimg=(ImageView)findViewById(R.id.imageView1);
    
           // 屏幕宽(像素,如:480px)   
            int screenHeight = getWindowManager().getDefaultDisplay().getHeight();      
            
            myimg.setMaxHeight(screenHeight-568);
        
            
            scanbtn.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View v) {
                    // TODO 自动生成的方法存根
                    Intent scanIntent=new Intent(MainActivity.this,ScanResult.class);
                    MainActivity.this.startActivity(scanIntent);
                //    Log.d("start scan activity", "start time");
                }
            });
            setbtn.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View v) {
                    // TODO 自动生成的方法存根
                    Intent setIntent=new Intent(MainActivity.this,SettingActivity.class);
                    MainActivity.this.startActivity(setIntent);
                }
            });
        }
    }

    SettingActivity.Java 这里不附录代码了!

    ScanResult.java 代码如下:

    package com.eoe.adskiller;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import android.R.integer;
    import android.app.Activity;
    import android.content.pm.PackageInfo;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.util.Log;
    import android.view.View;
    import android.widget.BaseAdapter;
    import android.widget.ListView;
    import android.widget.ProgressBar;
    import android.widget.RelativeLayout;
    import android.widget.TextView;
    import android.widget.Toast;
    
    public class ScanResult extends Activity {
        
        ListView rlListView;
        ProgressBar mProgressBar;
        TextView scaning,scanended;
        
        
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO 自动生成的方法存根
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_result);
            rlListView=(ListView)findViewById(R.id.listview);
            
            mProgressBar=(ProgressBar)findViewById(R.id.progressBar);
            scaning=(TextView)findViewById(R.id.textscan);
            scanended=(TextView)findViewById(R.id.scanend);
            
            Handler backHandler=new TaskHandler(this);
            ScanTask myScanTask=new ScanTask(this,backHandler);
            myScanTask.setPriority(Thread.MAX_PRIORITY);
            myScanTask.start();
        //    Log.d("activity create","create  time");
        }
        
        @Override
        protected void onStart() {
            // TODO 自动生成的方法存根
            super.onStart();
            
        }
    
        @Override
        protected void onResume() {
            // TODO 自动生成的方法存根
            super.onResume();
    
        }
        class TaskHandler extends Handler {
    
            private ScanResult parentActivityResult=null;
            ArrayList<AppInfo> appList = new ArrayList<AppInfo>(); 
            
            AppAdapter appAdapter;
            
            private int count =0;
            
            
            public TaskHandler (ScanResult result)
            {
                parentActivityResult=result;
                
            }
            
            @Override
            public void handleMessage(Message msg) {
                // TODO 自动生成的方法存根
                super.handleMessage(msg);
                
                
                if (msg.what==0) 
                {
                    AppInfo tmpInfo = new AppInfo(); 
                    tmpInfo=(AppInfo)msg.obj;
                    
                   
                    if (count==0) {
                        
                        appList.add(tmpInfo);
                        
                        appAdapter=new AppAdapter(ScanResult.this,appList);
    
                        rlListView.setDividerHeight(5);
                        if(rlListView!=null)
                        {
                            rlListView.setAdapter(appAdapter);
                        }
                        
                    } else 
                    {
                        
                        appAdapter.dataList.add(tmpInfo);
                        appAdapter.notifyDataSetChanged();
                    }
    
                    count++;
    
                } 
                else 
                {
                    setProgressBarVisibility(false);
                    mProgressBar.setVisibility(View.GONE);
                    scaning.setVisibility(View.GONE);
                    scanended.setVisibility(View.VISIBLE);
                }
            }
            
        }
    }
    package com.eoe.adskiller;
    
    import java.util.ArrayList;
    
    import android.R.raw;
    import android.content.Context;
    import android.content.Intent;
    import android.net.Uri;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.Button;
    import android.widget.ImageButton;
    import android.widget.ImageView;
    import android.widget.TextView;
    
    public class AppAdapter extends BaseAdapter {
        
        Context context;
        ArrayList<AppInfo> dataList=new ArrayList<AppInfo>();
        public AppAdapter(Context context,ArrayList<AppInfo> inputDataList)
        {
            this.context=context;
            dataList.clear();
            for(int i=0;i<inputDataList.size();i++)
            {
                dataList.add(inputDataList.get(i));
            }
        }
        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return dataList.size();
        }
    
        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return dataList.get(position);
        }
    
        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }
    
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            
            View v=convertView;
            final AppInfo appUnit=dataList.get(position);
            if(v==null)
            {
                LayoutInflater vi=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v=vi.inflate(R.layout.app_row, null);
                v.setClickable(true);
            }
            TextView appName=(TextView)v.findViewById(R.id.appName);
            ImageView appIcon=(ImageView)v.findViewById(R.id.icon);
            Button btnButton=(Button)v.findViewById(R.id.button1);
            if(appName!=null)
            {
                appName.setText(appUnit.appName);
            }
            
            if(appIcon!=null)
                appIcon.setImageDrawable(appUnit.appIcon);
            btnButton.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View v) 
                {
                    AppInfo theApp=(AppInfo)dataList.get(position);
                    Uri packageURI = Uri.parse("package:" +theApp.packageName);         
    
                    Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);         
    
                    context.startActivity(uninstallIntent);
            
                    
                }
            });
            return v;
        }
    }
  • 相关阅读:
    php 高精度计算函数
    CSS 文本溢出显示省略号样式
    Vue import、export及export default示例详解,附带如何实现全局调用
    利用高德API获取最新的省市区数据
    TP5 基类验证器
    php 两种递归方法
    新建PO類型ZFA的固定資產時灰掉 GR Non-Valuated
    MRP 參數設置
    info record
    kill procedure in os level
  • 原文地址:https://www.cnblogs.com/zhoujn/p/4318896.html
Copyright © 2020-2023  润新知