1

I got a problem in one Android Application which I am working in which I am getting error when I use PackageManager.

The Application is as follows:

Home.java

package com.main.home;

public class Home extends Activity
{
    //onclicking a Button say "send"
    send.onClickListener() 
    {
        public void onClick() {
            Intent i =new Intent();
            i.setClassName("com.main.home", "com.main.home.home1");
            startActivity(i); 
    }
}

Home1.java

package com.main.home;

import com.andr.resulting.Result ;

public class Home1 extends Activity  {
    EditText et=(EditText)findViewById(R.id.e1);
    //Clicking on forwardButton in that onClick()

    public void onClick()
    {
        String s[] = {e1.getText().toString(),""};
        //Calling a method in a class Result of another package which is not activity
        Result.finalfunc(Home1.this,s);

}

Result.java

package com.andr.resulting;   //different package

public class Result {
    public static void finalfunc(Activity act,String[] re) ...
    //Here I want to get the details of this particular class's package (com.andr.resulting) using PackageManager

    // I tried like this:
    Result.this.getPackageManager().getApplicationInfo(Result.getPackageName(),0))

I am getting error getPackageManager() does not exists in this class file.

How do I solve this issue? I will be eagerly waiting for valuable reply. Thanks in Advance.

5
  • 5
    dude... you have two stackoverflow users, and have posted several questions, and have been downvoted too many times, and you still don't know neither how to format the code nor how to ask good questions? I think you chose the wrong career.
    – Cristian
    Sep 7, 2010 at 18:21
  • Home1.java imports the Result package like this import com.android.resulting.Result in its class Sep 7, 2010 at 18:23
  • Is this user an actual android or bot? Sep 7, 2010 at 20:07
  • 3
    You really need to learn how to format your code better in the questions you ask. I tried to edit your question to fix it for you, but you have so many HTML tags in there it was kind of ridiculous. Look at some other questions on this site and see how other people format their questions.
    – Mark B
    Sep 7, 2010 at 20:22
  • 4
    After formatting the code, there are syntax errors that you'll need to take care of first. Please look at the edit screen to see how I formatted this for display on Stack Overflow, and follow that formatting in the future. It makes your posts much more readable. Sep 7, 2010 at 20:35

2 Answers 2

1

try this::

this.getPackageManager().getApplicationInfo(this.getPackageName(), 0);
1
  • I have to send this package information to a method of a class of other package which is as follows:<br> I used "this...." as said by you <br>.<br><br> otherclass.sendTo("hi","hrll",this.getPackageManager().getApplicationinfo(this.getPacakageName(),0)); <br> But I am getting error as "create method getPackageName() and getPacakgeManager() <br>. What will be the solution for this problem? Sep 7, 2010 at 18:54
1

Result doesn't extend Context like your Activity class does. So the method isn't available in that class. You need to call act.getPackageManager() inside there instead of this.getPackageManager().

4
  • Then we will get package information of that activity (i.e.Home1), but not result.java 's package information. I actually wants result.java 's package information. The solution that u have given will work with out errors but it is giving package information of Activity (Home1.java) but not result.java. How can we get the package information of Result.java ? And also one more query ,using packagemanager class can we get information about variables of that package? Sep 7, 2010 at 20:16
  • What kind of information are you wanting to get from that Package Manager? You are calling getApplicationInfo(). Result.java resides in the same application as Home.java correct? The application info should be the same. You haven't even instantiated an instance of Result, you just have a static method you are calling. I really don't see what you expect to get from that.
    – Mark B
    Sep 7, 2010 at 20:21
  • Result.java resides in package com.andr.resulting. I want this inf. to get from Result.java through PackageManager. Sep 7, 2010 at 20:54
  • Sounds like you need to use reflection instead of PackageManager. I still don't understand WHY you need to do any of this though. Perhaps if you explained the use case people might be able to better help you.
    – Mark B
    Sep 8, 2010 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.