Skip to content

Commit

Permalink
Add support for default SMS app
Browse files Browse the repository at this point in the history
  • Loading branch information
serso committed Feb 11, 2014
1 parent e5ae9b7 commit 1528fdc
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 7 deletions.
50 changes: 47 additions & 3 deletions app/AndroidManifest.xml
Expand Up @@ -42,7 +42,7 @@
<uses-feature android:name="android.hardware.wifi" android:required="false"/> <uses-feature android:name="android.hardware.wifi" android:required="false"/>
<uses-feature android:name="android.hardware.telephony" android:required="false"/> <uses-feature android:name="android.hardware.telephony" android:required="false"/>


<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="18"/> <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19"/>


<application android:allowBackup="true" android:debuggable="true" android:hardwareAccelerated="true" <application android:allowBackup="true" android:debuggable="true" android:hardwareAccelerated="true"
android:icon="@drawable/mpp_app_icon" android:label="@string/mpp_app_name" android:icon="@drawable/mpp_app_icon" android:label="@string/mpp_app_name"
Expand All @@ -51,8 +51,8 @@
<activity android:label="@string/mpp_app_name" android:name=".StartActivity" <activity android:label="@string/mpp_app_name" android:name=".StartActivity"
android:windowSoftInputMode="adjustPan"> android:windowSoftInputMode="adjustPan">


<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>


Expand Down Expand Up @@ -94,5 +94,49 @@
</intent-filter> </intent-filter>
</receiver> </receiver>


<!-- BroadcastReceiver that listens for incoming SMS messages -->
<receiver android:name=".realms.sms.SmsReceiver"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_DELIVER"/>
</intent-filter>
</receiver>

<receiver android:name=".realms.sms.SmsReceiver"
android:permission="android.permission.BROADCAST_WAP_PUSH">
<intent-filter>
<action android:name="android.provider.Telephony.WAP_PUSH_DELIVER"/>
<data android:mimeType="application/vnd.wap.mms-message"/>
</intent-filter>
</receiver>

<!-- Activity that allows the user to send new SMS/MMS messages -->
<activity android:name=".realms.sms.ComposeSmsActivity">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<action android:name="android.intent.action.SENDTO"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="sms"/>
<data android:scheme="smsto"/>
<data android:scheme="mms"/>
<data android:scheme="mmsto"/>
</intent-filter>
</activity>

<!-- Service that delivers messages from the phone "quick response" -->
<service android:name=".realms.sms.HeadlessSmsSendService"
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.RESPOND_VIA_MESSAGE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="sms"/>
<data android:scheme="smsto"/>
<data android:scheme="mms"/>
<data android:scheme="mmsto"/>
</intent-filter>
</service>

</application> </application>
</manifest> </manifest>
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -464,7 +464,7 @@
</sourceDirectories> </sourceDirectories>


<sdk> <sdk>
<platform>17</platform> <platform>19</platform>
</sdk> </sdk>


<zipalign> <zipalign>
Expand Down
@@ -0,0 +1,22 @@
/*
* Copyright 2014 serso aka se.solovyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.solovyev.android.messenger.realms.sms;

import android.app.Activity;

public class ComposeSmsActivity extends Activity {
}
@@ -0,0 +1,28 @@
/*
* Copyright 2014 serso aka se.solovyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.solovyev.android.messenger.realms.sms;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

public class HeadlessSmsSendService extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
Expand Up @@ -103,9 +103,11 @@ protected void start0() throws AccountConnectionException {
receiver = new ReportsBroadcastReceiver(); receiver = new ReportsBroadcastReceiver();
final Application application = getApplication(); final Application application = getApplication();


final IntentFilter intentReceivedFilter = new IntentFilter(INTENT_RECEIVED); final IntentFilter intentFilter = new IntentFilter();
intentReceivedFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); intentFilter.addAction(INTENT_RECEIVED);
application.registerReceiver(receiver, intentReceivedFilter); intentFilter.addAction(INTENT_SMS_DELIVER);
intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
application.registerReceiver(receiver, intentFilter, android.Manifest.permission.BROADCAST_SMS, null);
} }


getTelephonyManager().listen(callListener.phoneStateListener, LISTEN_CALL_STATE); getTelephonyManager().listen(callListener.phoneStateListener, LISTEN_CALL_STATE);
Expand Down
Expand Up @@ -54,6 +54,8 @@ public final class SmsRealm extends AbstractRealm<SmsAccountConfiguration> {
static final String USER_ID = "self"; static final String USER_ID = "self";


public static final String INTENT_RECEIVED = "android.provider.Telephony.SMS_RECEIVED"; public static final String INTENT_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
public static final String INTENT_SMS_DELIVER = "android.provider.Telephony.SMS_DELIVER";
public static final String INTENT_MMS_DELIVER = "android.provider.Telephony.WAP_PUSH_DELIVER";
public static final String INTENT_SENT_PREFIX = "SMS_SENT"; public static final String INTENT_SENT_PREFIX = "SMS_SENT";
public static final String INTENT_DELIVERED_PREFIX = "SMS_DELIVERED"; public static final String INTENT_DELIVERED_PREFIX = "SMS_DELIVERED";
public static final String INTENT_EXTRA_SMS_ID = "sms_id"; public static final String INTENT_EXTRA_SMS_ID = "sms_id";
Expand Down
@@ -0,0 +1,42 @@
/*
* Copyright 2014 serso aka se.solovyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.solovyev.android.messenger.realms.sms;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

import static org.solovyev.android.messenger.realms.sms.SmsRealm.INTENT_MMS_DELIVER;
import static org.solovyev.android.messenger.realms.sms.SmsRealm.INTENT_SMS_DELIVER;
import static org.solovyev.common.Objects.areEqual;

public class SmsReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();

if (areEqual(action, INTENT_SMS_DELIVER)) {
ComponentName component = SmsApplication.getDefaultSmsApplication(context, false);
if (component != null) {
return component.getPackageName();
}
} else if (areEqual(action, INTENT_MMS_DELIVER)) {

}
}
}

0 comments on commit 1528fdc

Please sign in to comment.