问题
I'm trying to modify the Android framework by displaying an Toast notification in the PasswordUnlockScreen.java file when a password verification is done. I've added the following line of code in verifyPasswordAndUnlock()
Toast.makeText(getApplicationContext(), "Verifying password", Toast.LENGTH_LONG).show();
However, I get the build error:
frameworks/base/policy/src/com/android/internal/policy/impl/PasswordUnlockScreen.java:166: cannot find symbol symbol : method getApplicationContext()
location: class com.android.internal.policy.impl.PasswordUnlockScreen
Toast.makeText(getApplicationContext(), "Verifying password", Toast.LENGTH_LONG).show();
What should I use as the context instead of getApplicationContext()?
Thanks!
回答1:
Try this one :
Toast.makeText(PasswordUnlockScreen.this, "Verifying password", Toast.LENGTH_LONG).show();
来源:https://stackoverflow.com/questions/11304267/displaying-a-toast-notification-in-android-framework