this will be a bit annoying to explain, but bear with me:
So i have a simple android app with buttons, one opens a facebook page (first checks if the app is installed, and will open in that, else will open same page in browser), the other opens a website url in the browser
The problem i'm having is that, instead of opening them as seperate applications, it seems to be opening the browser/fb app inside my original app.
So if i open the fb page through my app, and click the back button, it brings me back to my app's home screen. If i click the fb button, and minimize the app, and go into the ACTUAL fb app, it hasn't changed anything there.
So my app is not actually using the standalone fb app, just calling it up inside itself.
(hope that makes sense...) here is the code i used;
//just defined button variables
button facebook, shop;
//now for the onCreate method
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
facebook = (Button) findViewById(R.id.facebook);
shop = (Button) findViewById(R.id.shop);
facebook.setOnClickListener(new View.onClickListener(){
public void onClick(View v) {
try{ //left out the profile id on purpose...
Intent facebook = new Intent(Intent.ACTON_VIEW, Uri.parse("fb://profile/xxxx"));
startActivity(facebook);
}catch(Exception e){
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse ("http://www.facebook.com/example")));
}
}
});
The shop button is set up the same, only without the try/catch, it will only open in the browser.
How do i make it so that it sends the request to the actual fb app/browser, instead of what it's currently doing? Any help/tips are gratefully welcome :)
Create a new layout with layout/a.xml
Open the layout file & then add a WebView, assign an ID so you can access the widget later.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
<uses-permission android:name="android.permission.INTERNET" />
public class WebActivity extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
WebView mywebview = (WebView) findViewById(R.id.webview);
WebSettings webSettings = mywebview.getSettings();
webSettings.setJavaScriptEnabled(true);
mywebview.loadUrl("http://www.facebook.com");
}
}
mywebview.setWebViewClient(new WebViewClient())
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
facebook.setOnClickListener(new View.onClickListener(){
public void onClick(View v) {
try{
ApplicationInfo info = getPackageManager().getApplicationInfo("com.facebook.katana", 0 );
boolean isFacebookInstalled = true;
}
catch( PackageManager.NameNotFoundException e ){
isFacebookInstalled=false;
}
if(isFacebookInstalled)
{
//start the facebook app
Intent intent = new Intent("android.intent.category.LAUNCHER");
intent.setClassName("com.facebook.katana", "com.facebook.katana.LoginActivity");
startActivity(intent);
}
else
{
Intent facebook = new Intent(getApplicationContext(),WebActivity.class);
startActivity(facebook);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With