tags:

views:

92

answers:

2

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.

A: 

try this::

this.getPackageManager().getApplicationInfo(this.getPackageName(), 0);
Jorgesys
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?
Android_prog
A: 

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().

mbaird
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?
Android_prog
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.
mbaird
Result.java resides in package com.andr.resulting. I want this inf. to get from Result.java through PackageManager.
Android_prog
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.
mbaird