import android error

302 views
Skip to first unread message

joseph...@gmail.com

unread,
Jul 11, 2015, 11:29:51 AM7/11/15
to codenameone...@googlegroups.com
hi

i tried the native interface.  Created a readSMS.java under userclass directory.

=============
package userclasses;
import com.codename1.system.NativeInterface;

/**
 *
 * @author Joseph
 */
public interface readSMS extends NativeInterface
{
    public boolean isSupported();
}

======================

I then right click on Generate Native Access which creates the class readSMSImpl.java under native/android/userclasses directory.  I then add import android.content.BroadcastReceiver; but i get red (netbeans) which means the import of android doesn't work. 

======
package userclasses;

import android.content.BroadCastReceiver;
        
public class readSMSImpl {
    public boolean isSupported() {
        return false;
    }
}
=========


Chen Fishbein

unread,
Jul 11, 2015, 2:56:57 PM7/11/15
to codenameone...@googlegroups.com, joseph...@gmail.com, joseph...@gmail.com
Hi,
Native interfaces are compiled on the build server, you can simply ignore all errors marked by the IDE.

joseph...@gmail.com

unread,
Jul 12, 2015, 3:47:33 AM7/12/15
to codenameone...@googlegroups.com, joseph...@gmail.com
Hi

when i tried to call the nativeinterface in the file MyApplication.java

readSMS rs =(readSMS) NativeLookup.create(readSMS.class);
        if(rs!=null && rs.isSupported()){
            System.out.println("HERE");
        }


i get error after i do a build but the simulator still popsup

java.lang.ClassNotFoundException: userclasses.readSMSImpl
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.ClassLoader.findSystemClass(ClassLoader.java:1059)
at com.codename1.impl.javase.ClassPathLoader.findClass(ClassPathLoader.java:100)
at com.codename1.impl.javase.ClassPathLoader.loadClass(ClassPathLoader.java:50)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at com.codename1.system.NativeLookup.create(NativeLookup.java:55)
at com.mycompany.myapp.MyApplication.start(MyApplication.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.codename1.impl.javase.Executor$1.run(Executor.java:95)
at com.codename1.ui.Display.processSerialCalls(Display.java:1140)
at com.codename1.ui.Display.mainEDTLoop(Display.java:962)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)


Also another question do i need to create another class to extend the broadcastreceiver?  If i do, do i create the class in the native/android/userclasses directory?  I was thinking of not needing to create it but to override the broadcastreceiver functions in the 
native/android/userclasses readSMSImpl.java  as below

===========
readSMSImpl.java

package userclasses;
import android.app.Activity.*;
import com.codename1.impl.android.*;
import android.telephony.*;
import android.content.Intent.*;
import android.content.Context.*;
import android.content.BroadcastReceiver.*;
import android.widget.*;
import com.codename1.system.NativeLookup.*;

public class readSMSImpl implements readSMS{
    public String getSMS() {
        BroadcastReceiver bcr=new BroadcastReceiver(){
            @Override
            public void onReceive(Context context, Intent intent) {
                
            }
        
        };
      
        
        
        return "";
    }

    public boolean isSupported() {
        return true;
    }

}
================

thanks

Joseph

joseph...@gmail.com

unread,
Jul 12, 2015, 6:30:10 AM7/12/15
to codenameone...@googlegroups.com, joseph...@gmail.com
Hi

I have resolved the error after i did a clean and build.  

i just want to know do i need to create another class to extend the broadcastreceiver?  If i do, do i create the class in the native/android/userclasses directory?  I was thinking of not needing to create it but to override the broadcastreceiver functions in the 

Shai Almog

unread,
Jul 12, 2015, 9:09:13 AM7/12/15
to codenameone...@googlegroups.com, joseph...@gmail.com, joseph...@gmail.com
Hi,
you should have the broadcast receiver in a separate class since the implementation class is initialized by us.

joseph...@gmail.com

unread,
Jul 13, 2015, 8:40:46 AM7/13/15
to codenameone...@googlegroups.com, joseph...@gmail.com
hi
 
i created the class smsReceiverBroadcast extends BroadcastReceiver{} under native/android/userclasses directory.  In the smsReceiverBroadcast i call a static function StateMachine.getSMSIncomingMessages(String message).  the manifest i have attached.  I just wonder after i did a build and install the app i don't know how to test to know that the broacastreceiver is working.  The manifest i added below.  Please tell me if i did it right.

android.xpermission <uses-permission android:name="android.permission.READ_SMS" />
android.xpermissions <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>

==========
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import userclasses.StateMachine;
import userclasses.javascript;
/**
 *
 * @author Joseph
 */

public class smsReceiverBroadcast extends BroadcastReceiver {
    public static final String SMS_BUNDLE = "pdus";
    
    @Override
    public void onReceive(Context context, Intent intent) {
 
   //---get the SMS message passed in---
    StateMachine.getSMSIncomingMessages("onReceive start");

    Bundle bundle = intent.getExtras(); 
        if(null!=bundle)
        {
            Object[] sms = (Object[]) bundle.get(SMS_BUNDLE);
            String smsMgs="";
            String smsBody ="";
            String address = "";
            for (int i = 0; i < sms.length; ++i) {
                SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);
                smsBody = smsMessage.getMessageBody().toString();
                address = smsMessage.getOriginatingAddress();
                smsMgs += "SMS From: " + address + "\n";
                smsMgs += smsBody + "\n";
            }

            StateMachine.getSMSIncomingMessages(smsMgs);
                   
        }
    }
}
=========

Chen Fishbein

unread,
Jul 13, 2015, 9:42:30 AM7/13/15
to codenameone...@googlegroups.com, joseph...@gmail.com, joseph...@gmail.com
Hi,
You need to register your BroadcastReceiver:

        Activity activity = com.codename1.impl.android.AndroidNativeUtil.getActivity();
        activity.registerReceiver(...);

Joseph Luong

unread,
Jul 15, 2015, 8:58:56 AM7/15/15
to Chen Fishbein, codenameone...@googlegroups.com
hi chen

i did as you said but i think i still have incorrect directory issue

======
package userclasses;
import android.app.Activity.*;
import com.codename1.impl.android.*;
import android.telephony.*;
import android.content.Intent.*;
import android.content.Context.*;
import android.content.BroadcastReceiver.*;
import android.widget.*;
import com.codename1.system.NativeLookup.*;

public class readSMSImpl implements readSMS{
    public String getSMS() {
    

 /*IntentFilter filter = new IntentFilter();
    filter.addAction("SOME_ACTION");
    filter.addAction("SOME_OTHER_ACTION");
    */

    smsReceiverBroadcast srBroadcast = new smsReceiverBroadcast();
    Activity activity = com.codename1.impl.android.AndroidNativeUtil.getActivity();
    activity.register(srBroadcast,new IntentFilter("READ_SMS"));
        
        return "getSMSAndroid";
    }

    public boolean isSupported() {
        return true;
    }

}


=======

and i got the errors below

===
 [javac] Compiling 500 source files to /tmp/build3149152162160886177xxx/MyApplication/bin/classes
    [javac] /tmp/build3149152162160886177xxx/MyApplication/src/userclasses/readSMSImpl.java:14: error: cannot find symbol
    [javac]     IntentFilter filter = new IntentFilter();
    [javac]     ^
    [javac]   symbol:   class IntentFilter
    [javac]   location: class readSMSImpl
    [javac] /tmp/build3149152162160886177xxx/MyApplication/src/userclasses/readSMSImpl.java:14: error: cannot find symbol
    [javac]     IntentFilter filter = new IntentFilter();
    [javac]                               ^
    [javac]   symbol:   class IntentFilter
    [javac]   location: class readSMSImpl
    [javac] /tmp/build3149152162160886177xxx/MyApplication/src/userclasses/smsReceiverBroadcast.java:19: error: duplicate class: smsReceiverBroadcast
    [javac] public class smsReceiverBroadcast extends BroadcastReceiver {
    [javac]        ^
    [javac] /tmp/build3149152162160886177xxx/MyApplication/src/userclasses/readSMSImpl.java:18: error: cannot access smsReceiverBroadcast
    [javac]     smsReceiverBroadcast srBroadcast = new smsReceiverBroadcast();
    [javac]     ^
    [javac]   bad source file: /tmp/build3149152162160886177xxx/MyApplication/src/userclasses/smsReceiverBroadcast.java
    [javac]     file does not contain class userclasses.smsReceiverBroadcast
    [javac]     Please remove or make sure it appears in the correct subdirectory of the sourcepath.
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.

===

Chen Fishbein

unread,
Jul 15, 2015, 9:09:02 AM7/15/15
to codenameone...@googlegroups.com, joseph...@gmail.com, joseph...@gmail.com
Hi,
Fix your imports (import android.content.*; ) and fix this class smsReceiverBroadcast.
I guess you have this declared as inner class and in a separate java file
 
 

Joseph Luong

unread,
Jul 15, 2015, 9:25:31 AM7/15/15
to Chen Fishbein, codenameone...@googlegroups.com
hi chen

Sorry i don't understand your reply to the above email 
- Fix your imports (import android.content.*; )

and also i created the class smsReceiverBroadcast.java under native/android/userclasses is that incorrect? 




===
[javac] Compiling 500 source files to /tmp/build2363898838683068927xxx/MyApplication/bin/classes
    [javac] /tmp/build2363898838683068927xxx/MyApplication/src/userclasses/smsReceiverBroadcast.java:19: error: duplicate class: smsReceiverBroadcast
    [javac] public class smsReceiverBroadcast extends BroadcastReceiver {
    [javac]        ^
    [javac] /tmp/build2363898838683068927xxx/MyApplication/src/userclasses/readSMSImpl.java:19: error: cannot access smsReceiverBroadcast
    [javac]     smsReceiverBroadcast srBroadcast = new smsReceiverBroadcast();
    [javac]     ^
    [javac]   bad source file: /tmp/build2363898838683068927xxx/MyApplication/src/userclasses/smsReceiverBroadcast.java
    [javac]     file does not contain class userclasses.smsReceiverBroadcast
    [javac]     Please remove or make sure it appears in the correct subdirectory of the sourcepath.
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 2 errors
====

Joseph Luong

unread,
Jul 15, 2015, 9:37:49 AM7/15/15
to Chen Fishbein, codenameone...@googlegroups.com
hi chen

I understand what you mean import android.content.*; now.

Joseph

Joseph Luong

unread,
Jul 15, 2015, 9:41:33 AM7/15/15
to Chen Fishbein, codenameone...@googlegroups.com
hi chen

sorry for the multiple emails but i'm getting close.  I moved the file smsReceiverBroadcast.java to native/android dir and i only have the below errors.

 [javac] Compiling 500 source files to /tmp/build7889495433586324184xxx/MyApplication/bin/classes
    [javac] /tmp/build7889495433586324184xxx/MyApplication/src/userclasses/readSMSImpl.java:19: error: cannot find symbol
    [javac]     smsReceiverBroadcast srBroadcast = new smsReceiverBroadcast();
    [javac]     ^
    [javac]   symbol:   class smsReceiverBroadcast
    [javac]   location: class readSMSImpl
    [javac] /tmp/build7889495433586324184xxx/MyApplication/src/userclasses/readSMSImpl.java:19: error: cannot find symbol
    [javac]     smsReceiverBroadcast srBroadcast = new smsReceiverBroadcast();
    [javac]                                            ^
    [javac]   symbol:   class smsReceiverBroadcast
    [javac]   location: class readSMSImpl
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 2 errors

Shai Almog

unread,
Jul 15, 2015, 10:34:39 AM7/15/15
to codenameone...@googlegroups.com, joseph...@gmail.com, cf2...@gmail.com, joseph...@gmail.com
Did you name the file with that name? Is it in the same package? Is it public?

Chen Fishbein

unread,
Jul 15, 2015, 10:35:19 AM7/15/15
to codenameone...@googlegroups.com, joseph...@gmail.com, joseph...@gmail.com
Hi,
Put it in the same dir as your readSMSImpl and fix the package in the smsReceiverBroadcast file.
 
 

Joseph Luong

unread,
Jul 19, 2015, 9:25:15 AM7/19/15
to Chen Fishbein, codenameone...@googlegroups.com
hi Chen

I don't have anymore syntax error when i do build but i still can't get it to work.  I want to test so that when i receiver the SMS i know that the onReciever function works.  Not sure if i registered it correctly.
for the manifest i did below and my code are below.  Am i missing something ? 

android.xpermission=<uses-permission android:name="android.permission.READ_SMS" />

======
public class readSMSImpl implements readSMS{
    public String getSMS() {
    
    /*IntentFilter filter = new IntentFilter();smsReceiverBroadcast
    filter.addAction("SOME_ACTION");
    filter.addAction("SOME_OTHER_ACTION");
    */
    smsReceiverBroadcast srBroadcast = new smsReceiverBroadcast();
    Activity activity = com.codename1.impl.android.AndroidNativeUtil.getActivity();
    //activity.register(srBroadcast)
    //activity.register(srBroadcast,new IntentFilter("READ_SMS"));
        
        return "getSMSAndroid";
    }

    public boolean isSupported() {
        return true;
    }

}


===
public class smsReceiverBroadcast extends BroadcastReceiver {
    public static final String SMS_BUNDLE = "pdus";
    
    @Override
    public void onReceive(Context context, Intent intent) {
    //---get the SMS message passed in---
    StateMachine.getSMSIncomingMessages("onReceive start");
    Bundle bundle = intent.getExtras(); 
        if(null!=bundle)
        {
            Object[] sms = (Object[]) bundle.get(SMS_BUNDLE);
            String smsMgs="";
            String smsBody ="";
            String address = "";
            for (int i = 0; i < sms.length; ++i) {
                SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);
                smsBody = smsMessage.getMessageBody().toString();
                address = smsMessage.getOriginatingAddress();
                smsMgs += "SMS From: " + address + "\n";
                smsMgs += smsBody + "\n";
            }
           //StateMachine.getSMSIncomingMessages(smsMgs);
             //---display the new SMS message---
            Toast.makeText(context, smsMgs, Toast.LENGTH_SHORT).show();
        }
    }
}
=======

Chen Fishbein

unread,
Jul 19, 2015, 3:43:02 PM7/19/15
to codenameone...@googlegroups.com, joseph...@gmail.com, joseph...@gmail.com
Hi,
It seems like your register code is commented out

 
 

Joseph Luong

unread,
Jul 19, 2015, 6:08:35 PM7/19/15
to Chen Fishbein, codenameone...@googlegroups.com

Hi chen

I thought by adding the xml in the manifest i don't need to register.

Joseph

Chen Fishbein

unread,
Jul 21, 2015, 4:41:51 AM7/21/15
to codenameone...@googlegroups.com, joseph...@gmail.com, joseph...@gmail.com
Hi,
Remove it from the manifest and register it with code, it is easier to debug this that way.

Joseph Luong

unread,
Jul 22, 2015, 9:26:32 AM7/22/15
to Chen Fishbein, codenameone...@googlegroups.com
hi chen

for some reason i can't get it to go into the onReceive function when i receive an SMS message (readSMSMessageImp), do i need to add something in the manifest?

Also in the MyApplication.java i call the readSMSMessage native as below. that is the correct way to call getSMS()  function to start the Broadcastreceiver right?


 readSMSMessage rs =(readSMSMessage) NativeLookup.create(readSMSMessage.class);
        if(rs!=null && rs.isSupported()){
            rs.getSMS();
        }


===================
package userclasses;
import android.app.Activity;
import com.codename1.impl.android.*;
import android.telephony.*;
import android.content.*;
import android.widget.*;
import android.provider.*;
import com.codename1.system.NativeLookup;


public class readSMSMessageImpl {

    public String getSMS() {
       javascript.popupMessage("getSMS start"); 

        smsReceiverBroadcast srBroadcast = new smsReceiverBroadcast();
        Activity context = com.codename1.impl.android.AndroidNativeUtil.getActivity();
        IntentFilter filter = new IntentFilter();
        filter.addAction(Telephony.Sms.Intents.DATA_SMS_RECEIVED_ACTION);
        context.registerReceiver(srBroadcast,filter);
 
        javascript.popupMessage("getSMS end"); 
 
       return "";
    }

    public boolean isSupported() {
        return true;
    }

}

================================

Chen Fishbein

unread,
Jul 23, 2015, 1:35:19 AM7/23/15
to Joseph Luong, codenameone...@googlegroups.com
Hi,
Did you added the permissions needed?

joseph...@gmail.com

unread,
Jul 26, 2015, 3:08:02 AM7/26/15
to CodenameOne Discussions, cf2...@gmail.com
hi Chen

The broadcastreceiver i got it to work when i register it dynamically.  But now i want to register it statically so that even if my application is close when i receive sms it still go into the onreceive function and execute the code i want.  I read on the forum and you mentioned to some1 that you don't need to create a NativeInterface.  

1)If you use BroadcastReceiver you don't need the NativeInterface, you can do all the android stuff in the onReceive and preform a callback to your java code using a static method.
Something like this

I didn't get any errors when i compile or build however when i install my application and for testing i send an sms to myself i get 
Unfortunately, SOS has stopped. (SOS is my application name).  Below is my manifest and code, i assume


=======

<receiver android:name="smsReceiverBroadcast" ><intent-filter><action android:name="android.provider.Telephony.SMS_RECEIVED"/></intent-filter></receiver>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>

public class smsReceiverBroadcast extends BroadcastReceiver {
    public static final String SMS_BUNDLE = "pdus";
    
    public smsReceiverBroadcast(){}
    
    @Override
    public void onReceive(Context context, Intent intent) {
      Dialog.show("Message", "TESTING", "Ok", null);      
      StateMachine.getSMSIncomingMessages("onRECEIVE");
    }
}

Chen Fishbein

unread,
Jul 26, 2015, 5:05:32 AM7/26/15
to CodenameOne Discussions, joseph...@gmail.com, joseph...@gmail.com
Hi,
You are most likely failing here:
Dialog.show(....)

Notice your broadcastreceiver is running, but your main app isn't running so you are probably failing on NullPointers and I assume the EDT is not running either.

What you should do is send a local notification and the user should then open the app.


Joseph Luong

unread,
Jul 26, 2015, 5:32:11 AM7/26/15
to Chen Fishbein, CodenameOne Discussions
hi Chen

Maybe i can launch the app from the broadcastreceiver in the onReceive method.

Joseph

Joseph Luong

unread,
Jul 26, 2015, 5:34:26 AM7/26/15
to Chen Fishbein, CodenameOne Discussions
hi Chen

Also i notice even if in the onreceive method of smsReceiverBroadcast() i don't call the main application it still fail

Chen Fishbein

unread,
Jul 26, 2015, 6:31:02 AM7/26/15
to CodenameOne Discussions, joseph...@gmail.com, joseph...@gmail.com
Hi,
1)Sure you can use intent and launch your app
2)I suggest you to use DDMS and see what is the failure.

Joseph Luong

unread,
Jul 26, 2015, 6:07:53 PM7/26/15
to Chen Fishbein, CodenameOne Discussions
Hi Chen

Thanks for the advice. But this app it crashes when i send an sms,
how can i test it with DDMS?

Joseph

Shai Almog

unread,
Jul 26, 2015, 11:51:48 PM7/26/15
to CodenameOne Discussions, joseph...@gmail.com, cf2...@gmail.com, joseph...@gmail.com
Hi,
connect it with a cable to the desktop and run Androids ddms utility which will allow you to see console output and exception stacks.

Joseph Luong

unread,
Jul 27, 2015, 7:57:16 AM7/27/15
to Shai Almog, CodenameOne Discussions, Chen Fishbein
hi Shai

Thanks for the instructions on connecting desktop to android ddms utility.  I got it to work and in the logcat.txt i got the below.  I wonder if the error below is the reason my application is not working and keeps getting the message 
Unfortunately, SOS has stopped.

-------- beginning of /dev/log/system

W/ContextImpl( 9048): Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1212 android.content.ContextWrapper.sendBroadcast:365 com.lge.mlt.MltMonitorService$3.run:707 java.lang.Thread.run:841 <bottom of call stack> 

I/Vold    (  266): [LGE][VOLD][NetlinkHandler.cpp][onEvent()] subsys:cpu, action:0

I/Vold    (  266): [LGE][VOLD][NetlinkHandler.cpp][onEvent()] subsys:cpu, action:0

--------- beginning of /dev/log/main

Joseph

Shai Almog

unread,
Jul 27, 2015, 10:34:36 AM7/27/15
to CodenameOne Discussions, joseph...@gmail.com, cf2...@gmail.com, joseph...@gmail.com

Joseph Luong

unread,
Jul 28, 2015, 6:48:12 AM7/28/15
to Shai Almog, CodenameOne Discussions, Chen Fishbein
hi Shai 

I found the actual error it is below.  Somehow it can't find the class smsReceiverBroadcast.  At first my smsReceiverBroadcast.java is in location native/userClasses/smsReceiverBroadcast.java from the error i now created folders in the native to native/com/mycompany/myapp/smsReceiverBroadcast.java.  

I still get the error.  Also do i still need the native class (public interface readSMSMessage extends NativeInterface) since i don't think i need it.

E/AndroidRuntime( 6272): java.lang.RuntimeException: Unable to instantiate receiver com.mycompany.myapp.smsReceiverBroadcast: java.lang.ClassNotFoundException: Didn't find class "com.mycompany.myapp.smsReceiverBroadcast" on path: DexPathList[[zip file "/data/app/com.mycompany.myapp-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.mycompany.myapp-1, /vendor/lib, /system/lib]]

Joseph

Shai Almog

unread,
Jul 28, 2015, 11:12:30 AM7/28/15
to CodenameOne Discussions, joseph...@gmail.com, cf2...@gmail.com, joseph...@gmail.com
Hi,
how are you loading the sms receiver?
Did you use the class name in some way?
Our build process follows Google's recommendations and obfuscates your class names so if you rely on a class name either via manifest or some other means it might be removed.

Native interfaces are necessary to call from Codename One code to the native code in a portable way, if you don't need such an ability then you don't need them.

joseph...@gmail.com

unread,
Jul 30, 2015, 7:19:04 AM7/30/15
to CodenameOne Discussions, cf2...@gmail.com, shai....@gmail.com

Hi Shai

I declare the broadcastreceiver extension class in the manifest file
(i have attached for you to see).  Basically my goal is whenever i
receive an sms and that meets certain conditions i launch my
application.
Hence that's why i don't think i need Native interfaces at all.  I'm
just not sure if how i structure my broadcastreceiver extension class
location correctly.

Thanks

Shai Almog

unread,
Jul 30, 2015, 10:26:36 AM7/30/15
to CodenameOne Discussions, joseph...@gmail.com, cf2...@gmail.com, joseph...@gmail.com
I don't write broadcast receivers normally so I can't help much there.

fabrici...@gmail.com

unread,
Jul 30, 2015, 10:29:58 AM7/30/15
to CodenameOne Discussions, cf2...@gmail.com, shai....@gmail.com, joseph...@gmail.com
Hi Joseph, I am pretty sure you need Native interfaces to accomplish this. Intercepting these received messages can be trick. Be sure to have these set in your manifest, it works in my project:

    <receiver android:name="your.package.yourSmsReceiver" android:permission="android.permission.BROADCAST_SMS" android:exported="true">
      <intent-filter android:priority="5000">

         <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
      </intent-filter>
   </receiver>
   <uses-feature
        android:name="android.hardware.telephony"
        android:required="false" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.SEND_SMS"/>
    <uses-permission android:name="android.permission.WRITE_SMS"/>
    <uses-permission android:name="android.permission.RECEIVE_SMS"/>

    <uses-permission android:name="android.permission.READ_SMS"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

Joseph Luong

unread,
Jul 30, 2015, 5:55:30 PM7/30/15
to fabrici...@gmail.com, CodenameOne Discussions, cf2...@gmail.com, shai....@gmail.com
Hi fabricio

Thanks a lot for your help. I think i've read your problem with
native interface in the forum and use yours as basis for mine.

Just a few questions, i put my smsBroadcastreceiver.java under the
native/android/userclasses/smsBroadcastreceiver.java is that correct?
And you state regard manifest (<receiver
android:name="your.package.yourSmsReceiver"
), my receiver class name is smsBroadcastreceiver my package is
userclasses so do i put
android:name="userclases.smsBroadcastreceiver" ?

Lastly i want to understand why do i need native interface, because my
purpose is everytime i receive an sms onreceive will get call. I
don't understand why i need the native interface. Do i need it to
create an instance of the smsBroadcastreceiver although i use static
broadcastreceiver? Or do i need to interact with the native interface
from the onreceive method?

Joseph



On 7/30/15, fabrici...@gmail.com <fabrici...@gmail.com> wrote:
> Hi Joseph, I am pretty sure you need Native interfaces to accomplish this.
> Intercepting these received messages can be trick. Be sure to have these
> set in your manifest, it works in my project:
>
> <receiver android:name="your.package.yourSmsReceiver"
> android:permission="android.permission.BROADCAST_SMS"
> android:exported="true">
> <intent-filter android:priority="5000">
> <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
> </intent-filter>
> </receiver>
> <uses-feature
> android:name="android.hardware.telephony"
> android:required="false" />
> <uses-permission android:name="android.permission.INTERNET"/>
> <uses-permission android:name="android.permission.SEND_SMS"/>
> <uses-permission android:name="android.permission.WRITE_SMS"/>
> <uses-permission android:name="android.permission.RECEIVE_SMS"/>
> <uses-permission android:name="android.permission.READ_SMS"/>
> <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
>
>
>
> On Thursday, July 30, 2015 at 8:19:04 AM UTC-3, joseph...@gmail.com wrote:
>>
>>
>> <https://lh3.googleusercontent.com/-Y_Hy5EP9J18/VboIH1jaA4I/AAAAAAAAAL0/vQ0iOM9rEDY/s1600/manifest.jpg>

Shai Almog

unread,
Jul 31, 2015, 12:12:43 AM7/31/15
to CodenameOne Discussions, fabrici...@gmail.com, cf2...@gmail.com, shai....@gmail.com, joseph...@gmail.com
Hi,
the main issue with this is calling back into Java from the "native code". This is seamless in Android but in iOS etc. its a bit tricky: http://www.codenameone.com/blog/native-ios-code-callbacks.html
If this functionality is only intended for Android then I don' think you need a native interface.

fabrici...@gmail.com

unread,
Jul 31, 2015, 11:27:54 AM7/31/15
to CodenameOne Discussions, fabrici...@gmail.com, cf2...@gmail.com, shai....@gmail.com, joseph...@gmail.com
Your broadcast receiver seems ok but your main package is "userclasses", I believe it is auto-generated by the state machine flow, you probably have another main package where your broadcast receiver would fit better. Take a look at your project properties.

The native interface would be needed if you plan to do anything with the received message inside the codename one layer, if it is not the case you won't need it.

Joseph Luong

unread,
Jul 31, 2015, 7:44:12 PM7/31/15
to Fabrício Cabeça, CodenameOne Discussions, Chen Fishbein, Shai Almog
Hi fabricio

I notice the other package name is com.mycompany.myapp.  But my so do i have to create subfolders under the native android to be native/android/com/m/company/myapp/smsReceiverBroadcast.java.  And in the manifest i just do the below?

<receiver android:name="com.mycompany.myapp.smsReceiverBroadcast" android:permission="android.permission.BROADCAST_SMS" android:exported="true"><intent-filter android:priority="5000"><action android:name="android.provider.Telephony.SMS_RECEIVED"/></intent-filter></receiver>

Joseph Luong

unread,
Aug 1, 2015, 1:43:23 AM8/1/15
to Fabrício Cabeça, CodenameOne Discussions, Chen Fishbein, Shai Almog
one of Chen forum said below but i don't get what he meant?  my broadcastreceiver extention is under native/android/userclasses/smsReceiverBroadcast.java i don't understand how you can get the below comment.  I'm REALLY STUCK here.

place the androidBroadcastReceiver under native/android/com/mycompany/myapp

Shai Almog

unread,
Aug 1, 2015, 2:47:01 AM8/1/15
to CodenameOne Discussions, fabrici...@gmail.com, cf2...@gmail.com, shai....@gmail.com, joseph...@gmail.com
He meant under the native hierarchy and not under the src hierarchy. Your package name must match the package name defined for your project which must match your domain name.
Don't use the com.mycompany package or the com.codename1 package for anything!
Once you submit to the appstore you can't change this!

Joseph Luong

unread,
Aug 1, 2015, 2:59:45 AM8/1/15
to Shai Almog, CodenameOne Discussions, Fabrício Cabeça, Chen Fishbein
hi Shai

Yes i understand he meant under the native.  So what i'm trying to ask is say i just created a new project the package i name it com.sos.myapp (that's the package name defined) so what your saying is under the native android i should have native/android/com/sos/myapp/smsReceiverBroadcast.java ?  So what i'm trying to ask is how do i match it under the native hierachy?  Like do i right click on the native android folder and create a package of the same name com.sos.myapp?  that's what i'm trying to understand.

Joseph Luong

unread,
Aug 1, 2015, 3:05:50 AM8/1/15
to Shai Almog, CodenameOne Discussions, Fabrício Cabeça, Chen Fishbein
hi i think i got it. 

 When i create a new java class under android native do i select my package ie com.sos.myapp, i noticed it puts it under the src folder but then i moved it to the native/android/smsReceiverBroadcast.java.  Is that correct?

Joseph Luong

unread,
Aug 1, 2015, 3:28:19 AM8/1/15
to Shai Almog, CodenameOne Discussions, Fabrício Cabeça, Chen Fishbein
hi guys

i got it to work.  It was just want i mentioned above.  i didn't select the package when i created the broadcastreceiver extension file now it works.  Thanks  for everyones help

Joseph
Reply all
Reply to author
Forward
0 new messages