It it possible to start an adobe air apk from my current android app?
I tried this code but I got ActivityNotFoundException:
Intent intent = new Intent();
intent.setAction("air.caarsvcmobile.debug");
startActivity(intent);
Manifest:
<activity
android:name="caarsvcmobile"
android:label="CAARS Video Chat" >
<intent-filter>
<action android:name="air.caarsvcmobile.debug" />
</intent-filter>
</activity>
Is it possible to check package name and class name of an Air app?
After some Googling I found the solution of my problem:
Since I only knew the package name of the apk file I could use this code to launch the default launcher activity.
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("air.caarsvcmobile.debug");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
Thats all. I works fine.
Related
I am trying to add a short on home screen programmatically but it wont work.
The code works for Oreo and above but not below that.
public void addShortcutToHomeScreen() {
if (ShortcutManagerCompat.isRequestPinShortcutSupported(this)) {
ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(this, "#1")
.setIntent(new Intent(this, ActivityMemes.class).setAction(Intent.ACTION_MAIN)) //!!! intent's action must be set on oreo
.setShortLabel("Memeify")
.setIcon(IconCompat.createWithResource(this, R.mipmap.ic_launcher))
.build();
ShortcutManagerCompat.requestPinShortcut(this, shortcutInfo, null);
} else {
Intent shortcutIntent = new Intent(getApplicationContext(),
Activity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Name");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.mipmap.ic_launcher));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
addIntent.putExtra("duplicate", false);
getApplicationContext().sendBroadcast(addIntent);
}
}
Here is my Manifest file.
<activity
android:name="com.my.package.Activities.Activity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Please, Tell me what am I doing wrong cause I have tried to fixed it and have failed. And is there any better way than this? Any help would be appreciated thanks.
EDIT :
Found this in the Logcat.
2019-01-16 13:27:46.773 735-13377/? W/BroadcastQueue: Permission Denial: broadcasting Intent { act=com.android.launcher.action.INSTALL_SHORTCUT flg=0x10 launchParam=MultiScreenLaunchParams { mDisplayId=0 mBaseDisplayId=0 mFlags=0 } (has extras) } from com.chameleon.memeify (pid=14824, uid=10300) requires com.android.launcher.permission.INSTALL_SHORTCUT due to receiver com.sec.android.app.launcher/com.android.launcher3.home.InstallShortcutReceiver
you can use this method in your application class
public void createShortCut() {
Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
shortcutintent.putExtra("duplicate", false);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.drawable.logo);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext(), SplashActivity.class));
sendBroadcast(shortcutintent);
}
}
and apply this permission
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
If your are on Android 8+ you can't use the broadcast anymore and you have to use the ShortcutManager :
https://developer.android.com/about/versions/oreo/android-8.0-changes#as
Android 8.0 (API level 26) includes the following changes to app shortcuts:
The com.android.launcher.action.INSTALL_SHORTCUT broadcast no longer has any effect on your app, because it is now a private, implicit broadcast. Instead, you should create an app shortcut by using the requestPinShortcut() method from the ShortcutManager class.
The ACTION_CREATE_SHORTCUT intent can now create app shortcuts that you manage using the ShortcutManager class. This intent can also create legacy launcher shortcuts that don't interact with ShortcutManager. Previously, this intent could create only legacy launcher shortcuts.
Shortcuts created using requestPinShortcut() and shortcuts created in an activity that handles the ACTION_CREATE_SHORTCUT intent are now fully-fledged app shortcuts. As a result, apps can now update them using the methods in ShortcutManager.
Legacy shortcuts retain their functionality from previous versions of Android, but you must convert them to app shortcuts manually in your app.
To learn more about changes to app shortcuts, see the Pinning Shortcuts and Widgets feature guide.
I'm building an Android application that needs to have customer specific code. Customer specific code needs to be separated from the actual Android product our company supplies.
To do this I tried to create 2 packages:
com.company.product.activity
com.company.product.customcode.activity
Both packages contain ExampleActivity.
I have written a factory that uses reflection to determine of a custom component exists on top of the product class. This works fine.
Using the following code to start the ExampleActivity of product works:
Intent intent = new Intent(this, com.company.product.activity.ExampleActivity.class);
startActivity(intent);
Using the following code to start the ExampleActivity of customcode fails:
Intent intent = new Intent(this, com.company.product.customcode.activity.ExampleActivity.class);
startActivity(intent);
Error:
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.company.product.customername/com.company.product.customcode.activity.ExampleActivity}: java.lang.IllegalArgumentException: AppIndex: The URI host must match the package name and follow the format (android-app://<package_name>/<scheme>/[host_path]). Provided URI: android-app://com.company.product.customcode.activity/http/host/path
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2658)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2725)
I also tried this code, but then Android gives a Toast that it cannot find the Activity:
Intent intent = new Intent();
intent.setClassName("com.company.product.customcode.activity", "com.company.product.customcode.activity.ExampleActivity");
startActivity(intent);
Manifest:
<activity android:name="com.company.product.activity.ExampleActivity"
android:label="#string/app_name"
android:noHistory="false"
/>
//Custom implementation of the ExampleActivity
<activity android:name="com.company.product.customcode.activity.ExampleActivity"
android:label="#string/app_name"
android:noHistory="false"
/>
Does anybody have any ideas or tips how to achieve the maingoal: To split custom code from the productcode where activity names might be equal.
I am not sure what you missed here. I have tried this and it worked.
I have created a class MainActivity under package com.sample.so_sample.activities
and another MainActivity under package com.sample.so_sample1.test.activities
My manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.so_sample">
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".activities.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.sample.so_sample1.test.activities.MainActivity">
</activity>
</application>
</manifest>
and my call to navigate in com.sample.so_sample.activities.MainActivity is
Intent i = new Intent(this, com.sample.so_sample1.test.activities.MainActivity.class);
startActivity(i);
There is nothing wrong in the code.I had tried the same,it seems no issue.
Differen package names is the right way, it has to work fine, seem like problem is out of this code.
Your code can be in any java packages, you need just specify fully qulified name of activity in manifest. Android package name it's just a unique app id string.
instead of:
Intent intent = new Intent();
intent.setClassName("com.company.product.customcode.activity", "com.company.product.customcode.activity.ExampleActivity");
startActivity(intent);
try:
Intent intent = new Intent();
intent.setClassName("YOUR PACKAGE NAME IN MANIFEST", "com.company.product.customcode.activity.ExampleActivity");
startActivity(intent);
I've solved this question.
It seemed by further investigation that the Activity crashed because of some auto-generated code that was added while copy-pasting....
It seemed like a crash before the Activity was loaded, but this apparently was not the case.
Thank you all for you're answers, they were very useful!
I have a picture stored in my internal application storage, and I want to open it with android default application (gallery or any other).
So I'm using a FileProvider, my code works fine on android 4.3, but on some versions (2.3.6 for example), it doesn't work, the application open itself but then blackscreen, nothing.
My app needs to be API-10 compatible
I read many topics relating this problem, nothing seems to fix it. The code is probably not wrong since it works on 4.3...
Any thought?
My code to launch the activity :
File file = getMyFile();
Uri contentUri = FileProvider.getUriForFile(getContext(), <full-path-to-my-activity>, file);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(contentUri, "image/*");
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent = Intent.createChooser(intent, "Open with");
startActivity(intent);
in my manifest :
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="<full-path-to-my-activity>"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider"/>
</provider>
my provider.xml :
<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path
name="pictures"
path=""/>
</paths>
I have two sperate applications and I want to call start an activity from the second application in the first, here is my code to do so :
Intent intent1 = new Intent(Intent.ACTION_MAIN);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent1.setComponent(new ComponentName("org.two.three.application","org.two.three.application.one));
Context H= context;
H.startActivity(intent1);
And in the android manifest of the project I have this code, I have the line :
<activity android:name=".one">
</activity>
But I keep getting a runtime error, logcat says :
"Unable to find explicit activity class
{org.two.three.application/org.two.three.application.one}; have you
declared this activity in your AndroidManifest.xml?"
Can anyone see my error? The only thing I can think of is my package of the first activity is org.two.three.Class while the second is org.two.three.application.SecondClass. Does this matter?
Thanks in advance
At first try removing those code that you are adding
**
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent1.setComponent(new ComponentName("org.two.three.application","org.two.three.application.one));
Context H= context;
**
Then add following code into an action method like onClick
Intent intent = new Intent(this, NewActivity.class);
startActivity(intent);
Add your Android Manifest configuration file
<activity android:name="NewActivity"></activity>
You just need to make your activity publicly available. To do that just add
android:exported="true"
to the <activity> tag in your manifest.
Normally, activities are not available to other components that are outside of the package. This is the standard default behaviour. But, of course, you can make them available if you want to.
How can I get the package name of the current launcher in android 2.3 and above programmatically in Java ?
I think you should be able to use PackageManager.resolveActivity(), with the home intent.
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
String currentHomePackage = resolveInfo.activityInfo.packageName;
With the package visibility changes introduced in Android 11, it is now necessary to add a queries element in your application's manifest file as below before you can query the PackageManager.resolveActivity(intent:flags:) method for the default home (a.k.a. launcher) activity that is installed on the device:
<queries>
<intent>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
</intent>
</queries>
If this queries element is omitted from your application's manifest, then the device will report the com.android.settings.FallbackHome activity as its default home activity and that is most likely not what you want.
For guidance on how to query the PackageManager.resolveActivity(intent:flags:) method, see the accepted answer in this thread.
in general, I agree to #JesusFreke using the PM resolveActivity
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
but to get the right package name, you should use
resolveInfo.loadLabel(packageManager).toString()
or
resolveInfo.activityInfo.applicationInfo.loadLabel(packageManager).toString()
Hint:
if there is no default set, this might become "Android System" or "open" as for the general System Intent Receiver
Hint:
if you're looking for web browsers, you might use net.openid.appauth.browser.BrowserSelector#select() (0.7.1+) to implicit get the default browser even there is no one explicit set.