简体   繁体   中英

how to send information about android device in email subject

I know how to send email from android application and this is my code

Uri uri = Uri.parse("mailto:prayers@e-orthodoxy.net");
    Intent send = new Intent(Intent.ACTION_SENDTO, uri);
    send.putExtra(Intent.EXTRA_SUBJECT, "Review");
    startActivity(Intent.createChooser(send, "Review"));

but how to send

1- device model

2- android version

3- application version

within the subject so they will be wroted automatically

This is an example, into Intent.EXTRA_TEXT set the device information

Intent msg = new Intent(Intent.ACTION_SEND);
            String[] recipients = { "mailto:prayers@e-orthodoxy.net" };
            String[] carbonCopies = { "" };
            msg.putExtra(Intent.EXTRA_EMAIL, recipients);
            msg.putExtra(Intent.EXTRA_CC, carbonCopies);
            msg.putExtra(Intent.EXTRA_TEXT, getDeviceInformation( getResources().getString(R.string.appversion)));
            msg.putExtra(Intent.EXTRA_SUBJECT, "this is an email");
            msg.setType("message/rfc822");
            startActivity(Intent.createChooser(msg, "Email:"));

this is my method, you can send the appversion from strings.xml:

public static String getDeviceInformation(String appversion){
    String info = "\n\n"+android.os.Build.MODEL+" "+"/"+android.os.Build.VERSION.RELEASE+"/"+ appversion;
    return info;
}

or you can get the app version from your Manifest.xml file

public static String getDeviceInformation(){
PackageManager manager = this.getPackageManager();
PackageInfo infoPackage = manager.getPackageInfo(this.getPackageName(), 0);
String appversion = infoPackage.versionName;
        String info = "\n\n"+android.os.Build.MODEL+" "+"/"+android.os.Build.VERSION.RELEASE+"/"+ appversion;
        return info;
}

to get the android version you will use :

android.os.Build.VERSION.RELEASE

or

android.os.Build.VERSION.SDK_INT

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM