Assignment 6 MC 007

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

SIES College of Management Studies SYMCA (Revised), Sem III,

Roll No: 07

Assignment - 6

Use implicit intent to show the website, to send the text to messenger and send text to
another application.
Code:
App1:
MainActivity.java:
package com.example.p6;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {


String str ="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText ed1;
Button btn,btn1,btn2;
ed1 = findViewById(R.id.ed1);
btn = findViewById(R.id.btn);
btn1 = findViewById(R.id.btn1);
btn2 = findViewById(R.id.btn2);

//Send SMS
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str = ed1.getText().toString();
Intent sms = new Intent();
sms.setAction(Intent.ACTION_SEND);
sms.putExtra(Intent.EXTRA_TEXT,str);
sms.setType("text/plain");
startActivity(sms);
Subject: MCAL34 Mobile Computing Lab Academic Year
First Half 2023_24
SIES College of Management Studies SYMCA (Revised), Sem III,
Roll No: 07

}
});

//View Webpage
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent web = new Intent(Intent.ACTION_VIEW);
web.setData(Uri.parse("https://www.siescoms.edu.in"));
startActivity(web);
}
});

//Send Data to other App


btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str = ed1.getText().toString();
Intent oApp =new Intent(Intent.ACTION_SEND);
oApp.putExtra(Intent.EXTRA_TEXT,str);
oApp.setType("text/plain");
startActivity(oApp);
}
});
}
}

App2:
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.P6_2"
Subject: MCAL34 Mobile Computing Lab Academic Year
First Half 2023_24
SIES College of Management Studies SYMCA (Revised), Sem III,
Roll No: 07

tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
</application>
</manifest>

act2.java:
package com.example.p6_2;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

TextView tv1;
tv1= findViewById(R.id.tv1);

Intent in = getIntent();
String sharedText = in.getStringExtra(Intent.EXTRA_TEXT);
tv1.setText(sharedText);
}
}
Subject: MCAL34 Mobile Computing Lab Academic Year
First Half 2023_24
SIES College of Management Studies SYMCA (Revised), Sem III,
Roll No: 07

Output:

Subject: MCAL34 Mobile Computing Lab Academic Year


First Half 2023_24

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy