gpt4 book ai didi

java - 如何使用推送机器人在我现有的 Android 应用程序中添加推送通知

转载 作者:行者123 更新时间:2023-12-01 12:49:15 25 4
gpt4 key购买 nike

我正在尝试使用 PushBots ( http://www.pushbots.com ) 在我现有的 Android 应用程序中实现推送通知,我已按照提到的所有步骤检查并重新检查了这些步骤。但是当我运行该应用程序时,它突然崩溃但从未显示任何错误。我确信 MainActvitiy.java 中的键是正确的。

我只是将 .jar 添加到 libs 文件夹中![在此处输入图像描述][1]

MainActivity.java
----------------
public class MainActivity extends Activity {

private String SENDER_ID = "1017942666064";
private String PUSHBOTS_APPLICATION_ID = "53a8a9d71d0ab1c1428b4569";


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Pushbots.init(this, SENDER_ID,PUSHBOTS_APPLICATION_ID);
setContentView(R.layout.activity_main);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

list .xml

   <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pushboss"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />

<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>

<permission android:name="com.example.pushboss.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.pushboss.permission.C2D_MESSAGE" />

<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

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

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="com.example.pushboss.MESSAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.pushbots.push.PBMsg"/>
<activity android:name="com.pushbots.push.PBListener"/>
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.pushboss" />
</intent-filter>
</receiver>
<receiver android:name="com.pushbots.push.MsgReceiver" />
<service android:name="com.pushbots.push.GCMIntentService" />
<service android:name="org.openudid.OpenUDID_service" >
<intent-filter>
<action android:name="org.openudid.GETUDID" />
</intent-filter>
</service>

</application>

</manifest>

最佳答案

你真的应该去谷歌看看,这是一个非常简单的功能。在iOS上执行此操作的主要方法是使用parse,您可以在android上执行相同的操作,这里有一个教程:

how to add push notifications in my existing android app using pushbots

这是使用 Google 云 API 的另一个示例

https://mixpanel.com/help/reference/android-push-notifications

关于java - 如何使用推送机器人在我现有的 Android 应用程序中添加推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24376075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com