错误而在Android中使用PackageManager而在、错误、PackageManager、Android

2023-09-05 05:18:21 作者:那句未说出口的我爱你

我在一个Android应用程序,我在工作中的问题中,我得到的错误,当我使用PackageManager。

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

中的应用是如下:

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

我收到错误 getPackageManager()不存在此类文件。

我要如何解决这个问题?我会热切地等待宝贵的答复。 在此先感谢。

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

推荐答案

结果没有延伸的上下文的喜欢你的Activity类一样。因此该方法不是在该类可用。你需要调用 act.getPackageManager()里面有代替 this.getPackageManager()

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