I used the code from this answer by Jared Rummler in my project, and the following code is the outcome.
public class MainActivity extends Activity {
Button dadclink;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public Intent addListenerOnButton() {
dadclink = (Button) findViewById(R.id.dadclink);
public static Intent newInstagramProfileIntent(PackageManager pm, String url) {
Intent intent = new Intent(Intent.ACTION_VIEW);
try {
if (pm.getPackageInfo("com.instagram.android", 0) != null) {
if (url.endsWith("/")) {
url = url.substring(0, url.length() - 1);
}
String natgeo = url.substring(url.lastIndexOf("/") + 1);
intent.setData(Uri.parse("http://instagram.com/_u/" + natgeo));
intent.setPackage("com.instagram.android");
return intent;
}
} catch (NameNotFoundException e) {
}
intent.setData(Uri.parse(url));
return intent;
}};
However, I got syntax errors on this line:
public static Intent newInstagramProfileIntent(PackageManager pm, String url) {
with the following errors:
- Illegal modifier for parameter newInstagramProfileIntent; only final is permitted
- Syntax error on token ",", ; expected
- Syntax error on token ")", ; expected
How to fix this?