Shortcut to settings android - android

I'm interested about how is possible create a shortcut to different items of settings in android devices.
Specifically to advances settings of mobile data.
I want to do an app that allows user a quick access to switch menu 2g-3g.
I know that the app dosen't do switch, I only want the shorcut to this menu.
I don't know how It's made!
I'm very glad if somebody help me!
Thanks a lot!!!
public class MainActivity extends Activity implements OnClickListener
{
Button boton;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
boton = (Button) findViewById(R.id.boton);
boton.setOnClickListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onClick(View v)
{
if(v.getId() == R.id.boton)
{
startActivity(new Intent(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS));
}
}
}
I do this code by the explanation of Seraphim but dosen't work.

To switch to the 2G/3G settings page use this code inside the Button click handler:
startActivity(new Intent(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS));
or others, look at:
http://developer.android.com/reference/android/provider/Settings.html
Other interesting are:
android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS
android.provider.Settings.ACTION_NETWORK_OPERATOR_SETTINGS
android.provider.Settings.ACTION_WIRELESS_SETTINGS
android.provider.Settings.ACTION_APN_SETTINGS

i would like to suggest u that refer this three link(FIRST,SECOND,THIRD) and u would be able to change most of the settings by ur own . ANDROID SETTINGS mostly stores there respective values to this three tables.
If you want to enable or disable GPS than use
Settings.Secure.setLocationProviderEnabled(cr, LocationManager.GPS_PROVIDER, true);

Related

How can i move to any other activity with jfeinstein slider library

I have implemented jfeinstein10 slider menu library in my application. With this piece of code I am successfully able to implement slider in my app.
Now my question is how can I move to next activity using this slider? The following image shows how my slider looks like:
So basically I want to move to next activity or any other activity when I click on any of the options from slider. Like for example, when I click on Comment or Post or Chat or any other option I want to go to the relevant screen. Hope this is clear. Still if you need more explanation you can ask.
Following is my code snippet.
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.RIGHT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.5f);
menu.attachToActivity(MainActivity.this, SlidingMenu.SLIDING_CONTENT);
menu.setMenu(R.layout.activity_menu);
Button mButton = (Button) findViewById(R.id.slidingMenu);
mButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
menu.showMenu();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
You can define the onclick listenrs to the Menu layout that you have appended to the Main Activity like so:
menu.getMenu().findViewById(R.id.yourSideMenuOption).setOnClickLister(this);
Its advisable to use an abstract activity, so that you are not using the same code over and over in each of your activity.

Options menu persists in the second activity

After clicking a button to open a new Activity using this method:
setContentView(R.layout.activity_comunidades01);
The second Activity still display the same menu as the previous one.
I have already readed serval methods to fix it as the one related in here:
Android: How to enable/disable option menu item on button click?
But I discovered that the methods to intialize and create the menu are never called. I even try to follow this other link without success:
onCreateOptionsMenu is never called
I even deleted all the items in the menu.xml for this activity but still displaying the previous activity options.
I also clarify I am using android 4.4 as target API but level 10 as a minimum one since some devices that will be used are running android 2.3.
My second Activity is like this:
public class SecondActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_SecondActivity);
}
#Override
public boolean onPrepareOptionsMenu(Menu menu){
System.out.println("EN ON PREPARE OPTIONS MENU");
(menu.findItem(R.id.sincronizar)).setEnabled(false);
return super.onPrepareOptionsMenu(menu);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
System.out.println("EN ON CREATE OPTIONS MENU");
getMenuInflater().inflate(R.menu.SecondActivity, menu);
return true;
}
}
To start second activity use this:
Button bt = (Button)findViewById(R.id.bt);
bt.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(intent);
//finish(); //if you want to close FirstActivity after showing SecondActivity
}
});
After clicking a button to open a new Activity using this method:
setContentView(R.layout.activity_comunidades01)
This is not how you open another activity!
This way you only change the content of the current activity, nothing else.
Use Activity.startActivity() or Activity.startActivityForResult() as described in the docs to start another activity.

Setting the dropdown for the action bar item

I am setting the action bar and item by the below code and the respective image1 is shown. When the user clicks on show bookmark screen action item, it goes to other activity. In that activity I want another item(SELECT BOOKMARK TYPE ) to be displayed in the place of SHOW BOOKMARK SCREEN. So I am thinking to managing it with abstract class by setting the respective things to true or false as shown below. But now I am unable to get two things.
1) How to differentiate in case 0 for both action items? as I am replacing the action item with one another.
2)How to get the dropdown for that SELECT BOOKMARK TYPE as exactly shown in the image 2.
Have seen few posts, but as I am somewhat new to android, I am unable to understand and get it done by adding the extra code to my present code. Can you please help me on this? Code snippets are appreciated. Thanks in advance.
public abstract class ActionActivity extends SherlockActivity {
protected boolean mIsShowBookmarkScreen = true;
#Override
public boolean onCreateOptionsMenu(Menu menu) {
if(mIsShowBookmarkScreen)
{
menu.add("SHOW BOOKMARK SCREEN")
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
else
{
menu.add(SELECT BOOKMARK TYPE);
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
//This uses the imported MenuItem from ActionBarSherlock
switch(item.getItemId())
{
case 0:
Intent intent = new Intent(ActionActivity.this,BookmarkScreen.class);
startActivity(intent);
return true;
}
return false;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setHomeButtonEnabled(true);
}
}
image 1:
image 2:
At least can someone please help on achieving second one. I got an idea on 1st problem.
1) Differentiate by using instanceof.
if (this instanceof ActivityA) {
// start Intent A
} else if (this instanceof ActivityB) {
// start Intent B
}
2) Add a Spinner as a custom ActionView.
<string-array name="items">
<item>SELECT BOOKMARK TYPE</item>
<item>TYPE-1</item>
<item>TYPE-2</item>
<item>TYPE-3</item>
</string-array>
MenuItem spinnerItem = menu.add(null);
spinnerItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
IcsSpinner spinner = new IcsSpinner(this, null);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.items, R.layout.sherlock_spinner_item);
adapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
spinnerItem.setActionView(spinner);
Note that I am using the kind of private IcsSpinner here to create the same look on SDK Version < 4.0. See this answer for details.
If you want to further customize the Spinner, you will probably need to create your own Adapter.

android device specific functionality

different android devices will occasionally have different onscreen features (such as the buttons at the bottom of the screen in kindle fire apps). How can you change the behavior of these kind of buttons? I can't find any resources on doing such a thing..
** EDIT **
I found out that what I referred to as the "bottom buttons" is more appropriately called the Options Bar per some Kindle Fire documentation from Amazon
** EDIT **
Considering both answers say that this isn't possible, I decided it's time for an example. It looks like the menu I want to make is actually part of the application, but has a button listener for those system buttons. How do I go about finding example code for using those buttons?
How can you change the behavior of these kind of buttons?
You ask the manufacturer of the device in question how to modify things that they did that lie outside of the Android SDK. The odds are very good that the answer is "you can't".
How can you change the behavior of these kind of buttons?
behavior? You cant change behavior of 3rd party apps buttons that placed at the bottom of kindle fire (Its just OptionsMenu, and called by pressing "Menu" button on other android based devices)
You can disable these buttons - Home, Back and other stuff... (but not on kindle)
Kindle Fire does not support apps that contain disable_keyguard permissions or customize the lockscreen.
https://developer.amazon.com/help/faq.html#KindleFire
here it is: (java)
package com.wali.jackonsoptionsmenu;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
public class JacksonsOptionsMenuActivity extends Activity {
private final static String TAG = JacksonsOptionsMenuActivity.class
.getSimpleName();
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
// this one is called once before showing OptionsMenu
#Override
public boolean onCreateOptionsMenu(Menu menu) {
Log.d(TAG,
"onCreateOptionsMenu: called once, while creating options menu");
getMenuInflater().inflate(R.menu.jackonsmenu, menu); // this one
// inflates your
// xml based
// menu into
// memory and
// sets to menu,
// from
// 'R.menu.jacksonsmenu
// to 'menu'
return true; // if You want to handle bottom bar menu (OptionsMenu) you
// have to return 'true'
}
// this one is called everytime, but before showing the menu
// if You want to change button name, icon or other stuff, do it here
// its something like preparing
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
Log.d(TAG,
"onPrepareOptionsMenu: called everytime before showing the OptionsMenu");
return true;
}
// this one is called everytime, after the OptionsMenu is shown
// this one comes, if everything is ok in Your implementation, otherwise,
// nothing
#Override
public boolean onMenuOpened(int featureId, Menu menu) {
Log.d(TAG, "onMenuĂ–pened: called everytime after the OptionsMenu shown");
return true;
}
// this on is called when an item selected try item.getItemId()
#Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.d(TAG, "onOptionsItemSelected: called when an item selected");
switch (item.getItemId()) {
case R.id.menuRefreshAll:
Log.i(TAG, "onOptionsItemSelected: refreshing everything");
break;
case R.id.menuManageSources:
Log.i(TAG, "onOptionsItemSelected: managing sources");
break;
}
return true;
}
// this on is called everytime after the optionsmenu is disappeared
#Override
public void onOptionsMenuClosed(Menu menu) {
Log.d(TAG,
"onOptionsMenuClosed: called everytime after the OptionsMenu is disappeared");
Log.i(TAG, "Hey Jackson, I'm disappeared");
}
}
xml file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/itemStatus" android:title="#string/titleStatus"
android:icon="#android:drawable/ic_menu_edit"></item>
<item android:title="#string/titleTimeline" android:id="#+id/itemTimeline"
android:icon="#android:drawable/ic_menu_sort_by_size"></item>
<item android:id="#+id/itemPrefs" android:title="#string/titlePrefs"
android:icon="#android:drawable/ic_menu_preferences"></item>
<item android:icon="#android:drawable/ic_menu_delete"
android:title="#string/titlePurge" android:id="#+id/itemPurge"></item>
<item android:title="#string/titleRefresh" android:id="#+id/itemRefresh"
android:icon="#android:drawable/ic_menu_rotate"></item>
</menu>
there are some tricks:
if You have multiple activities with same OptionsMenu:
1. Create a base activity with OptionsMenu
2. Inherit this base activity on other activies, that handles same OptionsMenu
Result:
same Menu on multiple activities
Regards, Galymzhan Sh

Same Title Bar but different View below it in Android?

In one of my Android Application I need to keep the title bar same but the view that is shown in the rest of the screen changes. So, I have taken different Activity for all the views that I need to show and set the title bar in every Activities onCreate method.
Now, the problem is that I have a button in the title bar and need to perform certain action on its click event. Writing the same event handling code in every Activity class is very cumbersome. Is there any other way out that whenever there is a click event on that button of the title bar then we can have the same functionality without writing the same code in all the Activity classes.
Can we use ViewGroup for that? I don't have much idea about ViewGroup. Is that possible with ViewGroup?
If anyone knows the solution then please let me know.
Thanks & Regards
Sunil
If you are sharing view elements and functionality amongst several classes extending Activity, you might want to consider making a common superclass to handle this overlap.
The best solution is to keep a base activity like this.
public class HeaderBaseActivity extends AppCompatActivity{
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
mAppPreferences = AppUtil.getAppPreferences(this);
item_patients = menu.findItem(R.id.item_patients);
setBatchCountOnMenu(0);
RealmConfiguration realmConfig = new RealmConfiguration.Builder(this).build();
mRealm = Realm.getInstance(realmConfig);
mDotor = new Gson().fromJson(mAppPreferences.getString(Constants.SETTINGS_OBJ_DOCTOR, ""), Doctor.class);
mAppPreferences = AppUtil.getAppPreferences(this);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_logout:
/* DialogUtility.showShortToast(this, " Main manu Action Logout");*/
SharedPreferences.Editor Editor = mAppPreferences.edit();
Editor.putBoolean(Constants.SETTINGS_IS_LOGGED_IN, false);
Editor.apply();
clearRealmDB();
Intent loginIntent = new Intent(HeaderBaseActivity.this, LoginActivity.class);
loginIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(loginIntent);
finish();
break;
case R.id.item_patients:
System.out.println("current activity "+getApplicationContext());
Intent mPatientListIntent = new Intent(HeaderBaseActivity.this, PatientSummaryInfoActivity.class);
mPatientListIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(mPatientListIntent);
break;
case R.id.action_doctor_profile:
openDialogOfDoctorProfile();
break;
}
return super.onOptionsItemSelected(item);
}
}
Your other activities can extend the above activity like this:
public class MainActivity extends HeaderBaseActivity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
}
}

Categories

Resources