2
send.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

    sendSms("9500518057","message");

}

private void sendSms(String phno, String message) {
    // TODO Auto-generated method stub
    Log.v("PhoneNumber",phno);
    Log.v("MEssage", message);
    PendingIntent pi=PendingIntent.getActivity(mContext, 0, new Intent(mContext, Object.class), 0);
    SmsManager sms=SmsManager.getDefault();
    sms.sendTextMessage(phno, null, message, pi, null);
    }
});

在这段代码中,当我单击按钮发送消息时,它没有显示任何响应。任何人都可以告诉当单击按钮时,它只会向特定号码发送确认消息。我没有要求发送消息。我要求消息警报。有什么方法吗,请帮帮我

4

3 回答 3

0
Use this code    

private static final int SIMPLE_NOTFICATION_ID = 0;
private NotificationManager mNotificationManager;

send.setOnClickListener(new OnClickListener() {

     @Override
     public void onClick(View v) {    

        mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        final Notification notifyDetails = new Notification(R.drawable.ic_launcher, "New Alert, Click Me!",
        System.currentTimeMillis());

        Context context = getApplicationContext();

        CharSequence contentTitle = "Open App";

        CharSequence contentText = "hi";
        Intent notifyIntent = new Intent(getApplicationContext(), YourActivity.class);

        PendingIntent intent = PendingIntent.getActivity(YourActivity.this,0,notifyIntent,android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
        notifyDetails.setLatestEventInfo(context,contentTitle, contentText, intent);
        mNotificationManager.notify(SIMPLE_NOTFICATION_ID,notifyDetails);

     }
});
于 2012-12-21T11:08:34.957 回答
0

更新

SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage(destinationAddress, null, "Hello world", null, null, null);

https://stackoverflow.com/a/6996255/760489

于 2012-12-21T10:57:49.923 回答
0

我认为您声明了您的应用程序 manifest.xml 文件的权限,

<uses-permission android:name="android.permission.SEND_SMS" />
于 2012-12-21T11:26:53.117 回答