将解析通知代码集成到现有的Android代码中

时间:2015-04-25 14:09:00

标签: android parse-platform

我正在尝试整合解析通知代码,该代码在我现有的android项目中运行良好....但它显示错误.... 继承我的代码 MainActivity.java

public class MainActivity extends Activity implements OnClickListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ParseAnalytics.trackAppOpenedInBackground(getIntent());
    PushService.setDefaultPushCallback(this, MainActivity.class);
    ParseInstallation.getCurrentInstallation().saveInBackground();

    Button ib=(Button) findViewById(R.id.about);
    Button ib1=(Button) findViewById(R.id.sponsors);
    Button ib2=(Button) findViewById(R.id.events);
    Button ib3=(Button) findViewById(R.id.gallery);
    Button ib4=(Button) findViewById(R.id.faq);
    Button ib5=(Button) findViewById(R.id.contact);
    Typeface f=Typeface.createFromAsset(getAssets(), "RECOGNITION.ttf");
    ib.setTypeface(f);
    ib1.setTypeface(f);
    ib2.setTypeface(f);
    ib3.setTypeface(f);
    ib4.setTypeface(f);
    ib5.setTypeface(f);
    ib.setOnClickListener(this);
    ib1.setOnClickListener(this);
    ib2.setOnClickListener(this);
    ib3.setOnClickListener(this);
    ib4.setOnClickListener(this);
    ib5.setOnClickListener(this);
}

@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub
    switch(arg0.getId())
    {
    case R.id.about:
        Intent i=new Intent("com.svu.rhapsody.ABOUT");
        startActivity(i);

        break;
    case R.id.sponsors:


        break;
    case R.id.events:
        Intent j=new Intent("com.svu.rhapsody.EVENTS");
        startActivity(j);

        break;
    case R.id.gallery:
        Intent k=new Intent("com.svu.rhapsody.GALLERY");
        startActivity(k);

        break;
    case R.id.faq:
        Intent p=new Intent("com.svu.rhapsody.FAQ");
        startActivity(p);
        break;
    case R.id.contact:

        break;
    }

}

ParseApplication.java

public class ParseApplication extends Application{

@Override
public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();
    Parse.initialize(this, APP, SECRET);

    ParseUser.enableAutomaticUser();
    ParseACL defaultACL = new ParseACL();
    defaultACL.setPublicReadAccess(true);
    ParseACL.setDefaultACL(defaultACL, true);


    ParseInstallation.getCurrentInstallation().saveInBackground();
}

Receiver.java

public class Receiver extends ParsePushBroadcastReceiver{

@Override
protected void onPushOpen(Context arg0, Intent arg1) {
    // TODO Auto-generated method stub
    super.onPushOpen(arg0, arg1);
    Intent i = new Intent(arg0,MainActivity.class);
    i.putExtras(arg1.getExtras());
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    arg0.startActivity(i);
}

的AndroidManifest.xml

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="11" />
 <uses-permission android:name="android.permission.INTERNET"/>
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
 <uses-permission android:name="android.permission.VIBRATE" />
 <uses-permission android:name="android.permission.WAKE_LOCK"/>
 <uses-permission android:name="android.permission.GET_ACCOUNTS" />
 <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
 <permission android:protectionLevel="signature"
 android:name="com.example.parse.permission.C2D_MESSAGE" />
 <uses-permission android:name="com.example.parse.permission.C2D_MESSAGE" />

<application
    android:allowBackup="true"
    android:name="com.svu.rhapsody.ParseApplication"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" 
    >
    <activity
        android:name="com.svu.rhapsody.Back"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.svu.rhapsody.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.svu.rhapsody.MAINACTIVITY" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.svu.rhapsody.About"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.svu.rhapsody.ABOUT" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.svu.rhapsody.Events"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.svu.rhapsody.EVENTS" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.svu.rhapsody.Gallery"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.svu.rhapsody.GALLERY" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.svu.rhapsody.Faq"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.svu.rhapsody.FAQ" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.svu.rhapsody.Register"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.svu.rhapsody.REGISTER" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.svu.rhapsody.Sing"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.svu.rhapsody.SING" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity><activity
        android:name="com.svu.rhapsody.Treasure"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.svu.rhapsody.TREASURE" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.svu.rhapsody.Email"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.svu.rhapsody.EMAIL" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <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.svu.rhapsody.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>


</application>

</manifest>

Logcat详细信息:

04-26 02:08:51.595: I/dalvikvm(877): Could not find method    com.parse.Parse.initialize, referenced from method   com.svu.rhapsody.ParseApplication.onCreate

04-26 02:08:51.595:W / dalvikvm(877):VFY:无法解析静态方法40:Lcom / parse / Parse; .initialize(Landroid / content / Context; Ljava / lang / String; Ljava /郎/字符串;)V        04-26 02:08:51.595:D / dalvikvm(877):VFY:在0x0008处替换操作码0x71        04-26 02:08:51.633:D / AndroidRuntime(877):关闭虚拟机        04-26 02:08:51.635:W / dalvikvm(877):threadid = 1:线程退出未捕获异常(组= 0x40014760)        04-26 02:08:51.685:E / AndroidRuntime(877):致命异常:主要        04-26 02:08:51.685:E / AndroidRuntime(877):java.lang.NoClassDefFoundError:com.parse.Parse       04-26 02:08:51.685:E / AndroidRuntime(877):at com.svu.rhapsody.ParseApplication.onCreate(ParseApplication.java:16)      04-26 02:08:51.685:E / AndroidRuntime(877):在android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:968)      04-26 02:08:51.685:E / AndroidRuntime(877):在android.app.ActivityThread.handleBindApplication(ActivityThread.java:3580)      04-26 02:08:51.685:E / AndroidRuntime(877):在android.app.ActivityThread.access $ 2200(ActivityThread.java:123)     04-26 02:08:51.685:E / AndroidRuntime(877):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1031)     04-26 02:08:51.685:E / AndroidRuntime(877):在android.os.Handler.dispatchMessage(Handler.java:99)     04-26 02:08:51.685:E / AndroidRuntime(877):在android.os.Looper.loop(Looper.java:126)     04-26 02:08:51.685:E / AndroidRuntime(877):在android.app.ActivityThread.main(ActivityThread.java:3997)     04-26 02:08:51.685:E / AndroidRuntime(877):at java.lang.reflect.Method.invokeNative(Native Method)     04-26 02:08:51.685:E / AndroidRuntime(877):at java.lang.reflect.Method.invoke(Method.java:491)     04-26 02:08:51.685:E / AndroidRuntime(877):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:841)     04-26 02:08:51.685:E / AndroidRuntime(877):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)     04-26 02:08:51.685:E / AndroidRuntime(877):at dalvik.system.NativeStart.main(Native Method)     04-26 02:13:51.835:I / Process(877):发送信号。 PID:877 SIG:9

1 个答案:

答案 0 :(得分:0)

在你的日志中,你会发现你有java.lang.NoClassDefFoundError。您可以查看this回答,希望它能帮助