jeudi 7 juillet 2016

Service unable to send sms through build-in app

I have an application with only a service. Following is my code of the service, it is unable to call the device's build-in sms app.

public class smsservice extends Service {
private static final String TAG = "MyService";

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

@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "Service created.");
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d("TAG", "Service started.");
    try {

        String sb = (String) intent.getSerializableExtra("dest1");
        Intent sendIntent = new Intent(Intent.ACTION_VIEW);
        sendIntent.putExtra("sms_body", sb);
        sendIntent.setType("vnd.android-dir/mms-sms");
        startActivity(sendIntent);

    } catch (Exception e) {
        Toast.makeText(getApplicationContext(),
                "SMS faild, please try again later!",
                Toast.LENGTH_LONG).show();
        e.printStackTrace();
    }

    return super.onStartCommand(intent, flags, startId);
}

@Override
public void onDestroy() {
    Log.d("slog", "onDestroy()");
    super.onDestroy();
}

}

I have include the permission in the manifest file

<uses-permission android:name="android.permission.SEND_SMS" />

Is there something I am missing or is it even possible

Aucun commentaire:

Enregistrer un commentaire