2

Continuation of the previous query, see: SMS Receiver for AND API 19 and higher

I need to make the application run in the background and I could have it after installing the set as a default as shown here: http://android-developers.blogspot.cz/2013/10/getting-your-sms-apps-ready-for-kitkat.html

So I asked how to create a project to display a list of the "Super Duper SMS," which finally set as default.

The whole program must running as a service, without the need any screen for basic functions Receive SMS and should be registered in the core android

Thanks for any advice

Community
  • 1
  • 1
VladislavK
  • 39
  • 1
  • 2
  • Again, your question is a little unclear, but [this post](http://stackoverflow.com/questions/30127564/android-default-making-default-sms-app) shows the minimum you need to do for your app to be eligible to be the default SMS app. Do note that whatever functionalities you don't implement will most likely not be available to the user at all - like sending messages, handling MMS, etc. - since other SMS apps are expected to disable those functions when they're not the default. – Mike M. Jul 07 '16 at 23:17

1 Answers1

3

I am tried with this code it help me...

manifests.xml

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

<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/smsicon"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name="com.example.newsmsapp.MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">

    </activity>

    <activity android:name="com.example.newsmsapp.ComposeSMS">

        <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"/>


            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <category android:name="android.intent.category.LAUNCHER" />

            <data android:scheme="sms"/>
            <data android:scheme="smsto"/>
            <data android:scheme="mms"/>
            <data android:scheme="mmsto"/>

        </intent-filter>
    </activity>

    <receiver
        android:name="com.example.newsmsapp.SMSReceiver"
        android:permission="android.permission.BROADCAST_SMS">
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_DELIVER" />


        </intent-filter>
    </receiver>

    <activity
        android:name="com.example.newsmsapp.NotificationView"
        android:label="@string/title_activity_notification_view"
        android:theme="@style/AppTheme.NoActionBar">

    </activity>

    <receiver android:name="com.example.newsmsapp.MMSReceiver" 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>

    <service android:name="com.example.newsmsapp.HandlessSMSSendService"
        android:exported="true"
        android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE">
        <intent-filter>
            <action android:name="android.intent.action.RESPOND_VIA_MESSAGE"/>
            <data android:scheme="sms"/>
            <data android:scheme="smsto"/>
            <data android:scheme="mms"/>
            <data android:scheme="mmsto"/>
        </intent-filter>
    </service>
</application>

then create 4 file for smsReader,mmsReader,ComposeSMS,HeadlessSMSservice

smsReader.java

public class SMSReceiver extends BroadcastReceiver {
Notification notification;//=new Notification(R.drawable.icon,"New Message",System.currentTimeMillis());
NotificationManager notificationmaneger;

String SMSmsg;
public SMSReceiver() {
}
public static final String SMS_BUNDLE = "pdus";
@Override
public void onReceive(Context context, Intent intent) {
    Bundle intentExtras = intent.getExtras();
    if (intentExtras != null) {
        Object[] sms = (Object[]) intentExtras.get(SMS_BUNDLE);
        String smsMessageStr = "";

        for (int i = 0; i < sms.length; ++i) {
            SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);

            String smsBody = smsMessage.getMessageBody().toString();
            String address = smsMessage.getOriginatingAddress();

            smsMessageStr += "SMS From: " + address + "\n";
            smsMessageStr += smsBody + "\n";

            builder.setAutoCancel(true);
            //  builder.setTicker("this is ticker text");
            builder.setContentTitle("New Messge");
            builder.setContentText(SMSmsg);
            builder.setSmallIcon(R.drawable.smsicon);
            builder.setColor(context.getResources().getColor(R.color.colorAccent));
            builder.setContentIntent(pendingIntent);
            builder.setOngoing(true);
            // builder.setSubText("You have pending tax");   //API level 16
            //builder.setNumber(100);
            builder.build();
        }
SMSmsg=smsMessageStr;

    }
}

mmsReader.java

public class MMSReceiver extends BroadcastReceiver
{
    public MMSReceiver()
    {
     }
    @Override
    public void onReceive(Context context, Intent intent) {
    }
  }

ComposeSMS.java

public class ComposeSMS extends Activity {

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
 }

}

HeadlessSMSservices.java

public class HandlessSMSSendService extends Service {

@Nullable
@Override
public IBinder onBind(Intent intent) {
    return null;
    }
 }

if u want to see SMS then add listview in composeSMS.java and bind received data from sms table to listview adapter.

Kishor N R
  • 1,521
  • 1
  • 17
  • 23