This video shows the steps to start any other App from your Android App using the intent mechanism. To develop this feature, it is important to know the exact package name of the App being opened.
We hope you like this video. For any query, suggestions or appreciations we will be glad to hear from you at: programmerworld1990@gmail.com
Source Code:
package com.example.myopenfunctionapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Telephony;
import android.view.View;public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}public void gmailButton(View view){
Intent intent = getPackageManager().getLaunchIntentForPackage(“com.google.android.gm”);
if(intent != null){
startActivity(intent);
}
}public void whatsappbutton(View view){
Intent intent = getPackageManager().getLaunchIntentForPackage(“com.whatsapp”);
if(intent != null){
startActivity(intent);
}
}public void FacebookButton(View view){
Intent intent = getPackageManager().getLaunchIntentForPackage(“com.facebook.katana”);
if(intent != null){
startActivity(intent);
}
}public void smsButton(View view){
Intent intent = getPackageManager().getLaunchIntentForPackage(Telephony.Sms.getDefaultSmsPackage(this));
if(intent != null){
startActivity(intent);
}
}
}
<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”com.example.myopenfunctionapplication”><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=”.MainActivity”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” /><category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application></manifest>
<?xml version=”1.0″ encoding=”utf-8″?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:app=”http://schemas.android.com/apk/res-auto”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
tools:context=”.MainActivity”><Button
android:id=”@+id/button”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginStart=”156dp”
android:layout_marginTop=”101dp”
android:onClick=”gmailButton”
android:text=”@string/gmail”
app:layout_constraintStart_toStartOf=”parent”
app:layout_constraintTop_toTopOf=”parent” /><Button
android:id=”@+id/button2″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginStart=”154dp”
android:layout_marginTop=”53dp”
android:onClick=”whatsappbutton”
android:text=”@string/whatsapp”
app:layout_constraintStart_toStartOf=”parent”
app:layout_constraintTop_toBottomOf=”@+id/button” /><Button
android:id=”@+id/button3″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginStart=”154dp”
android:layout_marginTop=”51dp”
android:onClick=”FacebookButton”
android:text=”@string/facebook”
app:layout_constraintStart_toStartOf=”parent”
app:layout_constraintTop_toBottomOf=”@+id/button2″ /><Button
android:id=”@+id/button4″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginStart=”151dp”
android:layout_marginTop=”64dp”
android:onClick=”smsButton”
android:text=”@string/sms”
app:layout_constraintStart_toStartOf=”parent”
app:layout_constraintTop_toBottomOf=”@+id/button3″ />
</androidx.constraintlayout.widget.ConstraintLayout>
<resources>
<string name=”app_name”>My OpenFunctionApplication</string>
<string name=”gmail”>Gmail</string>
<string name=”whatsapp”>WhatsApp</string>
<string name=”facebook”>Facebook</string>
<string name=”sms”>SMS</string>
</resources>