Android-dev.it Community

 
Annunci

:arrow: Benvenuto!, se non sei ancora un utente registrato: puoi registrati qui, oppure effettua il login
:arrow: Apri un forum sul tuo nuovo smartphone Android e collabora con noi! (dettagli)

www.agendadigitale.org
Image


Sponsor
It is currently Wed May 23, 2012 5:37 pm

All times are UTC + 1 hour


 Topics   Replies   Views   Last post 
No new posts На интернет-витрине

by popowahgjfghjoiuyt on Sat May 19, 2012 2:25 pm in Amministrazione

0

15

Sat May 19, 2012 2:25 pm

popowahgjfghjoiuyt

No new posts Apri un forum sul tuo nuovo smartphone Android!

[ Go to page: 1, 2, 3 ]

by ReattileGar on Fri May 18, 2012 5:27 pm in Amministrazione

27

12547

Fri May 18, 2012 5:27 pm

ReattileGar

No new posts Новый: базы для хрумера - профессиональный софт для СЕО.

by Renatafe on Fri May 18, 2012 3:14 pm in Amministrazione

0

23

Fri May 18, 2012 3:14 pm

Renatafe

No new posts Pace is undoubtedly the vital affordable Jerseys Wholesale d

by barnettmmolive2012 on Wed May 16, 2012 7:36 am in Amministrazione

1

48

Wed May 16, 2012 7:36 am

barnettmmolive2012

No new posts Problema di compatibilità app

by deran on Tue May 15, 2012 10:44 am in Sviluppo e programmazione in Android

4

201

Tue May 15, 2012 10:44 am

deran




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Lanciare applicazione a runtime
PostPosted: Mon Jan 17, 2011 2:01 pm 
Offline
User avatar

Joined: Tue Dec 28, 2010 12:11 am
Posts: 3
Punti Android: ?
Come posso inglobare nel pacchetto apk, e lanciare al verificarsi di un determinato evento un'applicazione C-linux passando dei parametri, come per esempio una foto scattata dalla fotocamera?


Top
 Profile  
 
 Post subject: Re: Lanciare applicazione a runtime
PostPosted: Tue Jan 18, 2011 10:12 am 
Offline
User avatar

Joined: Thu Dec 27, 2007 7:09 pm
Posts: 659
Cellulare Android: HTC Dream
Operatore: TIM
Punti Android: 758
Ciao,
per prima cosa devi ricompilare l'applicazione Linux per Android, sperando che ciò si possa fare senza dover mettere mano al codice e quindi senza dover lavorare al porting dell'applicazione. Una volta che hai l'eseguibile per Android/ARM, copiala sul filesystem di Android, settagi i permessi di esecuzione e prova a vedere se funziona.

Fatto questo, per lanciare un eseguibile nativo da un'applicazione Android, puoi sfruttare il metodo android.os.Exec ma per farlo devi usare la "reflection" perchè questo metodo non è reso immediatamente disponibile tramite API (analizza il codice open source che trovi qui:***URLs are hidden from guests, please register and login to view the hyperlink*** per avere un esempio su come fare), troverai delle righe di codici simili a queste:
Code:
try {
    // android.os.Exec is not included in android.jar so we need to use reflection.
    Class<?> execClass = Class.forName("android.os.Exec");
    Method createSubprocess = execClass.getMethod("createSubprocess", String.class, String.class, String.class, int[].class);
    Method waitFor = execClass.getMethod("waitFor", int.class);
   
    // Executes the command.
    // NOTE: createSubprocess() is asynchronous.
    int[] pid = new int[1];
    FileDescriptor fd = (FileDescriptor)createSubprocess.invoke(null, "/system/bin/ls", "/sdcard", null, pid);
   
    // Reads stdout.
    // NOTE: You can write to stdin of the command using new FileOutputStream(fd).
    FileInputStream in = new FileInputStream(fd);
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    String output = "";
    try {
        String line;
        while ((line = reader.readLine()) != null) {
            output += line + "\n";
        }
    } catch (IOException e) {
        // It seems IOException is thrown when it reaches EOF.
    }
   
    // Waits for the command to finish.
    waitFor.invoke(null, pid[0]);
   
    return output;
} catch (ClassNotFoundException e) {
    throw new RuntimeException(e.getMessage());
} catch (SecurityException e) {
    throw new RuntimeException(e.getMessage());
} catch (NoSuchMethodException e) {
    throw new RuntimeException(e.getMessage());
} catch (IllegalArgumentException e) {
    throw new RuntimeException(e.getMessage());
} catch (IllegalAccessException e) {
    throw new RuntimeException(e.getMessage());
} catch (InvocationTargetException e) {
    throw new RuntimeException(e.getMessage());
}

_________________
***URLs are hidden from guests, please register and login to view the hyperlink***


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
phpBB SEO

All trademarks and logos used in this site are of properties of their respective owners.