android - 如何在其他安装了我的 android 应用程序的手机上单击按钮时发送我的 android 应用程序的通知

标签 android push-notification

我在 onClick 按钮中使用 parse.com 通知功能时出现此错误

The method setDefaultPushCallback(Context, Class) in the type PushService is not applicable for the arguments (new View.OnClickListener(){}, Class)

这是我的.class文件

public class Welcome extends ActionBarActivity {

    Button logout;
    Button emergency;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);

        ParseUser currentUser = ParseUser.getCurrentUser();

        String struser = currentUser.getUsername().toString();

        TextView txtUser = (TextView) findViewById(R.id.txtuser);
        txtUser.setText("You are logged in as " + struser);

        logout = (Button) findViewById(R.id.logout);

        logout.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                ParseUser.logOut();
                finish();
            }
        });
        emergency = (Button) findViewById(R.id.emergency);
        emergency.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                // inform the Parse Cloud that it is ready for notifications
                PushService.setDefaultPushCallback(this, Welcome.class);
                ParseInstallation.getCurrentInstallation().saveInBackground();              
            }
        });
    }
}

谁能帮我解决这个问题...

最佳答案

您将要使用 Google Cloud Messaging向其他用户的电话发送通知以及通知的详细信息。

我建议您这样做的方法是将所有用户最近的位置(例如,每当他们打开应用程序时)存储在数据库中,您可以通过在应用程序中实现 google maps api 来获取位置。然后,一旦用户单击该按钮,它将向您的数据库(使用您的用户当前位置)触发一个 php 脚本,并将其与数据库中现有的用户位置进行比较,然后您将从那里将该信息传递给 Web 服务器通过 GCM 发送该信息。

这是一个类似的脚本,它使用公式来查找用户手机 50KM 以内的用户。您可以根据您的应用程序相应地调整变量,但这几乎正是您要查找的内容。

   "SELECT p.id
     , p.PostTitle
     , p.SubmitDate
     , p.PostVotes
     , p.ImagePath
     , p.comments
     , p.latitude
     , p.longitude
     , p.DeviceID
      , ACOS( SIN(RADIANS (  $latitude ))
           * SIN(RADIANS( p.latitude ))
           + COS(RADIANS (  $latitude ))
           * COS(RADIANS( p.latitude ))
           * COS(RADIANS( p.longitude ) -        RADIANS( $longitude ))
           ) * $R
       AS D
  FROM posts p
 WHERE p.latitude  > $minLat
   AND p.latitude  < $maxLat 
   AND p.longitude > $minLon
   AND p.longitude < $maxLon 
      and featuredid = 0
      and exploreid = 0
      and Visible = 1
HAVING D < $rad
 ORDER BY PostVotes Desc"

关于android - 如何在其他安装了我的 android 应用程序的手机上单击按钮时发送我的 android 应用程序的通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31108100/

相关文章:

ios - 如何在iOS中仅清除通知

android - Xamarin AppCompat.NavigationPageRenderer 转换

php - Service Worker 中的 XMLHttpRequest

android - 如何根据两个不同 Activity 中其他微调器的位置更改微调器的位置

Android:如何使用 XML drawable 创建精确的 Material 设计阴影

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

android - 解析,推送通知。如何重置安装数据?

java - CronTrigger 未在指定时间触发,而是在错误的时间发送多个推送通知

java - 如何将 URL 中存在的 JSON 数据转换为 java 或 android 中的 JSON 字符串?

java - 渐变 : not installed (cordova requirements)