Android 安卓:如何获得短信发送与否的通知?
我是否可能在手机发送短信时收到通知,并在短信发送后获得接收者的号码。我使用BroadcasrReceiver来获取传入消息的通知。但以同样的方式,我无法使用“android.provider.Telephony.SMS_SENT”来跟踪传出的SMS消息 这是我的密码: 这是为了在收到短信时收到通知:Android 安卓:如何获得短信发送与否的通知?,android,android-intent,telephonymanager,Android,Android Intent,Telephonymanager,我是否可能在手机发送短信时收到通知,并在短信发送后获得接收者的号码。我使用BroadcasrReceiver来获取传入消息的通知。但以同样的方式,我无法使用“android.provider.Telephony.SMS_SENT”来跟踪传出的SMS消息 这是我的密码: 这是为了在收到短信时收到通知: public class IncomingSms extends BroadcastReceiver { // Get the object of SmsManager final
public class IncomingSms extends BroadcastReceiver {
// Get the object of SmsManager
final SmsManager sms = SmsManager.getDefault();
public void onReceive(Context context, Intent intent) {
// Retrieves a map of extended data from the intent.
final Bundle bundle = intent.getExtras();
try {
if (bundle != null) {
final Object[] pdusObj = (Object[]) bundle.get("pdus");
for (int i = 0; i < pdusObj.length; i++) {
SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
String phoneNumber = currentMessage.getDisplayOriginatingAddress();
String senderNum = phoneNumber;
String message = currentMessage.getDisplayMessageBody();
Log.i("SmsReceiver", "senderNum: "+ senderNum + "; message: " + message);
// Show Alert
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context,
"senderNum: "+ senderNum + ", message: " + message, duration);
toast.show();
} // end for loop
} // bundle is null
} catch (Exception e) {
Log.e("SmsReceiver", "Exception smsReceiver" +e);
}
}
}
我需要在短信发送后得到通知。请帮帮我。提前感谢:)无效发送文本消息(字符串目的地址、字符串地址、字符串文本、PendingEvent Sentinent、PendingEvent deliveryIntent)
是您要使用的完整方法。
在DeliveryIntent中,即方法的第5个参数中,您可以使用它来完成您想做的事情,而不是将其保留为空。
创建一个意图,例如启动另一个活动,将该意图包装在PendingEvent中,并在方法中使用该意图。
希望有帮助 我不明白,伙计,因为我对广播接收机和所有东西都不熟悉ll u plzzz如果可能,请使用一些示例代码解释假设您希望在发送sms时从应用程序启动一项活动。因此,您可以使用intent i=new intent(此,x.class)为相同的应用程序创建一个intent;假设x是您要启动的活动。现在创建一个pendingent,它将按照如下方式包装上述意图:pendingent pi=pendingent.getActivity(Context-activityContextHere,int-requestCode,intent-overcreatedIntent,intent.FLAG_-ACTIVITY_-NEW_-TASK)。
public class MainActivity extends Activity {
EditText e1,e2;
Button b;
String sms,phoneNo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1=(EditText) findViewById(R.id.editText1);
e2=(EditText) findViewById(R.id.editText2);
b=(Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
sms=e1.getText().toString();
//sms=e1.getText().toString();
phoneNo=e2.getText().toString();
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
Toast.makeText(MainActivity.this, "DelivereD", Toast.LENGTH_LONG).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}