I wan t to Building SMSstart app in my android. 我知道市场上有很多事情要做,但我只想自己尝试。
我的SMS接收器项目以及我的助手项目正在运行。 我想将它们作为1份申请合并,但我不抱任何想法。 谁能给我一手?
这里是我从某个地方经过测试的先令。
Caller.java
package pi.redphone;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
public class Caller extends Activity
{
private Context context;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String num = "2217238";
call(num);
}
public void call(String number)
{
try
{
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+number));
startActivity(callIntent);
}
catch (ActivityNotFoundException activityException)
{
Log.e("dialing-example", "Call failed", activityException);
}
}
}
上述代码中的电话号码是硬编码的,在安装后将打电话到这个号码<><><>2217>238。
SmsReceiver.java
package pi.redphone;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class SmsReceiver extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent)
{
Bundle bundle = intent.getExtras();
//SmsMessage msg = null;
String sender = null;
String msgBody = null;
if(bundle != null)
{
Object[] sms = (Object[]) bundle.get("pdus");
for(int i=0; i<sms.length; i++)
{
SmsMessage msg = SmsMessage.createFromPdu((byte[]) sms[i]);
sender = msg.getOriginatingAddress(); //store sender s mobile #
msgBody = msg.getMessageBody(); //msg content
}
Toast.makeText(context, sender, Toast.LENGTH_LONG ).show();
}
}
}
安装后,该机将给出这一错误。
The application Callforwarding has stoped working unexpectedly. Pls try again..
实际上,我想做的是,当有人向我的和roid我的SmsReceiver寄出小ms时,他们就会抽出放的手机号码,并将打回来。 变量。
我希望这样做。
call(sender);
但 这并不容易。 我可以把源代码与没有错误结合起来,但我无法在安装后工作。
This would be my first Android application if I can get this to work.. ;)
这是我明确的档案:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pi.redphone"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_SMS">
</uses-permission>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".callForward"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
这是我的后勤中心:
01-15 03:11:50.265: I/jdwp(289): Ignoring second debugger -- accepting and dropping
01-15 03:12:30.756: W/KeyCharacterMap(289): No keyboard for id 0
01-15 03:12:30.756: W/KeyCharacterMap(289): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
01-15 03:13:05.095: D/dalvikvm(289): GC_EXPLICIT freed 1347 objects / 90832 bytes in 74ms
01-15 03:18:25.995: D/AndroidRuntime(357): Shutting down VM
01-15 03:18:26.045: W/dalvikvm(357): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-15 03:18:26.115: E/AndroidRuntime(357): FATAL EXCEPTION: main
01-15 03:18:26.115: E/AndroidRuntime(357): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{pi.redphone/pi.redphone.callForward}: java.lang.ClassCastException: pi.redphone.callForward
01-15 03:18:26.115: E/AndroidRuntime(357): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
01-15 03:18:26.115: E/AndroidRuntime(357): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-15 03:18:26.115: E/AndroidRuntime(357): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-15 03:18:26.115: E/AndroidRuntime(357): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-15 03:18:26.115: E/AndroidRuntime(357): at android.os.Handler.dispatchMessage(Handler.java:99)
01-15 03:18:26.115: E/AndroidRuntime(357): at android.os.Looper.loop(Looper.java:123)
01-15 03:18:26.115: E/AndroidRuntime(357): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-15 03:18:26.115: E/AndroidRuntime(357): at java.lang.reflect.Method.invokeNative(Native Method)
01-15 03:18:26.115: E/AndroidRuntime(357): at java.lang.reflect.Method.invoke(Method.java:521)
01-15 03:18:26.115: E/AndroidRuntime(357): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-15 03:18:26.115: E/AndroidRuntime(357): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-15 03:18:26.115: E/AndroidRuntime(357): at dalvik.system.NativeStart.main(Native Method)
01-15 03:18:26.115: E/AndroidRuntime(357): Caused by: java.lang.ClassCastException: pi.redphone.callForward
01-15 03:18:26.115: E/AndroidRuntime(357): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-15 03:18:26.115: E/AndroidRuntime(357): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
01-15 03:18:26.115: E/AndroidRuntime(357): ... 11 more
01-15 03:18:35.085: I/Process(357): Sending signal. PID: 357 SIG: 9
01-15 03:31:01.475: D/AndroidRuntime(449): Shutting down VM
01-15 03:31:01.505: W/dalvikvm(449): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-15 03:31:01.555: E/AndroidRuntime(449): FATAL EXCEPTION: main
01-15 03:31:01.555: E/AndroidRuntime(449): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{pi.redphone/pi.redphone.callForward}: java.lang.ClassCastException: pi.redphone.callForward
01-15 03:31:01.555: E/AndroidRuntime(449): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
01-15 03:31:01.555: E/AndroidRuntime(449): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-15 03:31:01.555: E/AndroidRuntime(449): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-15 03:31:01.555: E/AndroidRuntime(449): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-15 03:31:01.555: E/AndroidRuntime(449): at android.os.Handler.dispatchMessage(Handler.java:99)
01-15 03:31:01.555: E/AndroidRuntime(449): at android.os.Looper.loop(Looper.java:123)
01-15 03:31:01.555: E/AndroidRuntime(449): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-15 03:31:01.555: E/AndroidRuntime(449): at java.lang.reflect.Method.invokeNative(Native Method)
01-15 03:31:01.555: E/AndroidRuntime(449): at java.lang.reflect.Method.invoke(Method.java:521)
01-15 03:31:01.555: E/AndroidRuntime(449): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-15 03:31:01.555: E/AndroidRuntime(449): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-15 03:31:01.555: E/AndroidRuntime(449): at dalvik.system.NativeStart.main(Native Method)
01-15 03:31:01.555: E/AndroidRuntime(449): Caused by: java.lang.ClassCastException: pi.redphone.callForward
01-15 03:31:01.555: E/AndroidRuntime(449): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-15 03:31:01.555: E/AndroidRuntime(449): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
01-15 03:31:01.555: E/AndroidRuntime(449): ... 11 more
01-15 03:31:15.255: I/Process(449): Sending signal. PID: 449 SIG: 9
The application still don t run. here is my whole source code.
package pi.redphone;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class callForward extends BroadcastReceiver
{
/** Called when the activity is first created. */
public void onReceive(Context context, Intent intent)
{
Bundle bundle = intent.getExtras();
//SmsMessage msg = null;
String sender = null;
String msgBody = null;
if(bundle != null)
{
Object[] sms = (Object[]) bundle.get("pdus");
for(int i=0; i<sms.length; i++)
{
SmsMessage msg = SmsMessage.createFromPdu((byte[]) sms[i]);
sender = msg.getOriginatingAddress(); //store sender s mobile #
msgBody = msg.getMessageBody(); //msg content
}
Toast.makeText(context, sender, Toast.LENGTH_LONG ).show();
}
}
}
我感觉到该守则是正确的,但我无法说明如何解决这一问题。
我不知道如何遵循你的建议,因为我总是错过。 而是帮助我检查我是否正确。
这是我最新的法典。 电话正在运行,但我的素养家没有。
我知道我如何说我的话。
public class SmsReceiver extends BroadcastReceiver
在这项活动中,它倾听了新陈词。
<>Call4wardActative.Java
package pi.redphone;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;
public class Call4wardActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
call();
}
public void call()
{
try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
} catch (ActivityNotFoundException activityException) {
Log.e("helloandroid dialing example", "Call failed", null);
}
}
public class SmsReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
// String body = null;
String sender = null;
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++)
{
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
sender = msgs[i].getOriginatingAddress();
}
//---display the new SMS message---
Toast.makeText(context, sender, Toast.LENGTH_LONG).show();
}
}
}
}
http://www.ohchr.org。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pi.redphone"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".Call4wardActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.CALL_PHONE"/>
</manifest>