Advertisement

Open any app using this code in android studio




activitymain.xml :-


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">


<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Gmail"
android:onClick="Gmail"
/>

<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Whatspp"
android:onClick="Whatsapp"
/>

<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="facebook"
android:onClick="Facebook"
/>

<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Gallery"
android:onClick="gallery"
/>
<Button
android:id="@+id/button5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Youtube"
android:onClick="Youtube"
/>

<Button
android:id="@+id/button6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Chrome"
android:onClick="chrome"
/>

<Button
android:id="@+id/button7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Instagram"
android:onClick="Instagram"
/>
<Button
android:id="@+id/button8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="twitter"
android:onClick="twitter"
/>


</LinearLayout> 


MainActivity.java :-


package com.example.ecasa;
import androidx.appcompat.app.AppCompatActivity;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
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 Facebook(View view) {
Intent intent = getPackageManager().getLaunchIntentForPackage("com.facebook.katana");
if (intent != null) {
startActivity(intent);
}
}
public void Whatsapp(View view) {
Intent intent = getPackageManager().getLaunchIntentForPackage("com.whatsapp");
if (intent != null) {
startActivity(intent);
}
}
public void Gmail(View view) {
Intent intent = getPackageManager().getLaunchIntentForPackage("com.google.android.gm");
if (intent != null) {
startActivity(intent);
}
}
public void gallery(View view) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivity(intent);
}

public void Youtube(View view) {
Intent intent = new Intent(Intent.ACTION_VIEW , Uri.parse("https://www.youtube.com/channel/UCRmoG8dTnv0B7y9uoocikLw"));
startActivity(intent);
}
public void chrome(View view) {
Intent intent = getPackageManager().getLaunchIntentForPackage("com.android.chrome");
if (intent != null) {
startActivity(intent);
}
}


public void Instagram(View view) {
Uri uri = Uri.parse("http://instagram.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
public void MxPlayer(View view) {
Intent intent = getPackageManager().getLaunchIntentForPackage("com.android.chrome");
if (intent != null) {
startActivity(intent);
}
}
public void twitter(View view) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.twitter.android", "com.twitter.android.ProfileActivity");
this.startActivity(intent);
}
}

Post a Comment

0 Comments