How run a native android Activity using titanium module? - android

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

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);

require() is used to include CommonJS modules inside, it doesn't create Intent.
If you want to create Intent inside your titanium application follow documentation about Android platform

Related

Live template for starting activity in Android studio

Is there a live template for starting activity in Android studio that generates the code needed?
Here is the live template:
Intent intent = new Intent($ACTIVITY$.this, );
startActivity(intent);
Abbreviation that I use is starta.

How to open the My Files folder in Android Programatically (using Intent)?

I am using the below code which opens up the Gallery, Music Player, Dropbox and Contacts, i want the My Files folder to get open programatically, please let me know if there are any specific intent parameters i need to pass to get the File Manager open.
if it is not possible through intent then please give me a snippet or an hint to open the My Files folder programatically.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
Intent i = Intent.createChooser(intent, "View Default File Manager");
startActivityForResult(i, CHOOSE_FILE_REQUESTCODE);
Thanks.
You can use this code to file the files.
int PICKFILE_RESULT_CODE=1;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent,PICKFILE_RESULT_CODE);
this will help you to browse the files from your storage.
Its best that you include a library in your project which handles this scenario.
This worked for me:
This library shows the list of third-party apps. It also has its own file browser for selecting files.
Bad thing is, most Android distributions may or may not ship with a file manager, and even so, may be not with the one which handles CHOOSE_FILE_REQUESTCODE.
So, you are left to create your own file picker activity. Luckily there are many ready made ones available:
http://code.google.com/p/android-filechooser/
https://developers.inkfilepicker.com/docs/android/
If you want to open samsung My Files application try this below code.
Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
startActivityForResult(intent, CHOOSE_FILE_REQUESTCODE);
You have to specifically mention the package name of the explorer application. Please find the example below to open a specific folder in ES Explorer.
public void openfolderInexplorer(String path){
Intent intent = this.getPackageManager().getLaunchIntentForPackage("com.estrongs.android.pop");
if (intent != null) {
// If the application is avilable
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.parse(path);
intent.setDataAndType(uri, "resource/folder");
this.startActivity(intent);
} else {
// Play store to install app
intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("market://details?id=" +
"com.estrongs.android.pop"));
this.startActivity(intent);
}
try this below code. if any file manager available , then it will pop up in a form of menu to choose appropriate for the user.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, CHOOSE_FILE_REQUESTCODE);

Is it possible to uninstall one android application from other application?

Suppose there are two different Android apps: A and B.
App A is a system admin. Is there any way for it to uninstall app B or make it non-functional?
Yes, it is possible, you need to use Intent.ACTION_DELETE have a look at following code,
Uri packageUri = Uri.parse("package:com.mypackgage");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE,packageUri);
startActivity(uninstallIntent);
when you run the above code, it will ask for uninstall application as follows, image
try below code for uninstall apk...
Uri packageURI = Uri.parse("package:com.example.uninstall"); // replace with your package name
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
uninstallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(uninstallIntent);
By using the below code snippet you can uninstall an installed application on your ANDROID phone.It redirected you to the uninstall confirmation...
Create an intent object with an action and data as the package name
and start with the ACTION_DELETE.
Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:com.pack.Applicationname"));
startActivity(intent);

How to launch the stock installer app in android

I used to have this problem but I found a solution, so just decided to post it here just in case someone else needs it.
How to launch the native installer app to install an apk?
Many posts have the solution as below:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(path), "application/vnd.android.package-archive");
context.startActivity(intent);
This is fine except a tiny but crutial detail:
the "path" string must start with file:// otherwise you'll get an exception such as
Unable to find an activity to handle the intent .....
So make sure the path starts with file://
Cheers.
Actually, instead of using the parse(...) method, you can simply use the fromFile(...) method of the Uri class (the Uri will automatically have the form "file://").
Thus:
final File file = new File(path);
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
context.startActivity(intent);

how to open another app in a tabhost / how to open a word doc within a tabhost of android?

i've been trying to create an app that could open multiple activities with the help of the tabhost. one of the support is i would like to open a word document within my app.
i know how to open one with other app, but i hope it could be open within my app rather then having the need to press back button to return to my app.
the code that i use to open word doc :
File file = new File
(Environment.getExternalStorageDirectory(),"/MLT/student.doc");
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/msword");
startActivity(intent);
i tried to add it to my tab using
File file = new File (Environment.getExternalStorageDirectory(),"/MLT/student.doc");
intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/msword");
spec = tabHost.newTabSpec("Info").setIndicator("Info",
res.getDrawable(R.drawable.ic_tab_info)).setContent(intent);
tabHost.addTab(spec);
but i get runtime error, with the main
01-12 13:16:32.945: E/AndroidRuntime(10066): java.lang.SecurityException: Requesting code from com.infraware.polarisoffice (with uid 10053) to be run in process com.app.mlt (with uid 10128) "
You can pass this intent as content of your specified tab.
But you should be careful - there can be devices, that does not necessary apps for opening doc files, or there can be several apps for this. Any way it is better to use Intent.createChooser() method for such operations.
I tried using the MIME application/msword type it didn't work so I used application/vnd.ms-word

Categories

Resources