How to Send URL via a message in an Android application
In this Tutorial Today LEan how to send URL via a message in an Android application SMS By Url Using In Android
1.MainActivity.Java:
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button sendMessageButton = findViewById(R.id.send_message_button);
sendMessageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = "https://example.com"; // Replace with your URL
// Create the intent
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, url);
sendIntent.setType("text/plain");
// Start the activity
startActivity(Intent.createChooser(sendIntent, "Send URL via:"));
}
});
}
}
2. activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity">
<Button
android:id="@+id/send_message_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send URL via Message"
android:layout_centerInParent="true"/>
</RelativeLayout>
3.Add Code AndroidMainfeast.xml:
<uses-permission android:name="android.permission.SEND_SMS"/>
No comments:
Post a Comment