USSD service not working

烈酒焚心 提交于 2019-11-28 05:58:10
Puru Pawar

Have you declared your broadcast receiver in your manifest file?

add inside your manifest:

<receiver android:name="com.xxx.receivers.BootReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

<service android:name="your.package.ExtendedNetworkService" />

in BootReceiver.java :

    public void onReceive(Context context, Intent intent) {

        context.startService(new Intent(context,ExtendedNetworkService.class));
}

in ExtendedNetworkService.java :

public class ExtendedNetworkService extends Service {

    IExtendedNetworkService.Stub binder = new IExtendedNetworkService.Stub() {

        public void setMmiString(String number) throws RemoteException {}
        public CharSequence getMmiRunningText() throws RemoteException {

            return null;
        }
        public CharSequence getUserMessage(CharSequence text)
                throws RemoteException {

            Log.d(Constants.TAG, "Message : " + text);
            Log.d(Constants.TAG, "getMmiRunningTest() : " + getMmiRunningText());
                return null;
        }
        public void clearMmiString() throws RemoteException {
        }

    };

        return false;
    }

    public void onCreate() {

        Log.d(Constants.TAG, "ExtendedNetworkService Started..");

        super.onCreate();
    }

public IBinder onBind(Intent arg0) {

        Log.d(Constants.TAG, "ExtendedNetworkService got binded...");

        return binder;

    }

}

Complete working code sample https://github.com/alaasalman/ussdinterceptor

Enjoy!

Please note that, this interface IExtendedNetworkService was removed starting from Android 4.2.2 No alternative provided by Google yet, and no plans to provide such alternative For reference you can see http://code.google.com/p/android/issues/detail?id=57120.

If your using android 3.1 (API 12), when an app installs it's in a stopped state by default until the user starts your app explicitly as stated in the commonsblog:

http://commonsware.com/blog/2011/07/13/boot-completed-regression-confirmed.html

and in the android documentation:

http://developer.android.com/about/versions/android-3.1.html#launchcontrols

I believe the bottom line is that an app containing only an IntentService or BroadcastReceiver cannot be started by it's own.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!