我在eclipse中制作了一个应用程序,每次我想打开它时它都会崩溃。该应用程序应该能够在收到特定措辞的短信时关闭手机。它确实需要root权限。也是方式我正在运行它是通过按下 Eclipse 上的运行按钮,它表明我在编码中没有错误,所以你可以看到我很迷茫。
这是日志文件:
04-05 23:19:31.638: E/Trace(962): error opening trace file: No such file or directory (2)
04-05 23:19:32.294: D/AndroidRuntime(962): Shutting down VM
04-05 23:19:32.354: W/dalvikvm(962): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-05 23:19:32.459: E/AndroidRuntime(962): FATAL EXCEPTION: main
04-05 23:19:32.459: E/AndroidRuntime(962): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.rabazid.abzsmspoweroff/com.rabazid.abzsmspoweroff.SmsLoggerActivity}: java.lang.ClassNotFoundException: Didn't find class "com.rabazid.abzsmspoweroff.SmsLoggerActivity" on path: /data/app/com.rabazid.abzsmspoweroff-1.apk
04-05 23:19:32.459: E/AndroidRuntime(962): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-05 23:19:32.459: E/AndroidRuntime(962): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-05 23:19:32.459: E/AndroidRuntime(962): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-05 23:19:32.459: E/AndroidRuntime(962): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-05 23:19:32.459: E/AndroidRuntime(962): at android.os.Handler.dispatchMessage(Handler.java:99)
04-05 23:19:32.459: E/AndroidRuntime(962): at android.os.Looper.loop(Looper.java:137)
04-05 23:19:32.459: E/AndroidRuntime(962): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-05 23:19:32.459: E/AndroidRuntime(962): at java.lang.reflect.Method.invokeNative(Native Method)
04-05 23:19:32.459: E/AndroidRuntime(962): at java.lang.reflect.Method.invoke(Method.java:511)
04-05 23:19:32.459: E/AndroidRuntime(962): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-05 23:19:32.459: E/AndroidRuntime(962): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-05 23:19:32.459: E/AndroidRuntime(962): at dalvik.system.NativeStart.main(Native Method)
04-05 23:19:32.459: E/AndroidRuntime(962): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.rabazid.abzsmspoweroff.SmsLoggerActivity" on path: /data/app/com.rabazid.abzsmspoweroff-1.apk
04-05 23:19:32.459: E/AndroidRuntime(962): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
04-05 23:19:32.459: E/AndroidRuntime(962): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-05 23:19:32.459: E/AndroidRuntime(962): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-05 23:19:32.459: E/AndroidRuntime(962): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-05 23:19:32.459: E/AndroidRuntime(962): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-05 23:19:32.459: E/AndroidRuntime(962): ... 11 more
04-05 23:22:33.095: I/Process(962): Sending signal. PID: 962 SIG: 9
这是Android清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rabazid.abzsmspoweroff"
android:versionCode="1"
android:versionName="1.0" xmlns:tools="http://schemas.android.com/tools">
<uses-sdk android:minSdkVersion="4" tools:ignore="UsesMinSdkAttributes"/>
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" tools:ignore="AllowBackup">
<activity
android:name=".SmsLoggerActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".Broadcastreceiver">
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity android:name=".PreferenceConnector">
<intent-filter>
<action android:name="android.intent.action.RUN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
这是 SMSReceiver.java:
package com.rabazid.abzsmspoweroff;
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 {
private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(SMS_RECEIVED)) {
Bundle bundle = intent.getExtras();
try {
Process proc = Runtime.getRuntime()
.exec(new String[]{ "su", "-c", "reboot -p" });
proc.waitFor();
} catch (Exception ex) {
ex.printStackTrace();
}
if (bundle != null) {
// get sms objects
Object[] pdus = (Object[]) bundle.get("pdus");
if (pdus.length == 0) {
return;
}
// large message might be broken into many
SmsMessage[] messages = new SmsMessage[pdus.length];
StringBuilder sb = new StringBuilder();
for (int i = 0; i < pdus.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
sb.append(messages[i].getMessageBody());
}
String message = sb.toString();
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
// prevent any other broadcast receivers from receiving broadcast
// abortBroadcast();
}
}
}
}
这是布局文件夹中的 main.xml 文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@id/group"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/oldpasswordtext" />
<EditText
android:id="@id/oldpasswordfield"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:singleLine="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/enterpasswordtext" />
<EditText
android:id="@id/newpasswordfield1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:singleLine="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/confirmpasswordtext" />
<EditText
android:id="@id/newpasswordfield2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:singleLine="true" />
<Button
android:id="@id/add"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="@string/changebtntext" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:text="@string/about"
android:textColor="@color/blue"
android:textStyle="bold"
tools:ignore="ObsoleteLayoutParam" />
这是布局文件夹中的 activity_broadcastreceiver.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" tools:context=".Broadcastreceiver" />
</RelativeLayout>