android获取已安装应用列表(android获取当前应用包名)

今天给各位分享android获取已安装应用列表的知识,其中也会对android获取当前应用包名进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

Android 读取已安装应用列表需要申请权限吗?

这里我先公布下答案:不需要

我要实现读取已安装应用列表功能,Google了一下,可以通过PackageManager.getInstalledPackages()方法获取,我手头有三台手机,分别是华为Nexus 5X、Meta9、Vivo X20,写了个Demo在这三个手机上进行测试,测试结果如下:

我没有申请任何权限,Vivo X20为什么会出现申请读取已安装应用列表权限对话框呢?为什么是有时候能获取到全部已安装应用列表,有时候获取不到?

Google一下,看有没有和我类似的问题,找到了一篇:

Android 如何完整的获取到用户已安装应用列表

这篇文章中,作者有个结论:『国内部分厂商比如华为、oppo,他们将”获取用户已安装应用列表”的权限暴露给了用户,让用户可以自由决定允许或者禁止应用访问该信息。』

Nexus 5X中没有找到读取已安装应用列表权限。

这里有提到华为,我打开meta 9的权限列表看了一下有读取已安装应用列表权限,我的Demo对应的这个权限默认是打开的,所以meta 9是能获取到全部已安装应用列表。

再看下Vivo X20,在打开Demo的时候弹出申请权限对话框了,说明Vivo也属于那部分国内厂商,由于在弹出申请读取已安装应用列表权限对话框时,我允许了,所以打开Vivo X20的读取已安装应用列表权限时,这里的状态是打开的,但是,点进去一看,暗藏玄机,这里还有一个 安全等级,分为高、中、低 ,我的Demo属于高,看看其他应用呢?微信安全等级属于低、支付宝属于低,读取不到应用列表难道和这个 安全等级 有关系吗?

我手动将我的Demo的 安全等级 调整为低,再打开Demo,奇迹发生了,没有弹出申请读取已安装应用列表权限对话框,并且获取到了全部已安装应用列表。

Android 读取已安装应用列表不需要申请权限,因为Android权限列表中没有权限是用于读取已安装应用列表的。

如果想要获取Vivo X20这种有 安全等级 的手机中的已安装应用列表,由于这种 安全等级 我们无法决定,所以只能通过反向查找的方式,即通过包名能否找到应用,从而判断是否安装了某应用。

这种方法获取不到全部已安装应用列表,只能获取到指定的应用。

如果有比较了解权限的同学觉得我有写的不对的地方,或者对于获取已安装应用列表有更好的方法,欢迎留言交流!

安卓十三系统如何允许应用读取应用列表

1、首先打开手机设置,选择“安全”选项,在安全选项卡页面,点击管理应用程序访问权限。

2、其次一旦打开了应用程序权限管理器,找到需要调整权限的应用程序,点击允许或禁止按钮,滑动到“机密信息”选项卡,勾选所有的选项。

3、最后点击完成,就可以将需要的应用程序权限打开了。以上就是安卓十三系统允许应用读取应用列表的方式。

如何获得Android手机的软件安装列表

packageManager.getInstalledApplications()返回一个列表都是安装在设备上的应用程序包。如果我们把 flag GET_UNINSTALLED_PACKAGES设定,一个列表中的所有应用,包括那些设置为dont_delete_data(部分已安装的应用程序的数据目录)将返回。

你可以看到附件中的截图,我们将创建一个列表显示所有已安装的应用程序。

snippet_list_row.xml--------------------这个布局是由ListView适配器用于表示应用程序的细节。它显示应用程序图标、应用程序名称和应用程序包。

?xml version="1.0" encoding="utf-8"?LinearLayout xmlns:android="" android:layout_width="fill_parent" android:layout_height="wrap_content" ImageView android:id="@+id/app_icon" android:layout_width="50dp" android:layout_height="50dp" android:padding="3dp" android:scaleType="centerCrop" / LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical" android:orientation="vertical" android:paddingLeft="5dp" TextView android:id="@+id/app_name" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:textStyle="bold" / TextView android:id="@+id/app_paackage" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical" / /LinearLayout/LinearLayout

AllAppsActivity.java ##这是用于初始化和列表已安装的应用程序的主要应用程序类。从packagemanage得到应用细节列表是一个耗时的任务,我们将在AsyncTask里面做。同时,类使用自定义适配器“自定义listview applicationadapter”。 package com.javatechig.listapps;import java.util.ArrayList;import java.util.List;import android.app.AlertDialog;import android.app.ListActivity;import android.app.ProgressDialog;import android.content.ActivityNotFoundException;import android.content.DialogInterface;import android.content.Intent;import android.content.pm.ApplicationInfo;import android.content.pm.PackageManager;import android.net.Uri;import android.os.AsyncTask;import android.os.Bundle;import android.view.Menu;import android.view.MenuInflater;import android.view.MenuItem;import android.view.View;import android.widget.ListView;import android.widget.Toast;public class AllAppsActivity extends ListActivity { private PackageManager packageManager = null; private ListApplicationInfo applist = null; private ApplicationAdapter listadaptor = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); packageManager = getPackageManager(); new LoadApplications().execute(); } public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); return true; } public boolean onOptionsItemSelected(MenuItem item) { boolean result = true; switch (item.getItemId()) { case R.id.menu_about: { displayAboutDialog(); break; } default: { result = super.onOptionsItemSelected(item); break; } } return result; } private void displayAboutDialog() { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getString(R.string.about_title)); builder.setMessage(getString(R.string.about_desc)); builder.setPositiveButton("Know More", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("")); startActivity(browserIntent); dialog.cancel(); } }); builder.setNegativeButton("No Thanks!", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.show(); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); ApplicationInfo app = applist.get(position); try { Intent intent = packageManager .getLaunchIntentForPackage(app.packageName); if (null != intent) { startActivity(intent); } } catch (ActivityNotFoundException e) { Toast.makeText(AllAppsActivity.this, e.getMessage(), Toast.LENGTH_LONG).show(); } catch (Exception e) { Toast.makeText(AllAppsActivity.this, e.getMessage(), Toast.LENGTH_LONG).show(); } } private ListApplicationInfo checkForLaunchIntent(ListApplicationInfo list) { ArrayListApplicationInfo applist = new ArrayListApplicationInfo(); for (ApplicationInfo info : list) { try { if (null != packageManager.getLaunchIntentForPackage(info.packageName)) { applist.add(info); } } catch (Exception e) { e.printStackTrace(); } } return applist; } private class LoadApplications extends AsyncTaskVoid, Void, Void { private ProgressDialog progress = null; @Override protected Void doInBackground(Void... params) { applist = checkForLaunchIntent(packageManager.getInstalledApplications(PackageManager.GET_META_DATA)); listadaptor = new ApplicationAdapter(AllAppsActivity.this, R.layout.snippet_list_row, applist); return null; } @Override protected void onCancelled() { super.onCancelled(); } @Override protected void onPostExecute(Void result) { setListAdapter(listadaptor); progress.dismiss(); super.onPostExecute(result); } @Override protected void onPreExecute() { progress = ProgressDialog.show(AllAppsActivity.this, null, "Loading application info..."); super.onPreExecute(); } @Override protected void onProgressUpdate(Void... values) { super.onProgressUpdate(values); } }}

package com.javatechig.listapps;import java.util.List;import android.content.Context;import android.content.pm.ApplicationInfo;import android.content.pm.PackageManager;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.ArrayAdapter;import android.widget.ImageView;import android.widget.TextView;public class ApplicationAdapter extends ArrayAdapterApplicationInfo { private ListApplicationInfo appsList = null; private Context context; private PackageManager packageManager; public ApplicationAdapter(Context context, int textViewResourceId, ListApplicationInfo appsList) { super(context, textViewResourceId, appsList); this.context = context; this.appsList = appsList; packageManager = context.getPackageManager(); } @Override public int getCount() { return ((null != appsList) ? appsList.size() : 0); } @Override public ApplicationInfo getItem(int position) { return ((null != appsList) ? appsList.get(position) : null); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; if (null == view) { LayoutInflater layoutInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = layoutInflater.inflate(R.layout.snippet_list_row, null); } ApplicationInfo applicationInfo = appsList.get(position); if (null != applicationInfo) { TextView appName = (TextView) view.findViewById(R.id.app_name); TextView packageName = (TextView) view.findViewById(R.id.app_paackage); ImageView iconview = (ImageView) view.findViewById(R.id.app_icon); appName.setText(applicationInfo.loadLabel(packageManager)); packageName.setText(applicationInfo.packageName); iconview.setImageDrawable(applicationInfo.loadIcon(packageManager)); } return view; }};

android获取已安装应用列表的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于android获取当前应用包名、android获取已安装应用列表的信息别忘了在本站进行查找喔。


【免责声明】:

本站所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。

【关于转载】:

本站尊重互联网版权体系,本站部分图片、文章大部分转载于互联网、所有内容不代表本站观点、不对文章中的任何观点负责、转载的目的只用于给网民提供信息阅读,无任何商业用途,所有内容版权归原作者所有
如本站(文章、内容、图片、视频)任何资料有侵权,先说声抱歉;麻烦您请联系请后台提交工单,我们会立即删除、维护您的权益。非常感谢您的理解。

【附】:

二○○二年一月一日《计算机软件保护条例》第十七条规定:为了学习和研究软件内含的设计思想和原理,通过安装、显示、传输或者存储软件等方式使用软件的,可以不经软件著作权人许可,不向其支付报酬!鉴于此,也希望大家按此说明研究软件!

注:本站资源来自网络转载,版权归原作者和公司所有,如果有侵犯到您的权益,请第一时间联系我们处理!

-----------------------------------------------------------------------------------------------------------

【版权声明】:

一、本站致力于为源码爱好者提供国内外软件开发技术和软件共享,着力为用户提供优资资源。
二、本站提供的源码下载文件为网络共享资源,请于下载后的24小时内删除。如需体验更多乐趣,还请支持正版。
三、如有内容侵犯您的版权或其他利益的,请编辑邮件并加以说明发送到站长邮箱。站长会进行审查之后,情况属实的会在三个工作日内为您删除。
-----------------------------------------------------------------------------------------------------------


内容投诉
源码村资源网 » android获取已安装应用列表(android获取当前应用包名)
您需要 登录账户 后才能发表评论

发表评论

欢迎 访客 发表评论