<li id="34b3z"></li>
    <nav id="34b3z"></nav>
  1. <wbr id="34b3z"><legend id="34b3z"></legend></wbr>
    
    

        1. <form id="34b3z"></form>
          <sub id="34b3z"><table id="34b3z"><th id="34b3z"></th></table></sub>

          獲取手機安裝的全部應用的示例教程

          [來源] 達內    [編輯] 達內   [時間]2012-09-12

          android用sharepreference保存輸入框中的內容

          android用sharepreference保存輸入框中的內容

          http://www.eoeandroid.com/thread-199222-1-1.html

          Android之ScrollView嵌套ListView

          http://www.eoeandroid.com/thread-198859-1-1.html

          android根據View的不同狀態更換不同的背景

          http://www.eoeandroid.com/thread-198029-1-1.html

          package
          
           com.isoftstone.apk_demo;   import
          
          
           android.app.Activity;  import android.app.ProgressDialog;  
          import android.content.Intent;  
          import android.os.Bundle;  
          import
          
           android.view.View;  import
           android.widget.Button;   public
           class
          
           APK_DemoActivity extends Activity implements
           android.view.View.OnClickListener{       /**
          
          
           Called when the activity is first created. */
          
           
                  public Intent mIntent;         
          static ProgressDialog pd;       @Override       
          public void
           onCreate(Bundle savedInstanceState) {           
          
          super
          .onCreate(savedInstanceState);          setContentView(R.layout.main);         Button button=(Button)findViewById(R.id.button1);          button.setOnClickListener(
          this
          
          );               }         @Override           public
           void onClick(View v) {                  
          // TODO Auto-generated method stub
          
                            Intent intent=new
           Intent(this,main.class
          
          
          );                                   Dialog();                  startActivity(intent);                          }                       public
           void Dialog(){                                                               pd 
          = new ProgressDialog(APK_DemoActivity.this
          
          
          );             pd.setMessage("親! 正在掃描中哦....");                     pd.show();              }  }  
          package
          
           com.isoftstone.apk_demo;    import
          
          
           java.util.ArrayList;  import java.util.HashMap;  
          import java.util.List;  
          import android.app.Activity;  
          import
          
           android.app.ProgressDialog;  import
           android.content.Context;  import
           android.content.Intent;  
          
          import android.content.pm.ResolveInfo;  
          import android.os.Bundle;  
          import
          
           android.view.View;  import
           android.widget.AdapterView;  import
          
          
           android.widget.Button;  import android.widget.ListView;  
          import android.widget.TextView;    
          public class
           main extends
          
           Activity implements  android.view.View.OnClickListener{       
          /** Called when the activity is first created. 
          */
          
           
                  public Intent mIntent;          
          private ProgressDialog pd;          
          int i=0;           
          public
          
           List<ResolveInfo> installApps = null;//
           本機已經安裝程序列表
           
                  private ListView lv_content;//
           內容顯示區域
           
                  public static
           final int
           installWhat = 1;//
          
           安裝程序列表
           
                  public static
           final int
           appPermissionWhat = 5;//
          
           某個程序的權限頁面處理          Context context;       
          public void
           onCreate(Bundle savedInstanceState) {           super
          
          
          .onCreate(savedInstanceState);          setContentView(R.layout.main0);
          Button button
          =(Button)findViewById(R.id.button1); button.setOnClickListener( this); try { handleInstall(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 處理本機安裝程序 * * @throws Exception */ private void handleInstall() throws Exception { // 1.設置操作按鈕可見(掃描已安裝程序) // 3.得到本機安裝應用程序 if (installApps == null ) { mIntent = new Intent(Intent.ACTION_MAIN, null ); mIntent.addCategory(Intent.CATEGORY_LAUNCHER); installApps = getPackageManager().queryIntentActivities(mIntent, 0); } List <HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();// 將本機安裝程序收集 for (ResolveInfo info : installApps) { HashMap<String, Object> map = new HashMap<String, Object> (); map.put("name", info.loadLabel(this .getPackageManager()).toString()); map.put("packageName", info.activityInfo.packageName); map.put( "img", info.loadIcon(this .getPackageManager())); list.add(map); } setTitle( "共安裝" + installApps.size() + "個程序");// 設置標題 // 3.將程序顯示到頁面上 lv_content = (ListView) this .findViewById(R.id.listView1); SearchAdapter adapter = new SearchAdapter(this , list, R.layout.list_content_main, new String[] { "name", "packageName", "img" }, new int [] { R.id.activityInfo_name, R.id.activityInfo_packageName, R.id.activityInfo_img }); // 自定義適配器 lv_content.setAdapter(adapter); } @Override public void onClick(View v) { // TODO Auto-generated method stub finish(); APK_DemoActivity.pd.cancel(); } }
          package
          
           com.isoftstone.apk_demo;   import
          
          
           java.util.HashMap;  import java.util.List;  
          import java.util.Map; 
          
          
          import android.content.Context;  import
           android.graphics.Bitmap;  import
           android.graphics.Canvas;  import
           android.graphics.Color;  
          
          import android.graphics.PixelFormat;  
          import android.graphics.drawable.Drawable;  
          
          
          import android.view.LayoutInflater;  import
           android.view.View;  import
          
          
           android.view.ViewGroup;  import android.widget.CheckBox;  
          import android.widget.Checkable;  
          import android.widget.ImageView;  
          import
          
           android.widget.SimpleAdapter;  import
           android.widget.TextView;   /**
          
          
            * 自定義Adapter  *  * @author machao  * @mail zeusmc.163.com  *  
          */
          
           
          public class
           SearchAdapter extends SimpleAdapter {           
          
          
          private Map<Integer, View> viewMap = new HashMap<Integer, View>
          ();           private int
          [] mTo;          private
           String[] mFrom;          
          
          private ViewBinder mViewBinder;         
          private List<? extends
           Map<String, ?>> mData;         private
           int
          
           mResource;         private
           LayoutInflater mInflater;           public
           SearchAdapter(Context context, List<? extends Map<String, ?>> data,
          int
          
           resource, String[] from, int[] to) {                   
          super(context, data, resource, from, to);                   mData 
          = data;                  mResource = resource;                  mFrom 
          = from;                  mTo = to;                   mInflater 
          =
          
           (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);          }           public
           View getView(int position, View convertView, ViewGroup parent) {                   
          
          
          return createViewFromResource(position, convertView, parent, mResource);          }           
          private View createViewFromResource(int
          
          
           position, View convertView,ViewGroup parent, int
           resource) {                   View rowView 
          
          = this.viewMap.get(position);                   
          if (rowView == null
          
          
          ) {                           rowView = mInflater.inflate(resource, null
          );                           
          
          final int
          [] to = mTo;                          final
           int
          
           count = to.length;                          final
           View[] holder = new View[count];                           
          for (int
           i = 0; i < count; i++
          
          ) {                                   holder[i] =
           rowView.findViewById(to[i]);                          }                           rowView.setTag(holder);                          bindView(position, rowView);                          viewMap.put(position, rowView);                   }                  
          return
          
           rowView;          }           @SuppressWarnings("unchecked")           
          private void bindView(int
           position, View view) {                   final
           Map dataSet = mData.get(position);                  if
           (dataSet == null
          
          ) {                           return
          ;                   }                   final
           ViewBinder binder = mViewBinder;                  final
           View[] holder =
          
           (View[]) view.getTag();                  final String[] from =
           mFrom;                  final int
          [] to = mTo;                  final
           int
          
           count = to.length;                    for
           (int i = 0; i < count; i++) {                           
          final View v = holder[i];                           
          if
          
           (v != null) {                                   
          final Object data =
           dataSet.get(from[i]);                                   String urlText 
          
          = null;                                   
          if (data == null
          
          
          ) {                                           urlText = "";                                   } 
          else
          
           {                                           urlText =
           data.toString();                                   }                                 boolean
           bound = false
          
          ;                                   if
           (binder != null) {                                           bound 
          = binder.setViewValue(v, data, urlText);                                   }                                 
          if
          
           (!bound) {                                           if
           (v instanceof
           CheckBox) {                                                   ((CheckBox) v).setText(data.toString());                                           } 
          
          else if
           (v instanceof Checkable) {                                                   
          if
          
           (data instanceof
           Boolean) {                                                           ((Checkable) v).setChecked((Boolean) data);                                                  } else
           {                                                           throw
           new
          
          
           IllegalStateException(v.getClass()                                                                           .getName()                                                                           
          
          + 
          " should be bound to a Boolean, not a "
           
                                                                                  + data.getClass());                                                 }                                           } 
          else if
           (v instanceof
           TextView) {                                                   setViewText((TextView) v, urlText);                                           } 
          
          else if
           (v instanceof CheckBox) {                                           } 
          
          
          else if (v instanceof
           ImageView) {                                                   if
           (data instanceof
           Integer) {                                                           setViewImage((ImageView) v, (Integer) data);                                                  }                                                   
          if (data 
          
          instanceof Drawable) {                                                         setViewImage((ImageView) v, (Drawable) data);                                                   } 
          else {                                                          
          if (urlText != null
           && data != null
          ) {                                                                   setViewImage((ImageView) v, urlText);                                                         } 
          
          else
           {                                                                                                                                    TextView tv =
           ((TextView) view .findViewById(R.id.activityInfo_name));                                                                   tv.setTextColor(Color.RED);                                                                 tv.setTextSize(
          18);                                                                 view.setClickable(
          
          false
          );                                                                  view.setFocusable(
          
          false
          );                                                                  view.setFocusableInTouchMode(false
          
          
          );                                                           }                                                   }                                           } else
          
          
           {                                                   throw new
          
           IllegalStateException(                                                                   v.getClass().getName()                                                                                   
          
          + " is not a &
          quot;
           
                                                                                          + " view that can be bounds by this SimpleAdapter"
          );                                           }                                 }                          }                 }          }          public
           void setViewImage(ImageView v, int
          
          
           value) {                 v.setImageResource(value);           }          public 
          void
          
           setViewImage(final ImageView v, Drawable drawable) {                   Bitmap bitmap 
          
          =
           Bitmap .createBitmap(                                                   drawable.getIntrinsicWidth(),                                                   drawable.getIntrinsicHeight(),                                                   drawable.getOpacity() 
          != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888    : Bitmap.Config.RGB_565);                   Canvas canvas 
          
          = new Canvas(bitmap);                 drawable.setBounds(
          0, 0, drawable.getIntrinsicWidth(), drawable .getIntrinsicHeight());                   drawable.draw(canvas);                 ((ImageView) v).setImageBitmap(bitmap);           }  }  

          效果圖:

            

            

          資源下載

          ?