After some more reading, found that I could to do these from my native code:

    options[0].optionString = "-verbose:jni";

    vm_args.version = JNI_VERSION_1_6;
    vm_args.options = options;
    vm_args.nOptions = 1;
    vm_args.ignoreUnrecognized = 1;

    result = JNI_CreateJavaVM(&p_jvm, &env, &vm_args); // This line still 
errors

    if (result != 0)
    {
        LOGE("JNI_CreateJavaVM, result = %d", result);
        return;
    }

    local_ref = env->FindClass("com.android.calculator2/Calculator");
    if (local_ref == NULL)
    {
        LOGE("Can't find Java class com.android.calculator2/Calculator...");
    }

    local_ref = env->FindClass("com/test/jnidemo/AppJni");
    if (local_ref == NULL)
    {
        LOGE("Can't find Java class  com/test/jnidemo/AppJni ...");
    }

FindClass fails in both cases, any ideas? I have both these apps running in 
the background and the full path (package + app name) is correct

Thanks
HV

On Wednesday, July 18, 2012 1:07:09 PM UTC-7, HV wrote:
>
> The desktop icon is for the simple java app (JNIDemo.apk). I guess what I 
> need is a way of calling a Java method from a native library without having 
> to do a load library from the Java app. Is that possible?
>
> If I load the library from JNIdemo, then there will be 2 contexts of the 
> library, one from JNIDemo and the other from where I actually need to 
> launch DragonHunter, so that wont work for my requirement
>
>
> On Tuesday, July 17, 2012 11:55:01 PM UTC-7, Dianne Hackborn wrote:
>>
>> What is "DesktopIcon"?  I don't understand what you are describing.
>>
>> On Tue, Jul 17, 2012 at 2:46 PM, HV <[email protected]> wrote:
>>
>>> Ok, I got this working. A simple JAVA app (say JNIDemo) that calls a 
>>> native method (in say NativeLib.so), which in turn calls back a JNIDemo 
>>> method. All of this is working seamlessly. Now, the next problem I have is 
>>> context related. I have a desktop icon which is supposed to launch an 
>>> Android app (such as DragonHunter) and that is failing:
>>>
>>> 1. JNIDemo -> NativeLib -> JNIDemo (works fine)
>>> 2. DesktopIcon -> NativeLib -> JNIDemo (fails to launch an app such as 
>>> DragonHunter)
>>>
>>> Now, since 1 & 2 are running in separate processes, the JNI variables 
>>> are no longer valid in #2. Any ideas?
>>>
>>> On Saturday, July 7, 2012 11:40:05 PM UTC-7, HV wrote:
>>>>
>>>> Thanks Dianne, that's what I thought, hence this question. Glad to know 
>>>> that using 'am' is not the way to go. Could you please provide a link to 
>>>> the SDK where it talks about this? If there is an example, that'll be 
>>>> awesome
>>>>
>>>> Thanks again
>>>> HV
>>>>
>>>> On Saturday, July 7, 2012 5:13:07 PM UTC-7, Dianne Hackborn wrote:
>>>>>
>>>>> No don't do that, the am command is not part of the SDK, and doing it 
>>>>> this way is horrible inefficient (you need to spin up and initialize a 
>>>>> fresh Dalvik vm for the am command, which takes a second or more), and 
>>>>> usually totally broken because you are not launching the activity from 
>>>>> your 
>>>>> own context for the system to correctly associate the call with you.
>>>>>
>>>>> And on top of that, your example here uses an explicit component name 
>>>>> of the browser activity, which is *completely* an implementation detail: 
>>>>> it 
>>>>> is likely to be different across different devices, it is *definitely* 
>>>>> different on devices that ship with Chrome as the default browser, etc.
>>>>>
>>>>> This is totally wrong.
>>>>>
>>>>> The right thing to do is follow the SDK and do it the right way, the 
>>>>> way it is documented.  If you need to write a little bit of JNI code (and 
>>>>> it *is* a little bit, just a method call into your own Java method that 
>>>>> uses the SDK), then that is what you do.
>>>>>
>>>>> On Fri, Jul 6, 2012 at 11:58 PM, Sandeep Kumar <
>>>>> [email protected]> wrote:
>>>>>
>>>>>> try below:-
>>>>>>
>>>>>> ret = execl("/system/bin/sh", "sh", "-c", "am start -a 
>>>>>> android.intent.action.MAIN -n   com.android.browser/.**BrowserActivity", 
>>>>>> (char *)NULL);
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Saturday, July 7, 2012 3:51:58 AM UTC+9, HV wrote:
>>>>>>>
>>>>>>>  Wanted to know what is the best practice to launch apps from native 
>>>>>>> code? Is using 'am' forbidden? It has to be via the system call though, 
>>>>>>> like system("am start ..."); Will 'am' support be discontinued going 
>>>>>>> forward?
>>>>>>>
>>>>>>>  Is there any alternative method?
>>>>>>>
>>>>>>> Thanks much
>>>>>>> HV
>>>>>>>
>>>>>>  -- 
>>>>>> unsubscribe: 
>>>>>> android-porting+unsubscribe@**googlegroups.com<android-porting%[email protected]>
>>>>>> website: 
>>>>>> http://groups.google.com/**group/android-porting<http://groups.google.com/group/android-porting>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> -- 
>>>>> Dianne Hackborn
>>>>> Android framework engineer
>>>>> [email protected]
>>>>>
>>>>> Note: please don't send private questions to me, as I don't have time 
>>>>> to provide private support, and so won't reply to such e-mails.  All such 
>>>>> questions should be posted on public forums, where I and others can see 
>>>>> and 
>>>>> answer them.
>>>>>
>>>>>   -- 
>>> unsubscribe: [email protected]
>>> website: http://groups.google.com/group/android-porting
>>>
>>
>>
>>
>> -- 
>> Dianne Hackborn
>> Android framework engineer
>> [email protected]
>>
>> Note: please don't send private questions to me, as I don't have time to 
>> provide private support, and so won't reply to such e-mails.  All such 
>> questions should be posted on public forums, where I and others can see and 
>> answer them.
>>
>>

-- 
unsubscribe: [email protected]
website: http://groups.google.com/group/android-porting

Reply via email to