Can not send email from android apps - java

I want to send an email from android without user interaction. I use this code Send email from android
It's running good on my Samsung phone(which version is 2.3.2 and API label 9). But the same app is not working in my Walton phone (which version is 4.2.2 and API label 17). I use minsdk 8 and targetsdk 19.
Here is my manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hiddencamera"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.hiddencamera.Main"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

You can refer to the following code. It works fine.
public class Email extends Activity implements View.OnClickListener {
EditText personsEmail, intro, personsName, stupidThings, hatefulAction,
outro;
// Your mail address here
String emailAdd;
Button sendEmail;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.email);
initializeVars();
sendEmail.setOnClickListener(this);
}
private void initializeVars() {
// TODO Auto-generated method stub
sendEmail = (Button) findViewById(R.id.bSentEmail);
}
public void onClick(View v) {
// TODO Auto-generated method stub
//Your mail addresses needs to be converted to Array/List before passing, so you can append more mail_id's too
String emailaddress[] = { emailAdd };
String message = "Your mail content here ";
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject of the mail");
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
startActivity(emailIntent);
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
In Manifest just remember to add the permission for Internet once only. You have mentioned it twice.Though it do not have any effect I thunk, but still you should be careful with everything.

Related

What forces android activity to be destroyed when launching another activity

I'm trying to add in-app purchases and when I call OpenIabHelper::launchPurchaseFlow function:
I see Google Play purchase window
onStop and onDestroy are executed in my main activity without calls to onActivityResult
So in the end I left with GooglePlay window and my dead app
I tried to start another activity via startActivityForResult and it worked fine
(nothing was destroyed and onActivityResult was called), so it seems that problem is with OpenIAB library
Therefore there's my question:
What can possibly force my activity to be destroyed after calling OpenIabHelper::launchPurchaseFlow ?
It doesn't seem to be system because it has enough memory and as I said startActivityForResult works fine.
Also there's no exceptions being trown so I'm puzzled
Any help would be appreciated
MyActivity.java
public class MyActivity extends AppCompatActivity {
private OpenIabHelper m_helper;
private Boolean m_bOpenIabInitialized = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
OpenIabHelper.Options.Builder builder = new OpenIabHelper.Options.Builder()
.addAvailableStores(new GooglePlay(this,null))
.addPreferredStoreName(OpenIabHelper.NAME_GOOGLE)
.setStoreSearchStrategy(OpenIabHelper.Options.SEARCH_STRATEGY_INSTALLER_THEN_BEST_FIT)
.setVerifyMode(OpenIabHelper.Options.VERIFY_SKIP)
.setCheckInventory(false);
m_helper = new OpenIabHelper(this, builder.build());
m_helper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
m_bOpenIabInitialized = result.isSuccess();
}
});
}
public void onListViewItemClicked(String sku, String payload) {
if (m_bOpenIabInitialized == null || !m_bOpenIabInitialized) return;
m_helper.launchPurchaseFlow(this, sku, 10001, null, payload);
}
#Override
public void startActivityForResult(Intent intent, int RequestCode) {
// never reaches here
Log.d(TAG, "startActivityForResult()");
}
#Override
protected void onActivityResult(int RequestCode, int ResultCode, Intent data) {
// never reaches here
Log.d(TAG, "onActivityResult()");
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example" >
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="com.android.vending.BILLING" />
<application
android:allowBackup="true"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity
android:name=".MyActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:configChanges="orientation|screenSize|keyboardHidden|screenLayout">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Have you tried changing the activity's launchMode? Maybe the singleTop launch mode will preserve your activity:
<activity
android:name=".MyActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:configChanges="orientation|screenSize|keyboardHidden|screenLayout"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You can find more about launch modes here:
https://developer.android.com/guide/topics/manifest/activity-element.html#lmode

Android SMS app Crashes when received sms contains lots of numbers

i have written the following code to get the received sms in phone
package com.example.recieveandsendsms;
public class IncomingSms extends BroadcastReceiver{
final SmsManager sms=SmsManager.getDefault();
#Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
str = msgs[i].getMessageBody().toString();
}
}
}
}
Following is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.recieveandsendsms"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS">
</uses-permission>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
<uses-permission android:name="android.permission.WRITE_CALL_LOG"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.recieveandsendsms.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.example.recieveandsendsms.IncomingSms">
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
</application>
</manifest>
it works fine when I receive the normal message
means example Ex1: He was not angry or upset I was remember
was drawn on with us just a little thing.
when message in Ex1 comes it works fine
but when Ex2: UB 9000000000 9787878787-asghkajhsgk kjashgkas
but when sms like Ex2 compes the application crashes i am not able get what is wrong the message in Ex2
Please anyone can help me to tell where i am going wrong
The library version for reading and writing data was mismatch so it was crashing and it was not giving any error :(

Android - Starting service by booting and wifi on

I am sorry for my bad english, I am from germany.
I try to explain my problem.
I'll start a service, if the smartphone booted and is internet connection enabled. I hope you can understand me.
This is my Autostart
public class Autostart extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
try {
context.startService(new Intent(context, SpyService.class));
} catch (Exception ex) {
}
}
}
}
and this is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.caglar.spyme"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="21" />
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" />
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<receiver android:name=".Autostart" android:enabled="true" android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<activity android:name=".StartService">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".SpyService"
android:enabled="true" />
</application>
</manifest>
If i restart my phone and open the wlan, the service is not started. Why?
use this code in your broadcast.
public class Autostart extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager connectivityManager = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE );
NetworkInfo activeNetInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
boolean isConnected = activeNetInfo != null && activeNetInfo.isConnectedOrConnecting();
if (isConnected)
// start your service
}
}

Android Air Native Extension to install new apk version throws "no activity found to handle intent"

All I want is to install (ask user for) new application version stored on sdcard as .apk file using Adobe Air Native Extension.
Here is my ANE function code:
#Override
//args[0] is the path to local stored apk (logs as /storage/sdcard0/testStorage/updates/1.1apk)
public FREObject call(FREContext _context, FREObject[] args) {
context = _context;
try {
Intent promptInstall = new Intent(Intent.ACTION_VIEW);
promptInstall.setDataAndType(Uri.parse(args[0].getAsString()), "application/vnd.android.package-archive");
promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.getActivity().startActivity(promptInstall);
alert("Okay", "start was!"); //using AlertDialog for debug purpose
} catch (Exception e) {
alert("Error!", e.getLocalizedMessage());
e.printStackTrace();
}
return null;
}
And here is manifest I'm using:
<android>
<manifestAdditions><![CDATA[<manifest android:installLocation="auto">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-feature android:name="android.hardware.microphone" android:required="false" />
<application android:hardwareAccelerated="true" />
<application android:debuggable="true"/>
<application>
<activity android:name="android.intent.action.VIEW">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.RESTART_PACKAGES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:required="true" android:name="android.hardware.touchscreen.multitouch" />
</manifest>]]></manifestAdditions>
</android>
But I'm always getting "No activity found to handle Intent error":
No Activity found to handle Intent { act=android.intent.action.VIEW dat=/storage/sdcard0/testStorage/updates/1.1.apk typ=application/vnd.adnroid.package-archive flg=0x10000000}
Added
File setupFile = new File(args[0].getAsString());
alert("Is exists?", Boolean.toString(setupFile .exists())); //output as true
Said that file is real and args[0] path is correct.
After hours of google i found that the problem was in missing "file://"
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + args[0].getAsString()), "application/vnd.android.package-archive");
Now everything work fine!

Android referral tracking not working with Google play

I am trying to implement referral tracking on downloads from the Google play.
Before uploading to Google Play, when I tried testing the app using below script, its working fine and i am getting referral string.
adb shell
am broadcast -a com.android.vending.INSTALL_REFERRER -n <my.myPackage>/.<path.up.until.my.CustomBroadcastReceiver> --es "referrer" "utm_source%3Dentity%26utm_medium%3Dsocial%26utm_campaign%3Dwo_referrer%26referrerId%3D173%26entity%3Dfacebook%26email%3Dmideeshp%40email.com"
After running this code, I am decoding the referral string and my server getting updated according to the referral string. But when I deployed this app to Google play, I am not getting any referral string from Google play. I am using Google Analytics V2 for both analytic tracking and referral tracking.
Below one is my custom BroadcastReceiver.
public class InstallReferrerReceiver extends BroadcastReceiver {
private static final String TAG = "InstallReferrerReceiver";
#Override
public void onReceive(Context context, Intent intent) {
HashMap<String, String> values = new HashMap<String, String>();
try {
if (intent.hasExtra("referrer")) {
Toast.makeText(context, "Inside app refferal", 5000).show();
String url = intent.getStringExtra("referrer");
final String referrer = URLDecoder.decode(url, "UTF-8");
String referrers[] = referrer.split("&");
int i = 0;
for (String referrerValue : referrers) {
String keyValue[] = referrerValue.split("=");
values.put(URLDecoder.decode(keyValue[0], "UTF-8"),
URLDecoder.decode(keyValue[1], "UTF-8"));
Log.i("" + i, keyValue[0] + "=" + keyValue[1]);
}
new AsyncTask<String, String, JSONObject>() {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected JSONObject doInBackground(String... params) {
// TODO Auto-generated method stub
String referrerUrl = "MyserverUrl?action=storerefer&" + referrer;
Log.i("purl address", referrerUrl);
JSONObject json = RestJsonClient.connect(referrerUrl);
return json;
}
#Override
protected void onPostExecute(JSONObject result) {
// TODO Auto-generated method stub
try {
if (result == null) {
Log.i("json null", "12");
} else {
String status, error;
status = result.getString("status");
error = result.getString("error");
if (status.equals("success")) {
Log.i("referrer", "referrer status success");
}
if (status.equals("failure")) {
Log.i("referrer", "referrer status failure");
}
}
} catch (JSONException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
super.onPostExecute(result);
}
}.execute();
}
} catch (Exception e) {
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.package.name"
android:versionCode="4"
android:versionName="1.2.1" >
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="my.package.name.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<permission
android:name="my.package.name.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar" >
<activity
android:name="my.package.name.Splash"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:windowSoftInputMode="stateHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="my.package.name.InstallReferrerReceiver"
android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="my.package.name" />
</intent-filter>
</receiver>
<service android:name="my.package.name.GCMIntentService" />
</application>
What should I do to get referral string from Google Play ?
you can write this simple reciever:
public class DetectInstall extends BroadcastReceiver{
private String referrerId;
#Override
public void onReceive(Context context, Intent intent) {
if ((null != intent)
&& (intent.getAction().equals("com.android.vending.INSTALL_REFERRER"))) {
Log.e("Message", "App is getting installed first time..");
referrerId = intent.getStringExtra("referrer");
}
}
}
then in manifest add the receiver tag inside the application like this :
<application
android:hardwareAccelerated="true"
android:icon="#drawable/ic_bmg"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/AppTheme" >
<receiver
android:name=".DetectInstall"
android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
then you will need to send the referrer parameter to the google playstore URL Like this :
https://play.google.com/store/apps/details?id=you.package.name&hl=en&referrer=you will get this first time when you install app
referrer field is required, whatever string u pass in referrer field you will get it in the broadcast reciever

Categories