我想从另一个班级打电话给sendPicture()
。但似乎我不能使sendPicture()
成为静态类型,因为它中有startActivity()
。我想知道是否可以从另一个班级调用它,如果是这样,怎么样?
sendPicture()
代码:
public static void sendPicture()
{
File f=new File(Environment.getExternalStorageDirectory().getAbsolutePath());
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra("address", "number");
sendIntent.putExtra("sms_body", "See attached picture");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
sendIntent.setType("image/jpg");
startActivity(sendIntent);
}
答案 0 :(得分:1)
startActivity()是Context的一种方法,因此您需要引用上下文。您可以尝试使用getApplicationContext()。startActivity(sendIntent),或将Context传递给静态方法并使用该引用。
答案 1 :(得分:0)
我不知道它是否正确,请试一试。假设你在 class1 中有这个所谓的'sendpicture()'函数,你想在的Class2 。然后在class2中编写以下代码并尝试。
Class1 cls1= new Class1();
cls1.sendpicture();