0

I am trying from more than a day to implement a simple PUSH notification using gcm, but unable to implement it.

When ever I am adding this permission

<permission android:name="Android.Test.permission.C2D_MESSAGE"  android:protectionLevel="signature" />

I get this error message while debugging via mobile device

pkg: /data/local/tmp/Android.Test
Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]

Can somebody suggest me what I am doing. for further help I am putting my whole manifest.xml file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="Android.Test"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="14"/>

    <permission android:name="Android.Test.permission.C2D_MESSAGE"  android:protectionLevel="normal" />
    <uses-permission android:name="Android.Test.permission.C2D_MESSAGE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />



    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
        <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>
        <receiver
                android:name="com.google.android.gcm.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="Android.Test" />
            </intent-filter>
        </receiver>
        <service android:name=".GCMIntentService" />
    </application>
</manifest>

Edit 1: This is how I am trying to send the message from C# to my android device.....I found this code from the blog.

private string SendGCMNotification(string apiKey, string postData, string postDataContentType = "application/json")
        {

            ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateServerCertificate);

            //
            //  MESSAGE CONTENT
            byte[] byteArray = Encoding.UTF8.GetBytes(postData);

            //
            //  CREATE REQUEST
            HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("https://android.googleapis.com/gcm/send");
            Request.Method = "POST";
            Request.KeepAlive = false;
            Request.ContentType = postDataContentType;
            Request.Headers.Add(string.Format("Authorization: key={0}", apiKey));
            Request.ContentLength = byteArray.Length;

            Stream dataStream = Request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            //
            //  SEND MESSAGE
            try
            {
                WebResponse Response = Request.GetResponse();
                HttpStatusCode ResponseCode = ((HttpWebResponse)Response).StatusCode;
                if (ResponseCode.Equals(HttpStatusCode.Unauthorized) || ResponseCode.Equals(HttpStatusCode.Forbidden))
                {
                    var text = "Unauthorized - need new token";

                }
                else if (!ResponseCode.Equals(HttpStatusCode.OK))
                {
                    var text = "Response from web service isn't OK";
                }

                StreamReader Reader = new StreamReader(Response.GetResponseStream());
                string responseLine = Reader.ReadToEnd();
                Reader.Close();

                return responseLine;
            }
            catch (Exception e)
            {

            }
            return "error";
        }

This is what I am getting in the responseLine code

{"multicast_id":7357801824672,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}

Thanks

5
  • basic4ppc.com/forum/basic4android-getting-started-tutorials/… Commented Sep 14, 2012 at 3:29
  • 2
    Should be your package name fault. Don't use capital in your package name. Try to rename it to com.android.test and see if you can install or not Commented Sep 14, 2012 at 3:38
  • Aprian, I followed your suggestion and it worked now I am able to compile and run the app on the phone, but I am unable to receive a message on the phone. I am pushing my messages from c# .net but they are not reaching to phone any suggestions...please... Commented Sep 14, 2012 at 4:13
  • If the problem, as initially posed, is solved, accept the answer and post a new question. This one is overloaded with pasted code as it is. Commented Sep 14, 2012 at 13:20
  • stackoverflow.com/questions/12579202/… Commented Nov 7, 2012 at 3:27

2 Answers 2

1
try this one       

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


<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.google.android.gcm.demo.app.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission
    android:name="com.google.android.gcm.demo.app.permission.C2D_MESSAGE" />

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

<!-- Main activity. -->
<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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


    <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="Android.Test" />
        </intent-filter>
    </receiver>


    <service android:name=".GCMIntentService" />
</application>

Sign up to request clarification or add additional context in comments.

5 Comments

now i am able to compile but while execution I got this error "java.lang.IllegalStateException: Application does not define permission Android.Test.permission.C2D_MESSAGE"
<permission android:name="Android.Test.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="Android.Test.permission.C2D_MESSAGE" />
no luck, "same error pkg: /data/local/tmp/Android.Test Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]"
i thinks the problem is not in manifest file because i done same one last 2days back its working fine to me.check once the tutorial of GCM
raju, i am able to compile and execute the app by following Aprian's suggestion, but now I am unable to receive the message, See Edit 1 for info.
0

Your response code contains the answer, you are passing invalid registration_ids

    "results":[{"error":"InvalidRegistration"}]

Sample php code:

    $postdata = array(
        'registration_ids' => array('your_device_registration_key'),
        'data' => 'message'
    );

    $headers = array(
        'Authorization: key=' . YOUR_API_KEY,
        'Content-Type: application/json'
    );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.