Search code examples
androidandroid-activitymoduletitaniumappcelerator

How run a native android Activity using titanium module?


I need to call a custom activity that is written in android in titanium studio. How should I run this code in accelerator?

The module code is this :

ChoosePDFActivity cpa = new ChoosePDFActivity();

Intent intent = new Intent(); 
intent.setClassName("com.pdfreader.my", "com.artifex.mupdf.MuPDFActivity");
Activity activity = TiApplication.getAppRootOrCurrentActivity();

activity.startActivity(cpa.showPDF());

Tiapp setting is :

<modules>
   <module platform="android">com.pdfreader.my</module>      
</modules>

and titanium code is :

var sample_module = require('com.pdfreader.my');
sample_module.example()

Nothing happen whenever i run my code? if i return a string i can show it in my titanium but i cannot run activity, can anyone help me? thanks


Solution

  • I solved my problem by changing my Java code:

    final File file = new File(path);       
    
    Uri uri = Uri.fromFile(file);
    Intent intent = new Intent();
    intent.setClassName("com.artifex.mupdf", "com.artifex.mupdf.MuPDFActivity");
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(uri);
    Activity activity = TiApplication.getAppRootOrCurrentActivity();
    activity.startActivity(intent);