Live template for starting activity in Android studio - android

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.

Related

Opening a native settings menu page programmatically in NativeScript

How can you programmatically open a page from the native Android settings menu using NativeScript?
Classic java examples show it can be done this way:
Intent intent = new Intent(Settings.ACTION_SETTINGS);
startActivity(intent);
but how to do the same in NativeScript?
This can be achieved using the module tns-core-modules/application, which will make startActivity available. An example using TypeScript is provided below:
import * as appM from 'tns-core-modules/application';
const intent = new android.content.Intent(android.provider.Settings.ACTION_SETTINGS);
const activity = appM.android.foregroundActivity || appM.android.startActivity;
activity.startActivityForResult(intent, 0);
Unfortunately, TypeScript types are not included for foregroundActivity and startActivity, which made finding a solution to this extremely hard.
A big thanks to user10655801 for his test repo containing the solution.

Could not use the standard linking in my app

I have just updated the new Uber app (January 8, 2018) and the deep linking is not working.
Could you explain more?
Below is my code:
formattedUrl = String.format("uber://action=setPickup&client_id=%s&dropoff[latitude]=%f&dropoff[longitude]=%f",
mClientId, http://to.lat , to.lng);
Uri uri = Uri.parse(formattedUrl);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(uri);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(i);
With the old version of Uber app, my code works well. It shows the correct the pickup & drop off location but in the new app, it doesn't work.
May be they have updated things on this in their application.
You can generate deep link using this link.

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

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

Open add contact activity android sdk 2.1 and above

i am using the following code to open android defaults add contact activity to add contact in phone.
Intent intentInsert = new Intent(Contacts.Intents.Insert.ACTION);
intentInsert.setData(People.CONTENT_URI);
startActivity(intentInsert);
But its showing deprecated when using in android sdk 2.1 and above.
how to show add contact activity in new contacts contract api.
Thanks
try this
Intent i = new Intent(Intent.ACTION_INSERT_OR_EDIT);
i.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
i.putExtra(Insert.NAME,"Name");
i.putExtra(Insert.PHONE,"Number");
startActivity(i);
yes above method got deprecated after 2.1 or above try to use
intentInsert.setData(ContactsContract.CONTENT_URI);
for sdk 2.1 or above

Categories

Resources