My app used to work when it was running in the background. The app simply sends a text message to a person whenever it receives a text message (essentially an away message).
With the new update they removed the permission BROADCAST_SMS which is what I think was allowing the app to operate in the background.
So my problem is this, I need my app to work when it is not displayed. In other words, My app currently works as expected when it is open and focused but as soon as the user minimizes/sends the app to the background, the app no longer works.
Here is the code behind my manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.katianie.awayreply2"
android:versionCode="2"
android:versionName="2.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:persistent="true" >
<activity
android:name="com.katianie.awayreply2.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>
</application>
</manifest>
Here is how I am sending a sms text message:
public void sendTextMessage(String phoneNo, String message)
{
//Used to detect when the sent text message was/was not delivered.
String actionStr = "android.provider.Telephony.SMS_DELIVERED";
Intent theDeliveredIntent = new Intent(actionStr);
PendingIntent deliveredPendingIntent = PendingIntent.getBroadcast(myMainActivity, 0, theDeliveredIntent, 0);
SmsManager smsManager = SmsManager.getDefault();
//When the SMS has been delivered, Notify the user with a simple toast.
myMainActivity.registerReceiver(new BroadcastReceiver()
{
//Called when the away message has gotten to the destination.
@Override
public void onReceive(Context arg0, Intent arg1)
{
int resultCode = getResultCode();
if(resultCode == Activity.RESULT_OK)
{
Toast.makeText(myMainActivity.getBaseContext(), "Away message delivered.", Toast.LENGTH_SHORT).show();
}
else if(resultCode == Activity.RESULT_CANCELED)
{
Toast.makeText(myMainActivity.getBaseContext(), "Away message could NOT be delivered.", Toast.LENGTH_SHORT).show();
}
myHasSentMessage = false;
}
}, new IntentFilter(actionStr));
//Send the text message
if(!myHasSentMessage)
{
smsManager.sendTextMessage(phoneNo, null, message, deliveredPendingIntent, null);
}
}