I am relearning Java, and am coming across the term ctx
in some contexts. Specifically in Android code.
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void goToFb (View view) {
startActivity(newFacebookIntent(this.getPackageManager(), "http://facebook.com/biddingo"));
/**
* <p>Intent to open the official Facebook app. If the Facebook app is not installed then the
* default web browser will be used.</p>
*
* <p>Example usage:</p>
*
* {@code newFacebookIntent(ctx.getPackageManager(), "https://www.facebook.com/JRummyApps");}
*
* @param pm
* The {@link PackageManager}.
* @param url
* The full URL to the Facebook page or profile.
* @return An intent that will open the Facebook page/profile.
*/
public static Intent newFacebookIntent(PackageManager pm, String url){
Uri uri = Uri.parse(url);
try {
ApplicationInfo applicationInfo = pm.getApplicationInfo("com.facebook.katana", 0);
if (applicationInfo.enabled) {
// https://stackoverflow.com/a/24547437/1048340
uri = Uri.parse("fb://facewebmodal/f?href=" + url);
}
} catch (PackageManager.NameNotFoundException ignored) {
}
return new Intent(Intent.ACTION_VIEW, uri);
}
}
I get an error in my code and can't find any information anywhere regarding this.
Is it some sort of placeholder?
Edit:
Replacing ctx
with this
seems to prevent the error message, but doesn't seem to fix the code correctly. The facebook app opens, but to a blank page and doesn't load anything else