我是安卓新手。我在同一个活动中定义了 BroadcastReceiver,甚至我在 AndroidManifest.xml 中输入了条目,但我遇到了异常。
public class CheckTicketReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
message = intent.getAction();
if(message != null) {
Toast.makeText(context, message, Toast.LENGTH_LONG).show();
if(message.equals("100")) {
intent = new Intent();
intent.setComponent(new ComponentName("com.sec.android.wallet", "com.sec.android.wallet.ui.activity.ticket.ExternalTicketDetailViewActivity"));
// Ticket ID (mandatory)
intent.putExtra("TICKET_ID", ticketId);
// Bounce ID (optional), set as the current system timestamp in milliseconds
intent.putExtra("BOUNCE_ID", ""+System.currentTimeMillis());
// RESULT_ACTION (mandatory)
intent.putExtra("RESULT_ACTION", "com.sample.partners.action.VIEW_TICKET_RESULT");
startActivity(intent);
}
}
}
}
AndroidManifest.xml 中的接收器
<receiver android:name=".BrandDetailActivity$CheckTicketReceiver" android:enabled="true">
<intent-filter>
<action android:name="com.sec.android.wallet.action.CHECK_TICKET" />
</intent-filter>
</receiver>
堆栈跟踪
10-23 00:54:37.148: E/AndroidRuntime(19923): FATAL EXCEPTION: main
10-23 00:54:37.148: E/AndroidRuntime(19923): java.lang.RuntimeException: Unable to instantiate receiver com.passbeemedia.BrandDetailActivity$CheckTicketReceiver: java.lang.InstantiationException: com.passbeemedia.BrandDetailActivity$CheckTicketReceiver
10-23 00:54:37.148: E/AndroidRuntime(19923): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1777)
10-23 00:54:37.148: E/AndroidRuntime(19923): at android.app.ActivityThread.access$2400(ActivityThread.java:117)
10-23 00:54:37.148: E/AndroidRuntime(19923): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
10-23 00:54:37.148: E/AndroidRuntime(19923): at android.os.Handler.dispatchMessage(Handler.java:99)
10-23 00:54:37.148: E/AndroidRuntime(19923): at android.os.Looper.loop(Looper.java:130)
10-23 00:54:37.148: E/AndroidRuntime(19923): at android.app.ActivityThread.main(ActivityThread.java:3687)
10-23 00:54:37.148: E/AndroidRuntime(19923): at java.lang.reflect.Method.invokeNative(Native Method)
10-23 00:54:37.148: E/AndroidRuntime(19923): at java.lang.reflect.Method.invoke(Method.java:507)
10-23 00:54:37.148: E/AndroidRuntime(19923): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
10-23 00:54:37.148: E/AndroidRuntime(19923): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
10-23 00:54:37.148: E/AndroidRuntime(19923): at dalvik.system.NativeStart.main(Native Method)
10-23 00:54:37.148: E/AndroidRuntime(19923): Caused by: java.lang.InstantiationException: com.passbeemedia.BrandDetailActivity$CheckTicketReceiver
10-23 00:54:37.148: E/AndroidRuntime(19923): at java.lang.Class.newInstanceImpl(Native Method)
10-23 00:54:37.148: E/AndroidRuntime(19923): at java.lang.Class.newInstance(Class.java:1409)
10-23 00:54:37.148: E/AndroidRuntime(19923): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1768)
10-23 00:54:37.148: E/AndroidRuntime(19923): ... 10 more