gpt4 book ai didi

android - 想要使用 Android 设备的解析向用户发送用户通知

转载 作者:行者123 更新时间:2023-11-29 20:25:57 24 4
gpt4 key购买 nike

我正在尝试通过单击按钮向特定用户发送用户到用户通知,但是在过去 4 天在 android 中发送通知时遇到此问题,并且每当我从我正在使用的手机上卸载该应用程序时作为模拟器,并重新安装它进行调试,它不会创建新的安装 ID 并采用旧的:我猜这是问题所在,如果有人以详细的方式帮助我,那将是很大的帮助

enter image description here

这是我的自定义接收器代码:

public class CustomPushReceiver extends ParsePushBroadcastReceiver {
private final String TAG = CustomPushReceiver.class.getSimpleName();

private NotificationUtils notificationUtils;

private Intent parseIntent;

public CustomPushReceiver() {
super();
}

@Override
protected void onPushReceive(Context context, Intent intent) {
super.onPushReceive(context, intent);

if (intent == null)
return;

try {
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));

Log.e(TAG, "Push received: " + json);

parseIntent = intent;

parsePushJson(context, json);

} catch (JSONException e) {
Log.e(TAG, "Push message json exception: " + e.getMessage());
}
}

@Override
protected void onPushDismiss(Context context, Intent intent) {
super.onPushDismiss(context, intent);
}

@Override
protected void onPushOpen(Context context, Intent intent) {
super.onPushOpen(context, intent);
}

/**
* Parses the push notification json
*
* @param context
* @param json
*/
private void parsePushJson(Context context, JSONObject json) {
try {
boolean isBackground = json.getBoolean("is_background");
JSONObject data = json.getJSONObject("data");
String title = data.getString("title");
String message = data.getString("message");

if (!isBackground) {
Intent resultIntent = new Intent(context, MainActivity.class);
showNotificationMessage(context, title, message, resultIntent);
}

} catch (JSONException e) {
Log.e(TAG, "Push message json exception: " + e.getMessage());
}
}


/**
* Shows the notification message in the notification bar
* If the app is in background, launches the app
*
* @param context
* @param title
* @param message
* @param intent
*/
private void showNotificationMessage(Context context, String title, String message, Intent intent) {

notificationUtils = new NotificationUtils(context);

intent.putExtras(parseIntent.getExtras());

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

notificationUtils.showNotificationMessage(title, message, intent);
}
}

和我的 ParseQuery:

try {
ParseQuery userQuery = new ParseQuery(ParseUser.class);
userQuery.whereNear("Location",
currentUser.getParseGeoPoint("Location"));
userQuery.setLimit(10);
userQuery.whereEqualTo("Type", "Doctor");
userQuery.whereEqualTo("deviceType", "android");
userQuery.findInBackground();
// Find devices associated with these users
ParseQuery pushQuery = ParseInstallation.getQuery();
pushQuery.whereMatchesQuery("user", userQuery);
// Send push notification to query
ParsePush push = new ParsePush();
push.setQuery(pushQuery);
push.setMessage("Only users near"
+ currentUser.getParseGeoPoint("Location")
+ " will recieve this push notification");
push.sendInBackground(new SendCallback() {

@Override
public void done(ParseException e) {
if (e == null) {
Toast.makeText(getApplicationContext(),
"Notification Sent", Toast.LENGTH_LONG)
.show();
} else {
Toast.makeText(getApplicationContext(),
"Notification not Sent",
Toast.LENGTH_LONG).show();
}
}

});

} catch (Exception e) {
e.printStackTrace();
}

我的 list 文件:

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

<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.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<permission
android:name="com.aspire.wecare.permission.C2D_MESSAGE"
android:protectionLevel="signature" />

<uses-permission android:name="com.aspire.wecare.permission.C2D_MESSAGE" />

<permission
android:name="com.aspire.wecare.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />

<uses-permission android:name="com.aspire.wecare.permission.MAPS_RECEIVE" />

<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />

<application
android:name="com.aspire.wecare.ParseApp"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.aspire.wecare.MainActivity"
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.aspire.wecare.Welcome"
android:label="@string/title_activity_welcome" >
</activity>
<activity
android:name="com.aspire.wecare.LoginActivity"
android:label="@string/title_login" >
</activity>
<activity
android:name="com.aspire.wecare.LoginSignupActivity"
android:label="@string/title_activity_login_signup" >
</activity>

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBA3_YfEl2cnZ8uDmrI23g8W7l1y2Xiku8" />
<!-- Added for Parse push notifications -->

<service android:name="com.parse.PushService" />

<receiver
android:name=".receiver.CustomPushReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<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>
<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" />
<category android:name="com.aspire.wecare" />
</intent-filter>
</receiver>

<!-- /Added for Parse push notifications -->
</application>

</manifest>

最佳答案

一般来说,

(1) 您将在云代码中执行此操作。幸运的是,一旦开始就非常容易。事实上,这是一个类似问题的完整解释。

https://stackoverflow.com/a/32540054/294884

不过更重要的是,

(2) 请注意,您使用的工具不当。 您不使用“推送”来实现您想要实现的目标。您应该使用 PubNub、Firebase、Pusher 或类似的服务。将其中一种与 Parse 结合使用是司空见惯的事情。

关于android - 想要使用 Android 设备的解析向用户发送用户通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32563044/

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