In order to open any website in Firefox Mozilla app, you will need to first download Firefox Mozilla app.
If the app is not installed, this code won't work and the app will rotate to landscape to show error. This is how the output will be:
This is the output when the Firefox Mozilla app is installed.
---------------------------------------firefox_mozilla_activity.xml--------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<Button
android:id="@+id/fma_openFirefoxBTN"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="80dp"
android:text="Open Firefox Mozilla"
android:textColor="#ffffff"
android:background="@color/colorPrimary"/>
</LinearLayout>
---------------------------------------
------------------------------- FirefoxOpenerActivity.java ---------------------------
package com.app.yourappname;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class FirefoxMozillaActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.firefox_mozilla_activity);
final Button openFirefoxBtn = findViewById(R.id.fma_openFirefoxBTN);
openFirefoxBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openFirefoxMozilla();
}
});
}
private void openFirefoxMozilla() {
try {
String url = "http://www.java.com";
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName("org.mozilla.firefox", "org.mozilla.firefox.App"));
intent.setAction("org.mozilla.gecko.BOOKMARK");
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse(url));
startActivity(intent); }
catch(Exception e) {
Toast.makeText(this,"Error: "+e, Toast.LENGTH_LONG).show();
}
}
}
------------------------------------------------------------------ In the manifest file declare Activity name ----------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.yourappname">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".FirefoxMozillaActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>---------------------------------------------
No comments:
Post a Comment