获取手机安装的全部应用的示例教程

[来源] 达内    [编辑] 达内   [时间]2012-09-12

android用sharepreference保存输入框中的内容

android用sharepreference保存输入框中的内容

< p style="margin: 5px auto; text-indent: 0px; color: rgb(0, 0, 0); font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">http://www.eoeandroid.com/thread-199222-1-1.html

< p style="margin: 5px auto; text-indent: 0px; color: rgb(0, 0, 0); font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">Android之ScrollView嵌套ListView

< p style="margin: 5px auto; text-indent: 0px; color: rgb(0, 0, 0); font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">http://www.eoeandroid.com/thread-198859-1-1.html

< p style="margin: 5px auto; text-indent: 0px; color: rgb(0, 0, 0); font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">android根据View的不同状态更换不同的背景

< p style="margin: 5px auto; text-indent: 0px; color: rgb(0, 0, 0); font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">http://www.eoeandroid.com/thread-198029-1-1.html

< div style="background-color: rgb(245, 245, 245); font-family: 'Courier New'; font-size: 12px; border: 1px solid rgb(204, 204, 204); padding: 5px; overflow: auto; margin: 5px 0px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; " class="cnblogs_code">
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();              }  }  
< div style="background-color: rgb(245, 245, 245); font-family: 'Courier New'; font-size: 12px; border: 1px solid rgb(204, 204, 204); padding: 5px; overflow: auto; margin: 5px 0px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; " class="cnblogs_code">
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(); } }
< div style="background-color: rgb(245, 245, 245); font-family: 'Courier New'; font-size: 12px; border: 1px solid rgb(204, 204, 204); padding: 5px; overflow: auto; margin: 5px 0px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; " class="cnblogs_code">
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);           }  }  
< p style="margin: 5px auto; text-indent: 0px; color: rgb(0, 0, 0); font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">效果图:

< p style="margin: 5px auto; text-indent: 0px; color: rgb(0, 0, 0); font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">  

< p style="margin: 5px auto; text-indent: 0px; color: rgb(0, 0, 0); font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">  

< p style="margin: 5px auto; text-indent: 0px; color: rgb(0, 0, 0); font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">

资源下载