launch an installed app with my own by pressing a button - android

How can I launch an app (3rd party app) that is installed on my phone with my own app?
I'm having several buttons in my app and when one has pressed an app that is installed should open, for example, Bank of America app. (I want to create a customized menu).
I totally new to android programming, but could it work like this? What URI string could I use or how do I figure it out? Thanks a lot!
Button b_boa = (Button) findViewById(R.id.button_boa);
b_boa.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent open_boa = new Intent(Intent.ACTION_VIEW,
Uri.parse("_________"));
startActivity(open_boa);
}
});

You can launch a different app from your application on click of a button or something with the package name and if you dont know the launching activity of the application to be opened..You can use this
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(LaunchIntent);
and if you know the launching activity also which you can see from the manifest file of the app to be open then use this.
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.package.address","com.package.address.MainActivity"));
startActivity(intent);

Related

how to open my app by clicking any button in other installed apps

i like to open my own app by clicking any button in another installed app in my phone.
Example: when i click a delivery button in any shopping app then my app will open or my app icon will pop up in bottom.
( The same method used in insta download app for download Instagram picture, when we copy url of a instagram image the insta download app will pop up automatically )
is it possible??? if anyone knows please help me
Intent i;
PackageManager manager = getPackageManager();
try {
i = manager.getLaunchIntentForPackage("com.example.yourApp");
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
}
If you know the data and the action, you simply should add these information to your intent instance before starting it.
I am assuming you have access to the AndroidManifest of the other app, you can see all needed information there LIKE
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.package.address","com.package.address.MainActivity"));
startActivity(intent);

How to share my app to facebook and twitter only?

I would like to create a button in my app such that upon clicking facebook and twitter options would appear and user can immediately share my app.
Right now my codes are as below but it still doesn't work. Anyone knows the reason? I'm guessing I need to declare it on manifest but how do I go about?
public Intent onClick(View arg0) {
Intent normalIntent = new Intent(Intent.ACTION_SEND);
normalIntent.setType("text/plain");
normalIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
normalIntent.putExtra(Intent.EXTRA_TEXT, content);
return Intent.createChooser(normalIntent, "Share");

How to link 5 apps from one app. New to android

I have 5 android apps and im trying to make a front page that has 5 buttons that connects to each one. How do I go about this? i tried to create a onclick method in layout but it didnt work.
you can use the package name of App to open them on button click as :
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(LaunchIntent);
Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setData(Uri.parse("https://play.google.com/store/apps/details?id=your Package name"));
startActivity(i);
Declare it in your Activity.
Let me know if it helps you.

Close the app programmatically (know package name)

I use the following code snippet to launch an app on device:
Context mContext = getContext();
String packageName = getPackageName(); //the app to launch
Intent mIntent = getPackageManager().getLaunchIntentForPackage(packageName);
if(mIntent!=null){
mContext.startActivity(mIntent);
}
It works, the app get launched, however, I don't figure out a way to close the launched app by using the packageName.
How to close the launched app if I only know the package name?
You cannot close another app. Only the system can do that.
But if you are also the author of that other app, you could create a receiver in that app's activities that accepts an intent that tells it to finish() the activities.
You cannot close other application from your app.your problem has a workaround,after starting app based on package name you may send home intent which will give same experience to user.
Intent mIntent = getPackageManager().getLaunchIntentForPackage(packageName);
if(mIntent!=null){
mContext.startActivity(mIntent);
}
//sleep for 250ms or whatever time using handler
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);

Accessing Android Inbox/Messaging from Activity?

Is it possible to open up the default Android Messaging activity from inside an activity you write yourself? Like for example: I press a "Mail" button inside my program, and it opens the Android Messaging app just like as if I was to press the Messaging icon on the main screen.
I did something similar to this with the Contacts activity, but only the contact list comes up, no extra functionality like Adding/Modifying/Deleting, etc.
Any ideas?
edit: I found this way to open the "Compose New Message" Activity, I just need to back it up a step. Does anyone know the correct MIME type instead of this one?
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setType("vnd.android-dir/mms-sms");
m_activity.startActivity(sendIntent);
This starts the messaging app from another app:
Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(new ComponentName("com.android.mms","com.android.mms.ui.ConversationList"));
startActivity(intent);
Just put it inside a button listener or whatever user input you want to open it from.
Enjoy :-)
If you want to open the messaging app to view messages and not for sending a message, this should do the job:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setPackage("com.google.android.apps.messaging");
startActivity(intent);

Categories

Resources