Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用asp.net获取GCM注册Id?_C#_Android_Asp.net_Sql Server_Google Cloud Messaging - Fatal编程技术网

C# 如何使用asp.net获取GCM注册Id?

C# 如何使用asp.net获取GCM注册Id?,c#,android,asp.net,sql-server,google-cloud-messaging,C#,Android,Asp.net,Sql Server,Google Cloud Messaging,我有一个android应用程序,它接收注册的ID并发送GCM。当一个设备注册时,我想把它的id添加到我的MSSQL服务器上。如何使用asp.net获取设备的注册ID android请求代码: private void sendRegistrationIdToBackend() {//Sunucuya regid deðerini gönderecek method URI url = null; try { url = new URI("http://aaaa

我有一个android应用程序,它接收注册的ID并发送GCM。当一个设备注册时,我想把它的id添加到我的MSSQL服务器上。如何使用asp.net获取设备的注册ID

android请求代码:

 private void sendRegistrationIdToBackend() {//Sunucuya regid deðerini gönderecek method

    URI url = null;
    try {
        url = new URI("http://aaaaa.com/bbbbb/duyuru-haber.aspx?regId=" + regid);
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet request = new HttpGet();
    request.setURI(url);
    try {
        httpclient.execute(request);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
string registered_id = Request.QueryString["regId"];
asp.net获取代码:

 private void sendRegistrationIdToBackend() {//Sunucuya regid deðerini gönderecek method

    URI url = null;
    try {
        url = new URI("http://aaaaa.com/bbbbb/duyuru-haber.aspx?regId=" + regid);
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet request = new HttpGet();
    request.setURI(url);
    try {
        httpclient.execute(request);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
string registered_id = Request.QueryString["regId"];

请尝试以下代码:

@Override
protected void onCreate(Bundle savedInstanceState)
{
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_launch);
   context = getApplicationContext();
   if (checkPlayServices()) 
      {
          gcm = GoogleCloudMessaging.getInstance(this);
          regid = getRegistrationId(context);

          if (regid.isEmpty())
          {
             registerInBackground();
          }
          else
          {
             Log.d(TAG, "No valid Google Play Services APK found.");
          }
      }
}

private String getRegistrationId(Context context) 
{
   final SharedPreferences prefs = getGCMPreferences(context);
   String registrationId = prefs.getString(PROPERTY_REG_ID, "");
   if (registrationId.isEmpty()) {
       Log.d(TAG, "Registration ID not found.");
       return "";
   }
   int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE);
   int currentVersion = getAppVersion(context);
   if (registeredVersion != currentVersion) {
        Log.d(TAG, "App version changed.");
        return "";
    }
    return registrationId;
}
private SharedPreferences getGCMPreferences(Context context) 
{
    return getSharedPreferences(LaunchActivity.class.getSimpleName(),
                Context.MODE_PRIVATE);
}

private static int getAppVersion(Context context) 
{
     try 
     {
         PackageInfo packageInfo = context.getPackageManager()
                    .getPackageInfo(context.getPackageName(), 0);
            return packageInfo.versionCode;
      } 
      catch (NameNotFoundException e) 
      {
            throw new RuntimeException("Could not get package name: " + e);
      }
}


private void registerInBackground() 
{     new AsyncTask() {
     Override
     protected Object doInBackground(Object... params) 
     {
          String msg = "";
          try 
          {
               if (gcm == null) 
               {
                        gcm = GoogleCloudMessaging.getInstance(context);
               }
               regid = gcm.register(SENDER_ID);               
               Log.d(TAG, "########################################");
               Log.d(TAG, "Current Device's Registration ID is: "+msg);     
          } 
          catch (IOException ex) 
          {
              msg = "Error :" + ex.getMessage();
          }
          return null;
     }     protected void onPostExecute(Object result) 
     { //to do here };
  }.execute(null, null, null);
}
您可能需要确保在AndroidManifest文件中添加了所有必需的行,并声明了GCM服务和GCM广播接收器。

request.setURI(url);函数使用get方法,因此我希望在c#或asp.net上执行get registeredID。我必须在链接“+regid”请求后采取registeredID