iOS 및 Android 앱에서 parse.com 푸시 알림을 구현하려고 시도했습니다. 필자는 iOS에서이 기능을 성공적으로 구현할 수 있었지만 아직 Android 구현에 어려움을 겪고 있습니다. 알림이 사용자에 의해 수신되고 사용자가 알림을 누르면, 'HomeScreen'활동을 열고 경고 대화 상자에 알림의 텍스트를 표시하려고합니다. Receiver 처리기 및 매니페스트 파일은 LogCat과 함께 아래에 표시됩니다. 내가 뭘 잘못하고, 어떻게 고칠 수 있니?parse.com 푸시 알림 수신과 관련된 오류입니다. Android
홈 화면 자바 :
public class Receiver extends ParsePushBroadcastReceiver {
public Receiver(){
}
private static final String TAG = "MyNotificationsReceiver";
@Override
public void onPushOpen(Context context, Intent intent) {
Log.e("Push", "Clicked");
Intent i = new Intent(context, HomeScreen.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
try {
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
String notificationText = json.getString("alert");
AlertDialog Alert= new AlertDialog.Builder(context)
.setTitle("News")
.setMessage(notificationText)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
}
})
.show();
} catch (JSONException e) {
Log.d(TAG, "JSONException: " + e.getMessage());
}
}
}
매니페스트 :
가<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<!--
IMPORTANT: Change "com.parse.tutorials.pushnotifications" to match your app's package name.
-->
<category android:name="au.gov.nsw.shellharbour.saferroadsshellharbour" />
</intent-filter>
</receiver>
<receiver android:name="au.gov.nsw.shellharbour.saferroadsshellharbour.HomeScreen$Receiver" android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
로그 캣 :
java.lang.RuntimeException: Unable to instantiate receiver au.gov.nsw.shellharbour.saferroadsshellharbour.HomeScreen$Receiver: java.lang.InstantiationException: can't instantiate class au.gov.nsw.shellharbour.saferroadsshellharbour.HomeScreen$Receiver; no empty constructor
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2265)
at android.app.ActivityThread.access$1600(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4963)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.InstantiationException: can't instantiate class au.gov.nsw.shellharbour.saferroadsshellharbour.HomeScreen$Receiver; no empty constructor
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2260)
at android.app.ActivityThread.access$1600(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4963)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
은 어디에서 구현해야 이? – scb998
수신자 클래스 내부. 여기를 참조하십시오 : https://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html –
Ive는 제안 된대로 (구현 된 질문 참조) 구현했지만 여전히 동일한 오류가 발생합니다. – scb998