I want to pass some parameters to a php script sitting on a webserver. The url is http://tom.byethost3.com/gcmapp/gcm.php?shareRegId=true. On the php script side, it is supposed to detect with GET that shareRegId is not null and then gather the other information via POST. A text file will then be generated. I have tested this with my MAMP server and it works. However, whenever I try this from my webserver, nothing happens, I still am successful in contacting the GCM server and getting a registration ID but I can't seem to trigger the url at all.
This is the script
//Get Reg ID sent from Android App and store it in text file
if(!empty($_GET["shareRegId"])) {
//$gcmRegID = $_GET["shareRegId"];
$gcmRegID = $_POST["regID"];
//echo $gcmRegID;
file_put_contents("./gcmtest/GCMRegId.txt",$gcmRegID);
echo "Done!";
exit;
}
This is how I send my request to the url
private void storeREG(){
pg.show();
params.put("regID", registerID);
Log.d("STORE","STORE");
//Make RESTful webservice call
AsyncHttpClient client = new AsyncHttpClient();
client.post(AppConstants.SERVER_URL,params,new AsyncHttpResponseHandler(){
@Override
public void onSuccess(String content) {
pg.hide();
if(pg!=null){
pg.dismiss();
}
Toast.makeText(applicationCtx,"ID sharing successful",Toast.LENGTH_LONG).show();
Intent home = new Intent(applicationCtx,HomeActivity.class);
home.putExtra("regID",registerID);
Log.d("REGID",registerID);
startActivity(home);
finish();
}
@Override
public void onFailure(int statusCode, Throwable error, String content) {
pg.hide();
if(pg!=null){
pg.dismiss();
}
Log.d("ERRORTHROW",error.toString());
if(statusCode==404){
Toast.makeText(applicationCtx,"Requested resource not found",Toast.LENGTH_LONG).show();
}else if(statusCode==500){
Toast.makeText(applicationCtx,"Something went wrong at the server",Toast.LENGTH_LONG).show();
}else{
Log.d("SHOWME",String.valueOf(statusCode));
Toast.makeText(applicationCtx,"Unexpected error occurred",Toast.LENGTH_LONG).show();
}
}
});
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.amosang.pushtest" >
<!-- GCM Permissions - Start here -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission android:name="com.example.amosang.pushtest.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.amosang.pushtest.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".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=".HomeActivity"
android:label="@string/title_activity_home" >
</activity>
<receiver
android:name=".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" />
<action android:name="com.example.amosang.pushtest" />
</intent-filter>
</receiver>
<service android:name=".GCMNotificationIntentService" />
</application>
</manifest>