• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Sending SMS from a widget

Hello, i am making an app for users of one Croatian mobile network. This app is used for checking money balance of network bill, then for activating sms and internet packets with sms, and many more. I made this, and it is working perfect. Now I wan't to add an widget with 3 buttons, one button will make call on predefined number, and other two buttons will send predefined sms to predefined number. I managed to do half of the job using intents, but sms is not sent, only sms builz in app opens and i need to click send and then will sms be sent :) Can you help me, to make this so that sms is sent automaticly. I tried to use smsManager, but can't get it to work...

My Code:

package cro.perger.bonbon;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.Button;
import android.widget.RemoteViews;



public class HelloWidget extends AppWidgetProvider {

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {

String encodedHash = Uri.encode("#");

for (int appWidgetId : appWidgetIds) {

Intent callIntent1 = new Intent("android.intent.action.CALL",
Uri.parse("tel:*100" + encodedHash));

Intent sendIntent1 = new Intent(Intent.ACTION_VIEW);
sendIntent1.putExtra("sms_body", "Poruka 1");
sendIntent1.putExtra("address", "5556");
sendIntent1.setType("vnd.android-dir/mms-sms");

Intent sendIntent2 = new Intent(Intent.ACTION_VIEW);
sendIntent2.putExtra("sms_body", "Poruka 2");
sendIntent2.putExtra("address", "5556");
sendIntent2.setType("vnd.android-dir/mms-sms");

PendingIntent pendingIntent1 = PendingIntent.getActivity(context, 0, callIntent1, 0);

PendingIntent pendingIntent2 = PendingIntent.getActivity(context, 0, sendIntent1, PendingIntent.FLAG_UPDATE_CURRENT);

PendingIntent pendingIntent3 = PendingIntent.getActivity(context, 0, sendIntent2, PendingIntent.FLAG_UPDATE_CURRENT);

RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setOnClickPendingIntent(R.id.button1, pendingIntent1);
views.setOnClickPendingIntent(R.id.button2, pendingIntent2);
views.setOnClickPendingIntent(R.id.button3, pendingIntent3);

appWidgetManager.updateAppWidget(appWidgetId, views);

}
}
}
 
just my 2 cents...
Did you check :
1) you use android.telephony.SmsManager and not android.telephony.gsm.SmsManager
2) Do you have declared your SEND_SMS permission (for SmsManager send message)
3) With Widget I prefer to broadcast private Intent to a BroadCastReceiver or Start private Service to do the job.

3 Intents in your case , is to invoke third party app to do the job (SMS job...) then the automatic sending may be not allowed by your SMS android core application...
>>> My guess is that SMS android core application use the SMSManager stuff, then to have complete automation (silently do the job), you need to use the SmsManager as well, with the right permission ...

Hope That help...

Have fun
 
Thanks for your reply ....

Answers:
1) Yes
2) Yes
3) I don't understand this, do you have some example, that I can put into my code...

??
 
Back
Top Bottom