Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VFY: unable to resolve static method 10876: Android

Tags:

java

android

I used SmsCbMessage.java class in a my program. It was taken from http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.1_r1/android/telephony/SmsCbMessage.java#SmsCbMessage Following is my program.

package com.android.internal.telephony;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import android.telephony.SmsCbMessage;
import android.widget.Toast;

public class MainActivity extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        //---get the CB message passed in---
        Bundle bundle = intent.getExtras();
        SmsCbMessage[] msgs = null;
        String str = "";
        if (bundle != null)  {
            //---retrieve the SMS message received---
            Object[] pdus = (Object[]) bundle.get("pdus");
            msgs = new SmsCbMessage[pdus.length];
            for (int i=0; i<msgs.length; i++) {
                msgs[i] = SmsCbMessage.createFromPdu((byte[])pdus[i]);
                str += "CB lang " + msgs[i].getLanguageCode();
                str += " :";
                str += msgs[i].getMessageBody().toString();
                str += "\n";
            }
            //---display the new CB message---
            abortBroadcast();
            Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
        }
    }
}

This compiles without errors. But when running it gives following error

06-21 23:32:43.530    1951-1951/com.example.samitha.cbmessagespro I/dalvikvm﹕ Could not find method android.telephony.SmsCbMessage.createFromPdu, referenced from method com.android.internal.telephony.MainActivity.onReceive
06-21 23:32:43.530    1951-1951/com.example.samitha.cbmessagespro W/dalvikvm﹕ VFY: unable to resolve static method 10876: Landroid/telephony/SmsCbMessage;.createFromPdu ([B)Landroid/telephony/SmsCbMessage;
06-21 23:32:43.530    1951-1951/com.example.samitha.cbmessagespro W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41784c68)
06-21 23:32:45.580    1951-1951/com.example.samitha.cbmessagespro I/Process﹕ Sending signal. PID: 1951 SIG: 9

How to solve this?

Not that I also included all the required dependent classes too when using that SmsCbMessage.java class.

like image 849
Samitha Chathuranga Avatar asked Jun 21 '15 18:06

Samitha Chathuranga


2 Answers

if you look at the sourcecode of [email protected]

you will see that the class is marked with the "@hide" attribute

 /*
 * ....
 * @hide
 */
public class SmsCbMessage implements Parcelable {...

This means that the class is an implementation detail of android that is not part of the public android api and that can be changed or removed without notice.

[email protected] does hot have the method public static SmsCbMessage createFromPdu(byte[] pdu) while your codefragment does have it.

Your Test-Device does have this class but without the static method.

If you want to use the class anyway you can add the sourcecode to your project and rename the package

[Update 2015-06-25]

Since adding source from grepcodes to local project does not solve the problem because it has to many dependencies (especially android.internal.*)

you can create your own MySmsCbMessage that inherits from devices SmsCbMessage class and try to add missing functions from grepcodes source.

public class MySmsCbMessage extends SmsCbMessage {

    public static SmsCbMessage createFromPdu(byte[] pdu) {

         try {
             return new MySmsCbMessage(pdu);
         } catch (IllegalArgumentException e) {
             Log.w(LOG_TAG, "Failed parsing SMS-CB pdu", e);
             return null;
         }
     }
}

This is still a fragile workaround because you cannot be shure that other devices will have SmsCbMessage

like image 180
k3b Avatar answered Sep 21 '22 13:09

k3b


It is probable that Huawei has customized the SmsCbMessage class. What you can do is to use reflection to see what methods are available on that class and hope that one looks like the one you need. Try something like this:

try {
    Class clazz = Class.forName("android.telephony.SmsCbMessage");
    Method[] methods = clazz.getDeclaredMethods();
    for (Method m : methods) {
        Log.v("XXX", "Method found: " + m);
    }
} catch (Exception e) {
    Log.e("XXX", "Exception: " + e);
}
like image 27
David Wasser Avatar answered Sep 21 '22 13:09

David Wasser