0

AndroidManifest.xml

...

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.justjava">

    <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/Theme.JustJava">
        <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>
        </activity>
    </application>

</manifest>

... MainActivity.java(Intent Part)

...

public void SubmitOrder(View view) {


        EditText enteredName = findViewById(R.id.name_editText_view);
        String name = enteredName.getText().toString();

        CheckBox checkCream = findViewById(R.id.checkbox1);
        boolean whippedCream = checkCream.isChecked();

        CheckBox checkChocolate = findViewById(R.id.checkbox2);
        boolean chocolate =checkChocolate.isChecked();

        int price = calculatePrice(whippedCream,chocolate);
        String priceMessage =createOrderSum(name,price,whippedCream,chocolate);

        Intent intent = new Intent(Intent.ACTION_SENDTO);
        intent.setData(Uri.parse("mailto:")); // only email apps should handle this
        intent.putExtra(Intent.EXTRA_SUBJECT, "The just java order for"+ name);
        intent.putExtra(Intent.EXTRA_TEXT,priceMessage);


        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        }

    }

...

Email intent is not working on my android 11 device but it is working fine on AVD on android versions less than 11. The submit order is not doing any thing in the app. It should send an intent to email app with order summary and subject filled.

  • Remove the setData() call. Further you did not tell what happens instead. – blackapps Jan 09 '22 at 14:11
  • You could remove `resolveActivity()` and wrap your `startActivity()` call in `try`/`catch` to handle the case where there is no matching activity. Or, if you want to keep the `resolveActivity()` call, you will need to add `` to your manifest to whitelist what `Intent` structure you want to resolve. – CommonsWare Jan 09 '22 at 14:15
  • @blackapps do I need to specify what happens instead I mean why is the first bit of code that is equivalent to try block not working specifically on Android 11?? Can you help me with that. – ARSALAN AHMAD 74 Jan 09 '22 at 14:36
  • I tried to help you with my comment. But you did not react on the things i said/asked. – blackapps Jan 09 '22 at 16:11

0 Answers0