So a few days ago I build an update for my custom android car tablet with my own launcher (based on Nexus 7 2013, Android 5.1.1). I added a few new features and some fixes (which have nothing to do we the activity that causes the problem), and I added accidentally the device admin permission together with the install packages permission.
After the update was installed on the tablet, the device opened always the Android for work app when clicked something which should start an external app (like Spotify or Maps). I thought it might be something with these permission and I deleted them and reinstalled a new version of the app (not updated!), but it didn't worked, it still started the Android for work app.
Then I uninstalled the Android for work app, and now the google now app started. After uninstalling it too, the settings app now launches?!
Has anyone an idea why this is happening and what I can do to get rid of it?
PS: Here is the code I am using to start an app using it's package name which is hundred percent right (there cannot be the failure):
pkg1 = prefs.getString("dash_app_music", null);
....
private View.OnClickListener clickhandler = new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tv_action_1:
Intent i = pm.getLaunchIntentForPackage(pkg1);
startActivity(i);
break;
case R.id.tv_action_2:
Intent i2 = pm.getLaunchIntentForPackage(pkg2);
startActivity(i2);
break;
case R.id.tv_back:
onBackPressed();
break;
}
}
};
Ok it came out that for some reason the package name for the packagemanager which gets the intent was empty and therefore android starts the settings app as a fallback(?).
Related
My Goal is here is to set my app as default launcher on Huawei devices.
1 - Explanations:
1.1 - Current situation:
I am already able to:
Check if my app is the default launcher
Display the 'launcher picker' (with the 'use once' / 'always' choice)
This all works fine.. except on Huawei devices!
From my point of view, Huawei's Android flavor does not properly 'honor' the "ACTION_MANAGE_DEFAULT_APPS_SETTINGS" intent action contract.
// this displays the list of default apps on all tested devices, except on Huawei devices!
// instead, it does display apps permissions, app links and apps'advanced settings
intent.setAction(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS);
activity.startActivity(intent);
As a B Plan, I am able to display the 'Applications & Notifications' settings 'page' using this:
String packageName = "com.android.settings";
String className = "Settings$AppAndNotificationDashboardActivity";
intent.setClassName(packageName, packageName + "." + className);
activity.startActivity(intent);
So the user can navigate from there, pressing this sequence of menu items:
-> Advanced Parameters ( expandable menu item : not present on tablet, and not sure it's present on phone)
-> Default Apps
-> Default Launcher
This requires 2 or 3 steps that I would like to avoid.
1.2 - This can be improved!
I found out that when the "-> Default Apps" menu item is selected, a (com.android.settings, .SubSettings) Intent (with extra) is launched but I was not able to make this works (permission denial).
But I installed Nova Launcher and it turns out it's able to display the "-> Default Apps" settings page on Huawei devices!
So the user land on a page where she/he only has to tap on "-> Default Launcher" then choose a default launcher: much easier.
2 - Questions:
As I think it's just not possible to display the 'Lancher Picker' on Huawei devices, here is my question:
How can I display the "-> Default Apps" settings page (image down here) on Huawei devices (like Nova Launcher does)?
Are they using another intent action on Huawei devices?
Thanks beforehand your help.
Yes on Huawei devices, Nova uses a different intent to open to the correct screen. I likely found this by using apktool on the Settings.apk pulled from a Huawei device and looking at the AndroidManifest.
Note that "com.android" is always a code smell as it means it's not part of the public API. Also this isn't even really "com.android" as it doesn't exist on AOSP and com.android.settings.PREFERRED_SETTINGS is purely a Huawei invention. It's very likely that some Huawei devices won't have this at all. It's also possible that in the future this intent might continue to work but not do what it currently does. So handle it carefully.
/* Some Huawei devices don't let us reset normally, handle it by opening preferred apps */
Intent preferredApps = new Intent("com.android.settings.PREFERRED_SETTINGS");
preferredApps.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
if (pm.resolveActivity(preferredApps, 0) != null) {
context.startActivity(preferredApps);
} else {
...
}
In fact, the accepted answer is not 100% correct, because it opens a general default apps chooser activity.
It works, but it's better to bring user right to the launcher chooser activity — it's com.google.android.permissioncontroller/com.android.packageinstaller.role.ui.HomeSettingsActivity (at least for the Android 10 Huawei Honors).
So, the correct code snippet is:
Intent()
.apply {
component = ComponentName("com.google.android.permissioncontroller", "com.android.packageinstaller.role.ui.HomeSettingsActivity")
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
}
.takeIf {
packageManager.resolveActivity(it, 0) != null
}
?.let(context::startActivity)
I have a smartwatch 2 app on the market which has been working fine for months, but recently it has started crashing a second after the context menu is opened.
The onKey code looks like this:
#Override
public void onKey(final int action, final int keyCode, final long timeStamp) {
// Menu button click
if (action == Control.Intents.KEY_ACTION_RELEASE
&& keyCode == Control.KeyCodes.KEYCODE_OPTIONS) {
showMenu(mMenuItemsText);
}
}
(mMenuItemsText is defined at the class level and instantiated in the constructor:
mMenuItemsText[0] = new Bundle();
mMenuItemsText[0].putInt(Control.Intents.EXTRA_MENU_ITEM_ID, MENU_ITEM_REVERSE_RATE);
mMenuItemsText[0].putString(Control.Intents.EXTRA_MENU_ITEM_TEXT, context.getResources().getString(R.string.converter_menu_reverse_rate));
)
When I click the watch menu button in my app, the menu opens up, and then a second later the watch crashes and disconnects from the phone before starting back up and reconnecting to the phone. Nothing in logcat and the phone doesn't show a crash prompt, it seems completely unaware that the watch has crashed.
If I put Log.d statements on each line above then they all show up in logcat, it seems to be happening after the menu has finished its "swipe in" animation.
Thinking the problem was in the utils app, I tried replacing the showMenu call with the same code to send the menu intent directly:
#Override
public void onKey(final int action, final int keyCode, final long timeStamp) {
// Menu button click
if (action == Control.Intents.KEY_ACTION_RELEASE
&& keyCode == Control.KeyCodes.KEYCODE_OPTIONS) {
Intent intent = new Intent(Control.Intents.CONTROL_MENU_SHOW);
intent.putExtra(Control.Intents.EXTRA_MENU_ITEMS, mMenuItemsText);
sendToHostApp(intent);
}
}
But I get the same problem. I have another SW2 app on the market with the same code and it works fine. I'm completely stumped as to how to find the problem, as I'm unable to step into the code in Eclipse.
This issue will be fixed in the upcoming 1.4.54 host app SW to be released in the next few days. The issue has to do with the number of touch regions supported, which has been increased from 25 to 30 in the update.
I have about the same problem. I have several menus in my app but only one of them will crash the Smartwatch 2. It happens every time now, also reported by many users. The problem came after the recent firmware update. So hopefully it will be fixed in a new firmware or updated SDK release.
My problem is now fixed in latest firmware from Sony
I have inserted some code in my app to check if there is a new version avaliable.
In case there is one, the user get a dialog asking if he want to update.
Everything is working fine, but the problem is that even if the play store is showing that the current version avaliable is 1.1, and the users has the version 1.0, it still ask to "launch" or "uninstall" the app, and doesn t show any update button.
This is problematic because the user will keep recieving the update dialog and will be redirected to a page that isn t showing any updated version.
here is my code:
if (!lastVersion.equals(actualVersion)){
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case DialogInterface.BUTTON_POSITIVE:
//Yes button clicked
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.xxx.yyy"));
startActivity(intent);
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.xxx.yyy")));
}
break;
case DialogInterface.BUTTON_NEGATIVE:
//No button clicked
if (force_update){
android.os.Process.killProcess(android.os.Process.myPid());
}
break;
}
}
};
I have fixed my own problem.
In fact, as I had modified my app and tested it on the phone I was trying to get the update proposal on, I guess something, maybe an apk signature, was irrevelant for the apk published on the play store.
I tried to then install the apk version 1.0 from the store, and then, the play store shown me the update button.
We can get last version using this request https://androidquery.appspot.com/api/market?app=com.instagram.android
But if our app is blocked we get 500 error
in agreement with the recent post from Android Developers http://android-developers.blogspot.pt/2013/10/getting-your-sms-apps-ready-for-kitkat.html ,I was trying to prepare my app to the new android version, but encountered a problem with the part they suggest to create a dialog to let the user set the app as the default application to handle SMS's :
Android Developers Post
public class ComposeSmsActivity extends Activity {
#Override
protected void onResume() {
super.onResume();
final String myPackageName = getPackageName();
if (!Telephony.Sms.getDefaultSmsPackage(this).equals(myPackageName)) {
// App is not default.
// Show the "not currently set as the default SMS app" interface
View viewGroup = findViewById(R.id.not_default_app);
viewGroup.setVisibility(View.VISIBLE);
// Set up a button that allows the user to change the default SMS app
Button button = (Button) findViewById(R.id.change_default_app);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent =
new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
myPackageName);
startActivity(intent);
}
});
} else {
// App is the default.
// Hide the "not currently set as the default SMS app" interface
View viewGroup = findViewById(R.id.not_default_app);
viewGroup.setVisibility(View.GONE);
}
}
}
the code itself in pretty much straightforward, but I'm unable to access to Telephony.Sms.getDefaultSmsPackage because it says that Telephony cannot be resolved, and I can't find any import or declaration that would fix that.
Can anyone please help?
android.provider.Telephony simply doesn't exist yet (as of API 18 - 4.3).
This class will be added in 4.4 (presumably API 19), and that blog post is highlighting the changes that you should make once the new API is released so you aren't surprised when the time comes.
From the end of the post:
To help you make the changes, we'll soon be providing the necessary SDK components for Android 4.4 that allow you to compile and test your changes on Android 4.4.
Don't forget that you should wrap this code in an API version check so you don't run into issues with older versions that don't have this class.
this change will break all the SMS blocking apps.
"Note that—beginning with Android 4.4—any attempt by your app to abort the SMS_RECEIVED_ACTION broadcast will be ignored so all apps interested have the chance to receive it."
Do you think there is a way to go around this?!
Maybe at least on Root?
Apparently there is with root access. The latest version Cerberus app claim to be doing this.
Now, if only I knew how they do it :(
The issue is that I need to install an apk(non market app) and for this, the user need to activate the unknown source setting, so i send him (if he didn't have it activated) to the settings so he can turn on the option, the issue is that i tested it in different phones and in samsung that option is on applications while in htcs phones is on security. i want send the user to that option but i don't know how to do it
I read about this and no one knows exactly how to do it
this is my code
int canInstallFromOtherSources = Settings.Secure.getInt(ctx2,Settings.Secure.INSTALL_NON_MARKET_APPS);
if(canInstallFromOtherSources == 0)
{
Intent intentSettings = new Intent();
intentSettings.setAction(android.provider.Settings.ACTION_APPLICATION_SETTINGS);
startActivity(intentSettings);
}
You can do it with the following line (changing to the corresponding action):
startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), REQUEST_CODE_ENABLE_LOCATION_PROVIDERS);
Check Android Settings documentation.
I think you should use ACTION_SECURITY_SETTINGS and one of ACTION_APPLICATION_SETTINGS or ACTION_APPLICATION_DEVELOPMENT_SETTINGS.
And here (line 304), you've got a working example of one of my apps: Tureame