How to implement a 'free up space' button on Android? - android

I would like to create button that can navigate on system clean up screen which allow user to clear storage space. Similar to Google Play's button:
Any ideas about intent which I can fire? Or they are even different from device to device so it isn't worth effort?

you can try the following code:
void goStorageManage(){
Intent intent =new Intent(Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
startActivity(intent);
}

Related

take screenshot from ACTION_DIAL intent -java android

i am amateur in android
i want to take a screenshot from dial activity of user`s phone,
i use this for going to dial page
Intent call = new Intent(Intent.ACTION_DIAL);
startActivity(call);
what is the best way for get screenshot without root? and we should write the code inside onPause() method? because our app is paused when we go to an intent
You can use this library for getting screen shot
Link
hope it help

Add HomeScreen WebApps from another application? [duplicate]

Do you know is there a programmatic way to create a web shortcut on the phone user's home screen?
What I want to do is:
When the phone user clicks a button in our Android application, the application will then place a website shortcut onto the phone user's home screen.
First you'll need to add a permission to your manifest.xml
<uses-permission
android:name="com.android.launcher.permission.INSTALL_SHORTCUT">
</uses-permission>
You'll need to build an intent to view the webpage. Something like...
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://www.blablaba.com"));
You can test this by creating a little test app and doing startActivity(i); This should open the browser. Once you verified that the above intent is correct you should move on to the next step.
Now you'll need to actually install the shortcut.
Intent installer = new Intent();
installer.putExtra("android.intent.extra.shortcut.INTENT", i);
installer.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN");
installer.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", I THINK this is a bitmap); //can also be ignored too
installer.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(installer)
;
It's also possible some home screens don't accept this, but most do. So enjoy.
EDIT:
Icon can be set to the shortcut using:
installer.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", Intent.ShortcutIconResource.fromContext(mContext, R.drawable.icon));
As an addition to the correct answer by #Mike-dg and #Gagan, instead of using
putExtra("android.intent.extra.shortcut.ICON_RESOURCE", Intent.ShortcutIconResource.fromContext(mContext, R.drawable.icon))
which requires a ShortcutIconResource, you can use
putExtra("android.intent.extra.shortcut.ICON", Bitmap))
which lets you use any bitmap as the icon. This makes it easy to use a the favicon of the shortcut's website as the icon.
You can't place UI elements on the phone's home screen through an .apk. For the web shortcut - you can create a widget that opens the browser (with the specified URL) upon click.

Stay on my activity when dialing

I am using the intent with ACTION_CALL to make call in my app:
str="tel:0123456789";
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(str));
startActivity(intent);
But it pops up the system dialing screen. I understand this is built into ROM and can not be customized. But Can I hide this screen and keep the user staying on my activity?
Did some googling and research here. But no clear answer so far.
It looks like you can't customize the dialing screen, but you can use a PhoneStateListener to get certain information about the phone call. See this link.

How to create a shortcut button to jump to a DialogPreference

I would like to make a button on the front page of the app that jumps to a specific DialogPreference.
The purpose of the button is to be a shortcut to that preference, bypassing having to browse the list of all preferences, since I'm going to be resetting that preference a lot.
If it's not possible to make this button, can someone give me the source for DialogPreference (I don't have enough space to download the source tree).
You can use android.provider.Settings.* intent to do this... for example, if you want to open the GPS settings page from your app, use the following code:
Intent myIntent = new Intent( android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS );
startActivity(myIntent);

Sending a running application to background programmatically

Is it possible to send a activity into background programmatically in android?
I am creating a prank application that plays funny sounds after a specified time (input by the user). And I don't want the application to be visible when playing that sound and also the display should be dark.
Yes.
You can use either:
boolean sentAppToBackground = moveTaskToBack(true);
if(!sentAppToBackground){
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
this.startActivity(i);
}
More information here: http://developer.android.com/reference/android/app/Activity.html#moveTaskToBack(boolean)
Or simply:
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
this.startActivity(i);
According to Romain Guy a Android Framework Engineer, "You cannot simulate a press on the Home key.". So beware...
Check: http://osdir.com/ml/Android-Developers/2010-03/msg01887.html
Updated this answer according to: moveTaskToBack(true) returns false always
This function ultimately works for you
moveTaskToBack(true)
Or download source code . Android minimize app programmatically
Maybe play the sound from a service instead?
To expand on the answer by #ns476, the reason you should play it from a service is that any Activity that is no longer in the foreground can be killed at any time by the OS. Please review the activity lifecycle.

Categories

Resources