Open Facebook page from Android app?

前端 未结 26 3468
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 07:03

from my Android app, I would like to open a link to a Facebook profile in the official Facebook app (if the app is installed, of course). For iPhone, there exists the

26条回答
  •  执念已碎
    2020-11-22 07:26

    You can open the facebook app on button click as follows:-

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        this.findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {
    
                startNewActivity("com.facebook.katana");
            }
        });
    
    }
    
    public void startNewActivity( String packageName)
    {
        Intent intent = MainActivity.this.getPackageManager().getLaunchIntentForPackage(packageName);
        if (intent != null)
        {
            // we found the activity
            // now start the activity
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
        else
        {
            // bring user to the market
            // or let them choose an app?
            intent = new Intent(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setData(Uri.parse("market://details?id="+packageName));
            startActivity(intent);
        }
    }
    

提交回复
热议问题