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.开发者_Python百科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.
try this::
this.getPackageManager().getApplicationInfo(this.getPackageName(), 0);
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()
.
精彩评论