Sharing installed apk applications for Android

Source: Internet
Author: User

Have you ever encountered a good app on your mobile phone, but you don't know how to share it with friends? As a programmer, I encountered such a simple problem. I must find a solution. After google and Baidu, I found that all installed apps on android would be backed up, they are stored in three locations:

1. Software signed by the system:/system/app

2. Non-system signature software installed on the memory:/data/app

3. Install the non-system signature software on the SD card:/mnt/asec/package name-number/pkg.apk

We can use the re browser to view and share these apk files. I have confirmed that these applications are available, but this is quite troublesome because you must remember these three locations, and the storage applications corresponding to the three locations. Otherwise, the three folders will be browsed once every time. This is a lot of trouble. The program is designed to make people lazy, as a result, I will post my own code to list all installed applications and share them via Bluetooth:
[Java]
Public class MainActivity extends Activity {
 
GridView mGridView = null; www.2cto.com
List <ResolveInfo> mAllApps = new ArrayList <ResolveInfo> ();
List <PackageInfo> mAllPackages = new ArrayList <PackageInfo> ();
PackageManager packageManager = null;
 
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main );
ShowView ();
}
 
Public void showView (){
PackageManager = getPackageManager ();
MGridView = (GridView) this. findViewById (R. id. gridView1 );
SetMyAllApps ();
 
MGridView. setAdapter (new MyAdapter (mAllApps, this ));
MGridView. setNumColumns (4 );
MGridView. setOnItemLongClickListener (new AdapterView. OnItemLongClickListener (){
 
Public boolean onItemLongClick (AdapterView <?> Arg0, View arg1,
Int arg2, long arg3 ){
// TODO Auto-generated method stub
ResolveInfo resolveInfo = mAllApps. get (arg2 );
String packageName = resolveInfo. activityInfo. packageName;
For (Iterator <PackageInfo> iterator = mAllPackages. iterator (); iterator. hasNext ();){
PackageInfo packageInfo = iterator. next ();
If (packageInfo. applicationInfo. packageName. equals (packageName )){
Log. I ("six grade", "source dir:" + packageInfo. applicationInfo. sourceDir );
File sourceFile = new File (packageInfo. applicationInfo. sourceDir );
// Call the sharing window of the android System
Intent intent = new Intent ();
Intent. setAction (Intent. ACTION_SEND );
Intent. setType ("*/*");
Intent. putExtra (Intent. EXTRA_STREAM, Uri. fromFile (sourceFile ));
StartActivity (intent );
}
}
Return true;
}
});
}
 
Public void setMyAllApps (){
// Search for all the first displayed activities
Intent intent = new Intent (Intent. ACTION_MAIN, null );
Intent. addCategory (Intent. CATEGORY_LAUNCHER );
MAllApps = packageManager. queryIntentActivities (intent, 0 );
MAllPackages = packageManager. getInstalledPackages (0 );
// Sort by name
Collections. sort (mAllApps, new ResolveInfo. DisplayNameComparator (
PackageManager ));
}
 
@ Override
Public boolean onCreateOptionsMenu (Menu menu ){
GetMenuInflater (). inflate (R. menu. activity_main, menu );
Return true;
}
 
Class MyAdapter extends BaseAdapter {
 
List <ResolveInfo> appList;
Context mContext;
 
Public MyAdapter (List <ResolveInfo> appList, Context context ){
This. appList = appList;
MContext = context;
}
 
Public int getCount (){
// TODO Auto-generated method stub
Return appList. size ();
}
 
Public Object getItem (int position ){
// TODO Auto-generated method stub
Return null;
}
 
Public long getItemId (int position ){
// TODO Auto-generated method stub
Return 0;
}
 
Public View getView (int position, View convertView, ViewGroup parent ){
// TODO Auto-generated method stub
ConvertView = LayoutInflater. from (mContext). inflate (
R. layout. application, null );
ImageView imageView = (ImageView) convertView
. FindViewById (R. id. imageView1 );
TextView textView = (TextView) convertView
. FindViewById (R. id. textView1 );
ResolveInfo resolveInfo = appList. get (position );
TextView. setText (resolveInfo. loadLabel (packageManager ));
ImageView. setBackgroundColor (Color. TRANSPARENT );
Bitmap iconBitmap = ImageUtils. drawableToBitmap (resolveInfo
. LoadIcon (packageManager ));
ImageView. setImageBitmap (ImageUtils. getRoundedCornerBitmap (
ImageUtils. zoomBitmap (iconBitmap, 60, 60), 10 ));
Return convertView;
}
 
}
}
Below is the program


I used the gridview to list all installed user applications, but I did not search for them. It will certainly be added in the future, and I believe it will bring convenience to you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.