Android应用程序,用于实现sms侦听器,提取消息正文和编号,并通过http请求发送
以下是.java文件: 软件包sms1.android.pkg; 导入java.io.OutputStreamWriter; 导入java.net.HttpURLConnection; 导入java.net.URL; 导入java.net.URLConnection; 导入java.net.urlcoder; 导入android.content.BroadcastReceiver; 导入android.content.Context; 导入android.content.Intent; 导入android.os.Bundle; 导入android.telephony.sms消息Android应用程序,用于实现sms侦听器,提取消息正文和编号,并通过http请求发送,android,Android,以下是.java文件: 软件包sms1.android.pkg; 导入java.io.OutputStreamWriter; 导入java.net.HttpURLConnection; 导入java.net.URL; 导入java.net.URLConnection; 导入java.net.urlcoder; 导入android.content.BroadcastReceiver; 导入android.content.Context; 导入android.content.Intent; 导入an
public class Sms1Activity extends BroadcastReceiver {
private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
public void onReceive(Context _context, Intent _intent) {
if (_intent.getAction().equals(SMS_RECEIVED)) {
Bundle bundle = _intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++)
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
for (SmsMessage message : messages) {
String msg = message.getMessageBody();
String to = message.getOriginatingAddress();
try {
// Construct data
String data = URLEncoder.encode("test", "UTF-8") + "=" + URLEncoder.encode(msg, "UTF-8");
data = data +"&"+ URLEncoder.encode("mobile", "UTF-8") + "=" + URLEncoder.encode(to, "UTF-8");
// Send data
URL url = new URL("http://www.medibeep.in/xyz.php");
URLConnection conn = url.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection)conn;
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(httpConnection.getOutputStream());
wr.write(data);
wr.flush();
wr.close();
} catch (Exception e) {
}
}
}
}
}
}
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="sms1.android.pkg.Sms1Activity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
公共类SMS1活动扩展广播接收器{
私有静态最终字符串SMS_RECEIVED=“android.provider.Telephony.SMS_RECEIVED”;
接收时公共无效(上下文_上下文,意图_意图){
如果(_intent.getAction().equals(SMS_已接收)){
Bundle Bundle=_intent.getExtras();
if(bundle!=null){
Object[]pdus=(Object[])bundle.get(“pdus”);
SmsMessage[]messages=新SmsMessage[pdus.length];
对于(int i=0;i
以下是.manifest文件:
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="sms1.android.pkg.Sms1Activity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
没有错误,.apk文件崩溃。有人能帮我吗?在AndroidManifest as中注册android.provider.Telephony.SMS\u
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="sms1.android.pkg.Sms1Activity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<receiver android:name=".Sms1Activity">
<intent-filter>
<action android:name=
"android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
使用catlog数据编辑您的帖子,或将您收到的内容出错