1

Hi there I am making my app and I am worried that I might have left some permissions out and can really never be sure I have used the right permissions can you put in any sort of code to see what my app is actually using? or something like that as it is always a guessing game for me when selecting my permissions as I can never be sure.

Heres an example I make a "Check for Updates" Button. From that I launch an Intent to go to my app in the market is that using the internet connection ? or am I just using an Intent because some people will not have a working data connection so would I have to write access full network or something like that? Its just really confusing me

  • 1
    Try http://stackoverflow.com/questions/7203668/how-permission-can-be-checked-at-runtime-without-throwing-securityexception – Seraphim's May 28 '13 at 11:00
  • Thanks for that but I have already tried it and it does not work and I would like to have a list of what permissions my app uses – user2283550 May 28 '13 at 11:04
  • I was googling about lint. I've never seen any specific warning aout permission, yet... your question is good – Seraphim's May 28 '13 at 11:12
  • What has this question got to do with Eclipse? Why not call it "Android Earth" since you're (probably) on Earth when you're developing? – mah May 28 '13 at 11:42
  • "on Android Eclipse" the program duh! – user2283550 May 28 '13 at 11:43
  • @user2283550 there's no such thing as "Android Eclipse" so consider that before posting things like "duh". Eclipse is a development environment, it does not run Android. Android is an operating system and it happens that Eclipse is the most popular tool to develop for it, however Eclipse has _absolutely nothing_ to do with how the operating system runs. – mah May 28 '13 at 11:48
  • Sorry, bad copy/paste. I was talking about Android/Eclipse and Lint features to check permissions in code. At this moment I see Lint does not check permissions. Or am I wrong? – Seraphim's May 28 '13 at 12:08

2 Answers2

0

I think u have to check it during testing phase of apps.if there is not proper permissions given by u then the apps give error and u can add proper permission according to error.

PankajSharma
  • 1,529
  • 14
  • 27
  • Not necessarily as I think I am using the internet but I have not put a permission on it so that actually wont work – user2283550 May 28 '13 at 11:36
0

Here is an example to walk through permissions:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    PackageManager pm = getPackageManager();
    try {
        PackageInfo pi = pm.getPackageInfo("<INTERESTING PACKAGE NAME>", PackageManager.GET_PERMISSIONS);
        if ((null == pi.requestedPermissions) ||
            (pi.requestedPermissions.length == 0)) {
            Log.d("NOTE", "Package has NO permissions!");
            return;
        }

        for (int i = 0; i < pi.requestedPermissions.length; ++i) {
            Log.d("NOTE", pi.requestedPermissions[i] + " " + checkCallingOrSelfPermission(pi.requestedPermissions[i]));
        }
    } catch (NameNotFoundException e) {
        Log.d("ERR", "Package name is wrong!");
    }
}

Edit: your question seems to ask what permissions your app is using; this code tells your app what permissions you've requested. If you want to know what is being used, you need to strip all permissions from your app (which will cause runtime errors if you actually need any of them), and then through reading error logs and/or incrementally adding permissions until things work correctly, determine by hand what is actually needed.

mah
  • 39,056
  • 9
  • 76
  • 93
  • I have tried putting that in and this is what I get [2013-05-28 12:50:02 -.apk on device '001917910fac5e': timeout [2013-05-28 12:50:02 - ] Launch canceled! – user2283550 May 28 '13 at 11:50
  • The error you're getting has nothing to do with any code in the apk, it's a communication issue between your device or AVD and your host. Restarting the device/AVD should address it. – mah May 28 '13 at 11:55
  • do you know the bit where yo wrote "" should i do "" or "My package Name" ? – user2283550 May 28 '13 at 12:06
  • You can either replace that with the actual package name you're using (as defined in the AndroidManifest.xml file, such as "com.my.app"), or with the name of any other package that is installed on the device. The < and > are not to be included. – mah May 28 '13 at 12:09
  • Ok so I have now done that but in My Logcat I do not know what to find what am I supposed to look for ? – user2283550 May 28 '13 at 12:17
  • This was an example for how to programatically determine (at run time) what permissions you've got. Be sure you read my edit, where I addressed that I may have missed the point of what you're looking for. I may have added that just after you read the original answer I posted. – mah May 28 '13 at 12:19