I want to set default home application when user click my menu.
So, I make this code and resolveractivity is shown when I click my menu.
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.HOME");
intent.setComponent(new ComponentName("android","com.android.internal.app.ResolverActivity"));
startActivity(intent);
But, although I choose any applications in the resolver activity, default application isn't applied.
Why default home application isn't changed?
Related
I'm developing a simple android application using the TabActivity.
This Activity adds 3 tabs, each one with its own activity.
The problem is: when I tap each tab, the system calls onDestroy of the current activity. So, when I tap the first activity again, all the state of private fields are gone, its like it has created a new instance every time I change tabs.
I was searching around about this, and looking on the samples, but I guess that the default behavior is to keep the activity instances paused when the tab is not current.
Anyone have an idea of what I'm missing?
Thanks.
That is by design. You need to override onSaveInstanceState() and onRestoreInstanceState() in your activity class. You can store/retrieve state data there, or retrieve it int the Bundle passed into OnCreate(). See:
http://developer.android.com/reference/android/app/Activity.html#onCreate(android.os.Bundle)
to provide a list option i would like to use a context menu, is it possible to open a context menu through a onClick intent? if so how ?
thanks
I have multiple widgets provided by one app, and thus multiple classes that extend AppWidgetProvider. The idea is that every widget contains a Button, which starts a Service when pressed. This Service runs a bit of code and then stops. Now for the problem: for example, I have a Widget1a and a Widget1u. These widgets look like each other, but each widget does a slightly different thing. If I place a Widget1a on the homescreen and press it, a Service is started and the code that this Service should run is run, as it should be. Now I place a Widget1u on the homescreen, and suddenly Widget1a stops working and doesn't do anything when I press it. If I place a second Widget1a on the homescreen both Widget1as work again, but now Widget1u is disabled and doesn't respond when I press it. In short: it seems that at any particular time only one type's code works when it is pressed (and if there are multiple instances of the same type on the homescreen all of these instances will work, but no instances of any other widget of my app will do anything when pressed).
The code in the AppWidgetProvider of each widget is pretty basic. It merely contains an overrided onUpdate-method. It creates an Intent to start a Service that I previously created, this is then used to create a PendingIntent which is used by setOnClickPendingIntent to make sure it can be activated by a Button in the widget. Each widget makes, when its Button is pressed, a slightly different Intent so that a certain Service is executed slightly differently. So this only works for the instances of 1 widgettype at a time, namely those of which an instance was added to the homescreen most recently.
Why do all my app's other widgets stop working when I add a widget of a different type to my homescreen? Does anyone know more about widgets or how I can make sure that each widget keeps doing its job when I add a new one from the same app to the homescreen?
Here is the onUpdate method of one of my AppWidgetProviders for one of my widgets. All widgets operate similarly and I know I used a lot of copypasting which is a bad programming habit but it didn't seem to really want to work otherwise.
Code:
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// Create an intent to launch the service
Intent serviceIntent = new Intent(context, SendService.class);
//I just put some extra data here to be used by the Service which wil eventually get this Intent and thus the data inside
serviceIntent.setData(Uri.parse("uri::somethingrandomandunique"));
serviceIntent.putExtra("Lamp", "1a");
// PendingIntent is required for the onClickPendingIntent that actually
// starts the service from a button click
PendingIntent pendingServiceIntent =
PendingIntent.getService(context, 0, serviceIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
// Get the layout for the App Widget and attach a click listener to the
// button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget1a);
views.setOnClickPendingIntent(R.id.button1a, pendingServiceIntent);
// super.onUpdate(context, appWidgetManager, appWidgetIds);
ComponentName componentName = new ComponentName(context.getPackageName(), Widget1a.class.getName());
appWidgetManager.updateAppWidget(componentName, views);
}
So what am I doing wrong?
So I'm a noob when comes to android programing. Can someone tell me if the "Complete Action Using" dialog box is suppose to set the defaults when you use the "Always" response? Personally I thought it was however in my programming I have not been able to get it to use the "always" response always. What I mean is if I have "Google Music" installed and then I want to kick off the music player i ALWAYS get the "Complete Action Using" dialog popup.
To remove my code I went back to the Android developers first app program and used that. The SendMessage code now looks like this below. When running this on the emulator the "Complete Action Using" popup always comes up irrespective of selecting "Always" or "Just Once". What have I missed or done wrong?
Code:
public void sendMessage(View view) {
// Do something in response to button
if(android.os.Build.VERSION.SDK_INT>=15){
Intent intent=Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
Intent.CATEGORY_APP_MUSIC);
startActivity(intent);
}else{
Intent intent = new Intent("android.intent.action.MUSIC_PLAYER");//Min SDK 8 and deprecated in API 17 for makeMainSelectoryActivity
startActivity(intent);
}
}
tommiyau said:
So I'm a noob when comes to android programing. Can someone tell me if the "Complete Action Using" dialog box is suppose to set the defaults when you use the "Always" response? Personally I thought it was however in my programming I have not been able to get it to use the "always" response always. What I mean is if I have "Google Music" installed and then I want to kick off the music player i ALWAYS get the "Complete Action Using" dialog popup.
To remove my code I went back to the Android developers first app program and used that. The SendMessage code now looks like this below. When running this on the emulator the "Complete Action Using" popup always comes up irrespective of selecting "Always" or "Just Once". What have I missed or done wrong?
Code:
public void sendMessage(View view) {
// Do something in response to button
if(android.os.Build.VERSION.SDK_INT>=15){
Intent intent=Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
Intent.CATEGORY_APP_MUSIC);
startActivity(intent);
}else{
Intent intent = new Intent("android.intent.action.MUSIC_PLAYER");//Min SDK 8 and deprecated in API 17 for makeMainSelectoryActivity
startActivity(intent);
}
}
Click to expand...
Click to collapse
If you select "Always", the default application will be set which you can remove from the settings.
However, there should be a better possibility to do this.
You could try to use the unofficial Google Music API.
EDIT: If you just want to start Google Music use that code:
Code:
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address"); //replace the package name
startActivity(LaunchIntent);
nikwen said:
If you select "Always", the default application will be set which you can remove from the settings.
However, there should be a better possibility to do this.
You could try to use the unofficial Google Music API.
EDIT: If you just want to start Google Music use that code:
Code:
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address"); //replace the package name
startActivity(LaunchIntent);
Click to expand...
Click to collapse
Actually you can not use this to set a default application. You can try this in the emulator. The selection of Always does not impact the default application setting.
It appears that the Confirmation of "Always" and "Just Once" when ACTION_MAIN is used with a CATEGORY is a misnormer altogether. A default is only set when an Intent contains a mime type. So if you did not use ACTION_MAIN but say GET_CONTENT with a type of audio/* then you can launch with a default player.
Try it your self in the emulator this never sets a default. Seems everyone says it does but certainly the emulator and a real device support the outcomes that a default is never established through his call at all.
Stll looking for a answer but at least I now know that the above will always prompt you to select an application irrespective of any defaults set.
did you try it on a device?
out of ideas said:
did you try it on a device?
Click to expand...
Click to collapse
you mean my original code. Yes I did and the way it behaves is as described. I also went debugging what the makemainselector actually does under these situations. It actually registers the selected application in the packagemanager against the "Android device". Subsequent calls with the APP_MUSIC Category do not get found for some reason. Its like the code does not look for the application that is registered but asks for the number of applications that support the category and then throws a prompt rather than checking if there is a existing default. So either the makemainselector is the wrong thing to use or this just behaves incorrectly. When looking through the developer apps it does state to use makemainselectoractivity for API>15 as the action for the <15 intent of MUSIC_PLAYER is deprecated. However, an intent using MUSIC_PLAYER works corrctly and kicks off the default where as makemainselectoractivity seems to set the default, and kick off the app but does this every time. So either the documentation is incorrect or the code has a bug. If I get time I'll try and look through the code but at present it does not seem that this actually works to select a default allocated application and use it......you have to put up with being prompted and then selecting an option or double clicking every time.
Code:
Intent intent=Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
Intent.CATEGORY_APP_MUSIC);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//Min SDK 15
PackageManager pm = this.getPackageManager();
final ResolveInfo mInfo = pm.resolveActivity(intent, 0);
Toast.makeText(this, pm.getApplicationLabel(mInfo.activityInfo.applicationInfo), Toast.LENGTH_LONG).show();
startActivity(intent);
I can't for the life of me find ANYTHING written about how to create a shortcut to an app. All over stackoverflow it's just about having ones app get created as a shortcut onto users own launcher.
I want the user to be able to click my button which opens a dialog, in where the user can then select an app of their choosing, rename the shortcut and lastly hit the "Ok" button which should then let that app sit in my apps fragment until the user decides to remove it.
How would I go about doing this?
nex7er said:
I can't for the life of me find ANYTHING written about how to create a shortcut to an app. All over stackoverflow it's just about having ones app get created as a shortcut onto users own launcher.
I want the user to be able to click my button which opens a dialog, in where the user can then select an app of their choosing, rename the shortcut and lastly hit the "Ok" button which should then let that app sit in my apps fragment until the user decides to remove it.
How would I go about doing this?
Click to expand...
Click to collapse
To get a list of all installed applications, use
Code:
final PackageManager pm = getPackageManager(); //get a list of installed apps.
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
To start them just create a new Intent(packageName) and start it with startActivity(intent);
SimplicityApks said:
To get a list of all installed applications, use
Code:
final PackageManager pm = getPackageManager(); //get a list of installed apps.
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
To start them just create a new Intent(packageName) and start it with startActivity(intent);
Click to expand...
Click to collapse
Hey, thanks for the quick reply! That works wonders! Half way already. Thanks a lot.
Now how would I go about having it so that the apps I select in the list of apps stay selected, then upon an onClick of a button they get returned to my fragment (activity)? And to have them saved after that, would I need to read up on sqlite?