activity manager - How can I determine permission of Running apps programmatically in android? -
I want to see permission to run android apps in my software.
For this reason, I have the following code:
list & lt; App & gt; Apps = New Arrestist & lt; App & gt; (); ActivityManager am = (ActivityManager) this.getSystemService (ACTIVITY_SERVICE); PackageManager packageManager = getPackageManager (); & Lt; RunningAppProcessInfo & gt; L = am.getRunningAppProcesses (); Iterator & LT; RunningAppProcessInfo & gt; I = L. Knitter (); PackageManager pm = this.getPackageManager (); Int row_count = 0; While (i.hasNext ()) {ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo) (i.next ()); Try {CharSequence c = pm.getApplicationLabel (pm.getApplicationInfo (info.processName, PackageManager.GET_META_DATA)); App app = new app (); App.setTitle (c.toString ()); App.setPackageName (l.get (ROW_COUNT) .processName); PackageInfo packageInfo = packageManager.getPackageInfo (l.get (line_ count) .processName, PackageManager.GET_PERMISSIONS); String [] reqPermission = packageInfo.requestedPermissions; App.set_Permission_Info (reqPermission); // app.setVersionName (p.versionName); // app.setVersionCode (p.versionCode); // Charanjance description = p.applicationInfo.loadDescription (package manager); // app.setDescription (description! = Null? Description.Torth (): ""); ROW_COUNT ++; // app.setSize (p.s) apps.add (app); } Hold (Exception E) {} But there is a problem.
When I run my app, I know that the name of the app and the app's package name is not consistent. Why is this problem presented?
The main problem is described:
We believe that an app called "EBOOK_Reader" and "camera" is running in my device. Package name is "com.a.b" and "com.c.d" respectively. The problem with this code is not with the proper app name proper package name.
This package name for "Com.Ab" from "camera" and "com.cd" shows the name "ebook_raderer", which is not desired.
How can detect this problem can be solved? ThankYou
app name and app's package name usually is different you better package Use the name because it is unique across the entire device.
Update: Now I understand your problem. Thanks for clarifying. This variable is due to row_count , in fact you are using two different iterator variables. That's why getting your 2 different results you row_count is not required because you have already i to Intrattr to try the updated code: Actually l.get (row_count) .processName was replaced by info.processName . From the list & lt; Applications & gt; Apps = New Arrestist & lt; App & gt; (); ActivityManager am = (ActivityManager) this.getSystemService (ACTIVITY_SERVICE); PackageManager packageManager = getPackageManager (); & Lt; RunningAppProcessInfo & gt; L = am.getRunningAppProcesses (); Iterator & LT; RunningAppProcessInfo & gt; I = L. Knitter (); PackageManager pm = this.getPackageManager (); // int row_road = 0; // Feel free to delete (I.hasNext ()) for this (ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo) (i.next ()); {CharSequence c = pm.getApplicationLabel ( Try pm.getApplicationInfo (info.processName, PackageManager.GET_META_DATA)) or, app app = new app (); app.setTitle (c.toString ()); app.setPackageName (info.processName); PackageInfo packageInfo = packageManager. getPackageInfo (info.processName, PackageManager.GET_PERMISSIONS); string [] reqPermission = packageInfo.requestedPermissions; app.set_Permission_Info (reqPermission); // app.setVersionName (p.versionName); // app.setVersionCode (p.versionCode); / / Charity details = p.applicationInfo.loadDescription (package manager); // app.setDescription (Viv O! = Null? Details. Tothr (): ""); // ROW_COUNT ++; // no need for this // app.setSize (ps) Feel free to remove apps.add (app) Do;} hold (exception e) {}
Comments
Post a Comment