我在一个Android应用程序中遇到了一个问题,我在使用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);
}
}
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);
}
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()
在此类文件中不存在。
如何解决此问题?我将热切地等待有价值的回复。 在此先感谢。
答案 0 :(得分:1)
试试这个::
this.getPackageManager().getApplicationInfo(this.getPackageName(), 0);
答案 1 :(得分:1)
结果不像Activity类那样扩展Context。因此该方法在该类中不可用。您需要在其中调用act.getPackageManager()
而不是this.getPackageManager()
。