Bring Live Wallpaper to Front - java

I had originally asked another question, but I think I found a work-around, which presents a new question hah!
I think my question is fairly basic, and I have searched for anything relevant.
When you are setting a live wallpaper in android, before you set the wallpaper, you have a chance to view the wallpaper without being in the background with all of your icons above it. A sort of "preview" of the wallpaper.
Is there a simple java code to force this activity, on a double tap for instance? I want the user to be able to bring the wallpaper to the front on demand basically.
Maybe this isn't possible, but I assume it is as you can do it before you actually set the wallpaper.
Any help would be greatly appreciated.
Thanks,
Jack
Edit-
I should note I think I found a similar question but the English is so bad I can't tell:
How to make directly show live wallpaper in main activity?
public void StartActivity() {
WallpaperInfo localWallpaperInfo = ((WallpaperManager) getSystemService("wallpaper")).getWallpaperInfo();
if (localWallpaperInfo != null) {
String str1 = localWallpaperInfo.getSettingsActivity();
if (str1 != null) {
String str2 = localWallpaperInfo.getPackageName();
Intent localIntent1 = new Intent();
ComponentName localComponentName = new ComponentName(str2, str1);
localIntent1.setComponent(localComponentName);
localIntent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(localIntent1);
}
}

You can use
wallpaper.bringToFront(); With a double tap listener.
Or you can use the answer on the question you have in your edit.

Related

Which is the best way to use media player?

Just to be clear, because my question can be not so clear.
I develop Music Player app. The thing is I have MainActivity and 4 Fragments in this activity(it's not all).
In each fragment I have list of songs retrieved from device using CustomCursorAdapter(for example: first fragment - all songs, second fragment albums e.t.c.)
I already tried to use MediaPlayerSingleton
public class singletonMediaPlayer{
MediaPlayer mediaPlayer;
private static singletonMediaPlayer in = null;
private singletonMediaPlayer() { }
public static singletonMediaPlayergetInstance() {
if (in == null) {
synchronized (singletonMediaPlayer.class) {
if (in == null) {
in = new singletonMediaPlayer();
}
}
}
return instance;
}
}
But here the problem was that all playback controls I have in MainActivity(not in fragments) and have no idea how to handle previouse, next buttons. It is not a problem if media player is in fragment or activity together with ListView of songs but like this... have no idea. Plus when I tried to select item(song) from another activity it just didn't play until I press play button. Playbacks I can see it through all fragments so it's looks like this(just in case):
Plus I have 2 seperate Activities to show songs from albums and from playlists. Sooooooooooo... Finaly the question is:
How do you think it is better to build Media Player for such app (just in case, I don't need code from you). Is it better to use Music Service(which I already started to build) or maybe Singletone is better(in that case I just don't know how to perform the task with singletone for now) or maybe there is another way??? Will be great if somebody response with hint, link or just show me the way in which better to go.
Thank you in advance!
P.S.
Yep, by the way there are 3 ListViews with songs(for now) - 2 of them reusable.

Make a call via my app programatically [duplicate]

This question already has answers here:
How to make a phone call using intent in Android?
(21 answers)
Closed 7 years ago.
I'm building an app that lets you do various tasks and for this particular task. I want the user to be able to call someone. I've taken a look at many questions but all of them tell you to use intents and direct you to the phone app or instead they give you an answer where the users clicks a button and it calls the number assigned in the code.
I want the user to be able to type in a number in and EditText field and be able to hit the call button to call someone, how can I do something similar to this?
I'm not sure if this website is good for stuff like this as answers are hard to come by so I will keep looking around for answers, hopefully someone can answer my q and help me out a bit.
EDIT -
Super disappointed with all the notices and the downvote, really sucks however I appreciate the answers provided. But none helped lol.
So here is how I managed to do what I had asked. I create a onClick event and defined the two main objects with the objects and IDS above it (The EditText and the Button). In the onClick method I got the code to check and see if anything has been entered in the textfield (EditText), it detects with the following code -
(!TextUtils.isEmpty(txtPhone)) {
Uri uri = Uri.parse("tel:" + txtPhone);
If numbers have been typed in, it will run this intent and pull the string from the EditText object.
Intent intent = new Intent(Intent.ACTION_CALL, uri);
startActivity(intent);
if nothing is in field it will show a toast.
Check below for my method. Hopefully someone in my position will benefit from this and wont have to get downvoted for no particular reason.
// Call button
ImageButton call = (ImageButton) findViewById(R.id.call_button);
final EditText txtPhoneNo = (EditText) findViewById(R.id.txtPhoneNo);
call.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String txtPhone = txtPhoneNo.getText().toString();
if (!TextUtils.isEmpty(txtPhone)) {
Uri uri = Uri.parse("tel:" + txtPhone);
Intent intent = new Intent(Intent.ACTION_CALL, uri);
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(),
"Please enter recipients number", Toast.LENGTH_LONG)
.show();
}
}
});
Looks like I will be using YouTube for stuff like this now, StackOverFlow is supposed to be about helping new users. Not downvoting their questions and repeatedly labelling their posts as duplicates and already answered.
You should check this : how to make phone call using intent in android? and the accepted answer.
I don't know whether you have searched or not, I found this solution as first link in my search and its pretty much what you want to do (i.e. Call Directly from your app).
Try this
handle this on your call button click
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+ editText.getText.toString()));
startActivity(callIntent);
add <uses-permission android:name="android.permission.CALL_PHONE" /> in Manifest

Calling two different activities on different devices (tablet and phone)

Here, I'm trying to start an activity on different devices (Android Tablet and Android Phone). Is there a way to use if statement to check which activity should to load based on the devices?
Here's my code:
Button buttonGo = (Button) findViewById(R.id.button_goToActivity);
buttonGo.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (tablet device) {
startActivity(new Intent(MainActivity.this, TabletActivity.class));
} else {
startActivity(new Intent(MainActivity.this, AndroidPhoneActivity.class));
}
});
Thanks for your effort...
In order to achieve that you must use Fragment not an Activity. the Design Philosophy of Fragments is exactly what you want. you can take a look at Example to see how it is implemented. This is a master-detail app with two Fragments, when device in a portrait mode or it is not a tablet it just shows master, otherwise it also shows detail beside the master and when you select an item from the list you will see the details without going to other Activity.
Firstly as Android Best Practice it is adviced to use Fragments rather than Activity to achieve your requirement.
But if you are keen on using Activity, then below is the solution to find device type and load different activities.
1) Have 2 values folders: values -> strings.xml and values-sw600dp -> strings.xml
2) Create string value in both the xml
<string name="device_type">PHONE</string> in values -> strings.xml
<string name="device_type">TABLET</string> in values-sw600dp -> strings.xml
3) create a method to check if current device is Phone or not
public boolean isPhone() {
String deviceType = getResource().getString(R.string.device_type);
if (deviceType.equalsIgnoreCase("PHONE") {
return true;
} else {
return false;
}
}
4) Depending on the device load your activity as you have already done in your above code snippet
Let me know if this helps...
Most likely, you should not have two separate activities here. Instead, you should have two different layouts for the same activity. The layout for phones should be in the regular res/layout folder and the layout for tablets should be in the res/layout-large folder. Read Supporting Different Screens for more details.
If you are using same fuctionality for Tablet Activity and Phone activity then you do not need two activities for this purpose. You need to make two different Layout xml for Tablet as well as Phone.
Make a Layout folder named : layout-large and layout-xlarge.
Now copy the xml file from normal layout folder and paste in both new layout folders.
No need to change the name of xml file.
Now Adjust xml file of layout-large and layot-xlarge as you want to make design for tablet.
Now on running application Tablet and phone bot will pick xml according to there size and screen density.
Note : the functionality should be same.
And if: you want to show different screen with different functionality for phone and tablet then. use this code for check.
if ((getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
}
Hope this wll help you.

Opening apps on buttons

Im trying to open. Google Search on my application. But the problem is. when I click the button. the COMPLETE ACTION USING windows is popping up instead of the google search.. search the net for more than an hour but it seems I cant find the solution.. here is my code..
#Override
public void onClick(View view) {
Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(ComponentName.unflattenFromString("com.google.android.googlequicksearchbox"));
intent.addCategory("android.intent.category.LAUNCHER");
startActivity(intent);
This is due to Android's nature to allow users to make their own decisions. If, for instance, they have Bing installed and prefer it as a search engine over Google, they will have the option to select it. As far as I know, there is no way to open a specific app this way. If the user selects Google and makes it the default app for this action, it will auto-open in successive times, but they must make that conscious decision first.
have you probably tried to follow this guide..?
It describes well about what you might need..
hope it helps..
List<ResolveInfo> resolveInfoList = getPackageManager().queryIntentActivities(intent, 0);
for(int i = 0; i < resolveInfoList.size(); i++) {
ResolveInfo info = resolveInfoList.get(i);
if (info.activityInfo.packageName.equals("com.google.android.googlequicksearchbox") {
// that's the one you want
}
}
I don't have Eclipse available right now to test it, but this should help you get there. Also check out the documentation for queryIntentActivities()
PS: I'm not sure about that packageName for google search
Try this. This code will search the meaning of value of query variable on google.
String url = "http://www.google.com/search?q=" + "Meaning of " +query;
Intent intentSearch = new Intent(Intent.ACTION_VIEW);
intentSearch.setData(Uri.parse(url));
startActivity(intentSearch);

How to show different page if user is first time user (Android)

I have a blank-ish Android Project and what I want to do is take the user to a different "page/screen" if it is their first time only.
I know the logic for this but since I'm new to Android, I'm unsure of how to code this.
Below are the steps I believe I need to take in order to accomplish this:
App loads. If Local storage contains setting "FirstTimeUser", then it is not their first time using the app. Show the MainActivity page. If FirstTimeUser setting does not exist, it is their first time using the app (or they have uninstalled and reinstalled it), so instead, show WelcomeActivity page.
After viewing Welcome activity page, create FirstTimeUser setting and set to False.
But how do I code this for an Android app?
Use shared preferences as shown:
//declare as global
SharedPreferences prefs = null;
//and in your onCreate method:
prefs = getSharedPreferences("packageNameHere", MODE_PRIVATE);
if (prefs.getBoolean("firstrun", true)) {
//do stuff here if first run
//make sure to flag the boolean as false
prefs.edit().putBoolean("firstrun", false).commit();
}
else{
//if not first run, do something else
}
There is something called "SharedPreferences" that i believe your looking for.
http://developer.android.com/reference/android/content/SharedPreferences.Editor.html

Categories