Basically what I am trying to do is open this testing menu (*#*#4636*#*#) via an app that I am making using Android Studio
I will leave you some screenshots so you know what I am talking about
I have the code that opens the app, but I am missing the package name and/or the activity name that will cause this menu to show up.
Code:
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.chartcross.gpstest"); // This launches GPS test app, I need to launch the testing menu
startActivity(launchIntent);
Thank you! :good:
Try this:
Code:
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:*#*#4636#*#*"));
startActivity(intent);
or
Code:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.TestingSettings");
startActivity(intent);
@mmdeveloper said:
Try this:
Code:
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:*#*#4636#*#*"));
startActivity(intent);
or
Code:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.TestingSettings");
startActivity(intent);
Click to expand...
Click to collapse
Thank you very much, the second one worked fine :good:
When the testing app starts it opens this menu:
Instead, I want it to open directly this menu:
That activity is called com.android.settings.TestingSettingsBroadcastReceiver, but when I do this:
Code:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.TestingSettingsBroadcastReceiver");
startActivity(intent);
The app just crashes with this error:
Code:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.feche.manual3gtoggle/com.feche.manual3gtoggle.Toggle3G}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.settings/com.android.settings.TestingSettingsBroadcastReceiver}; have you declared this activity in your AndroidManifest.xml?
Any idea of why? It says something that I should add to AndroidManifest.xml but since I am new to this I really don't understand to what it reffers. Thanks
EDIT:
Nevermind, I just found out that is called com.android.settings.RadioInfo instead of com.android.settings.TestingSettingsBroadcastReceiver, thanks anyways :highfive:
For your future reference,
Every class which extends activity or fragmentactivity or app combat activity etc.
Then you need to declare that particular class in your AndroidManifest.xml
mantlabs said:
Try this:
Code:
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:*#*#4636#*#*"));
startActivity(intent);
or
Code:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.TestingSettings");
startActivity(intent);
Click to expand...
Click to collapse
above code is not working in my sample do i need to add any permissions in Manifest file can you please help in this thing
sujith.e said:
above code is not working in my sample do i need to add any permissions in Manifest file can you please help in this thing
Click to expand...
Click to collapse
What Android version are you trying? This post was almost 6 years ago.
Related
I have the following two classes:
Code:
public class filechooser extends ListActivity{
private File f;
private fileArrayAdapter adapter;
public filechooser(File f2){
f = f2;
}
public void fill(){
......
adapter = new fileArrayAdapter(this, R.layout.file_view, dir); //get problems
this.setListAdapter(adapter);
}
}
and the other class
Code:
public class fileArrayAdapter extends ArrayAdapter<fc_option>{
private Context c;
private int id;
private List<fc_option>items;
public fileArrayAdapter(Context context, int textViewResourceId, List<fc_option> obj){
[B]super(context, textViewResourceId, obj);[/B]
c = context;
id = textViewResourceId;
items = obj;
}
public fc_option getItem(int i){
return items.get(i);
}
I checked that when the code is running to super(context...), a run time error occurs. But I have no idea what the problem is, could anyone help, please?
Thank you.
Why don't you say what kind of exception the runtime error is?
sorry, I dont know how to check. Where could I get the error?
I dont know how to use the eclipse debugger..
You need to open the DDMS perspective in eclipse and then look at the logcat log while your app is running. When it hits a runtime error there will be a load of red text in the log which will tell you what kind of exception it it and which line of code it comes from.
Thank you.
I got the following error
11-14 02:42:36.502: ERROR/AndroidRuntime(249): Uncaught handler: thread main exiting due to uncaught exception
11-14 02:42:36.522: ERROR/AndroidRuntime(249): java.lang.IllegalStateException: System services not available to Activities before onCreate()
Did I miss catching the exception in some code?
So in my toolkit, id like to design an activity where I could point it towards certain lines in the build.prop to allow a user to easily toggle, for instance this line
qemu.hw.mainkeys=0
So, in the layout xml, lets say it had "Enable Nav Bar" and a "Toggle Button" for on/off
Where would i start in developing such a feature?
You create a ToggleButton and whenever it is clicked, you change the line.
What is your problem?
nikwen said:
You create a ToggleButton and whenever it is clicked, you change the line.
What is your problem?
Click to expand...
Click to collapse
My concerns are wouldnt I need to add ro permissions on the prop before toggling and a reboot action to apply
I think your device needs to be rooted to be able to write to the build.prop file. You do not need root access to read it though
I'm from mobile and i can't post some code but i will give you some hints
To edit build.prop programmatically first you ne ed to be rooted then you can use the shell command "sed" to exchange values. Take a look at AOKP settings source on github and look for density changer class
If you want to import various build properties you can use fileinputstream and read the file line by line then let the app create listview custom items for every line in the file (you need a custom adapter) .
Sorry if this post it's not really useful but i will edit this when at PC
Sent from my HTC One X using Tapatalk 4 Beta
Thankyou for the tip! The answer might of been infront of my face possibly...
Sent from my 9300 using xda app-developers app
xcesco89 said:
I'm from mobile and i can't post some code but i will give you some hints
To edit build.prop programmatically first you ne ed to be rooted then you can use the shell command "sed" to exchange values. Take a look at AOKP settings source on github and look for density changer class
If you want to import various build properties you can use fileinputstream and read the file line by line then let the app create listview custom items for every line in the file (you need a custom adapter) .
Sorry if this post it's not really useful but i will edit this when at PC
Sent from my HTC One X using Tapatalk 4 Beta
Click to expand...
Click to collapse
I Wrote something up but I keep getting force closes "Not a java code monkey yet, still learning" and Ill post here what I have when I get to my pc later. Maybe you can see what Im missing or did wrong. What I did is I have a preference screen similiar to AOKP density changer class. What Im going for is a PreferenceList that you click and your values are Enable or Disabled and another preference to reboot to apply settings. Im wanting to allow the user to enable and disable the Navigation Bar by toggling it through the build.prop. If this works, I want to add more toggles custom values like change your phone model, Screen Density, build number, ect; but figured Id start with something simpler first and see if it works.
Sent from my Alps9300 using Tapatalk
Nx Biotic said:
I Wrote something up but I keep getting force closes "Not a java code monkey yet, still learning" and Ill post here what I have when I get to my pc later. Maybe you can see what Im missing or did wrong. What I did is I have a preference screen similiar to AOKP density changer class. What Im going for is a PreferenceList that you click and your values are Enable or Disabled and another preference to reboot to apply settings. Im wanting to allow the user to enable and disable the Navigation Bar by toggling it through the build.prop. If this works, I want to add more toggles custom values like change your phone model, Screen Density, build number, ect; but figured Id start with something simpler first and see if it works.
Sent from my Alps9300 using Tapatalk
Click to expand...
Click to collapse
this is the method you need:
Code:
private void setLcdDensity(int newDensity) {
Helpers.getMount("rw");
new CMDProcessor().su.runWaitFor("busybox sed -i 's|ro.sf.lcd_density=.*|"
+ "ro.sf.lcd_density" + "=" + newDensity + "|' " + "/system/build.prop");
Helpers.getMount("ro");
}
( method took from here : https://github.com/TeamBAKED/packag...aked/romcontrol/fragments/DensityChanger.java )
newDensity is the int/string you let the user set ( you can use a seekbar or a dialog or what you prefer)
you have also CMDProcessor().su.runWaitFor : just use the classes you can find here : https://github.com/TeamBAKED/packag...11bca71808c9143/src/com/baked/romcontrol/util
just add these classes in your project ( these are to simplify your life when you need to use android terminal [ remember to give credits on your app! ] )
Now, you can use various types of views and methods to show to the user all the available props:
- manually add every view for every line in your build.prop ( this will probably limit the compatibility with other devices and make your app "laggy" due to "gazilions" views )
- use a blank linearLayout and inflate a "row view" for every line in build.prop:
read file line by line and import every line in an ArrayList:
Code:
ArrayList<String> Tokens = new ArrayList<String>();
try {
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("/system/build.prop");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
// Read File Line By Line
while ((strLine = br.readLine()) != null) {
strLine = strLine.trim();
if ((strLine.length()!=0)) {
String[] names = strLine.split("\\s+");
Tokens.add(names[0]);
}
}
for (String s : Tokens) {
//System.out.println(s);
//Log.d("NNNNNNNNNNNNNNNNNN", s);
}
// Close the input stream
in.close();
} catch (Exception e) {// Catch exception if any
System.err.println("Error: " + e.getMessage());
}
names = new String[Tokens.size()-1];
names = Tokens.toArray(names);
ArrayList<String> value = new ArrayList<String>();
try {
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("/sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
// Read File Line By Line
while ((strLine = br.readLine()) != null) {
strLine = strLine.trim();
if ((strLine.length()!=0)) {
String[] val = strLine.split("\\s+");
value.add(val[1]);
}
}
for (String s : value) {
//System.out.println(s);
//Log.d("NNNNNNNNNNNNNNNNNN", s);
}
// Close the input stream
in.close();
} catch (Exception e) {// Catch exception if any
System.err.println("Error: " + e.getMessage());
}
values = new String[value.size()-1];
values = value.toArray(values);
LineNumberReader lnr = null;
try {
lnr = new LineNumberReader(new FileReader(new File("/sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table")));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
lnr.skip(Long.MAX_VALUE);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int num = lnr.getLineNumber();
Log.d("LINES", ""+num);
int i = 0;
//now inflate a specific view for every line
// you can also filter every item for example by reading the string and inflating a different layout using an if statement
for (String s : names) {
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View v = inflater.inflate(R.layout.uvrow, null, true);
TextView text0 = (TextView) v.findViewById(R.id.text0);
ImageButton back0 = (ImageButton) v.findViewById(R.id.back0);
final EditText edit0 = (EditText) v.findViewById(R.id.edit0);
ImageButton fwd0 = (ImageButton) v.findViewById(R.id.fwd0);
text0.setText(s);
parentGroup.addView(v);
edit0.setText(values[i]);
/*
* if you need to set listeners and actions insert them inside this loop!
*/
}
if you need more informations, take a look at my code on github ( was my first "really useful" app ): https://github.com/cesco89/CustomSettings/blob/master/src/com/cesco/customsettings/UVTable.java
it's not perfect, could be tricky, but i can't post all the code here
This Is what I put together...Excuse any errors in java...Im new at this. When I start this fragment, I get a force close. What did I do?
Code:
package com.bionx.res.catalyst;
import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment;
import com.bionx.res.R;
import com.bionx.res.helpers.CMDProcessor;
import com.bionx.res.helpers.Helpers;
public abstract class Navbar extends PreferenceFragment implements OnPreferenceChangeListener {
Preference mReboot;
ListPreference mStockValue;
int newStockValue;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.navbarchanger);
mStockValue = (ListPreference) findPreference("stock_value");
mStockValue.setOnPreferenceChangeListener(this);
mReboot = findPreference("reboot");
}
public boolean onPreference(Preference preference) {
if (preference == mReboot) {
PowerManager pm = (PowerManager) getActivity()
.getSystemService(Context.POWER_SERVICE);
pm.reboot("Setting Navbar");
}
return false;
}
[user=439709]@override[/user]
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mStockValue) {
newStockValue = Integer.parseInt((String) newValue);
setNavbarValue(newStockValue);
mStockValue.setSummary(getResources().getString(R.string.navbar_changer) + newStockValue);
return true;
}
return false;
}
private void setNavbarValue(int newNavbar) {
Helpers.getMount("rw");
new CMDProcessor().su.runWaitFor("busybox sed -i 's|qemu.hw.mainkeys=.*|"
+ "qemu.hw.mainkeys" + "=" + newNavbar + "|' " + "/system/build.prop");
Helpers.getMount("ro");
}
}
Code:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<Preference
android:title="System Properties"
android:summary="User System Tweaks" />
<ListPreference
android:entries="@array/navbar_stock_entries"
android:entryValues="@array/navbar_stock_values"
android:key="stock_value"
android:title="NavBar Enabler"
android:summary="Toggle the system navbar" />
<Preference
android:key="reboot"
android:title="Reboot"
android:summary="Applies tweaks and reboots" />
</PreferenceScreen>
Where I launch the fragment.
Code:
...
<header
android:fragment="com.bionx.res.catalyst.Navbar"
android:icon="@drawable/ic_changelog"
android:title="System Ui Tweaks"
android:summary="Developers soup of the week" />
...
Nx Biotic said:
This Is what I put together...Excuse any errors in java...Im new at this. When I start this fragment, I get a force close. What did I do?
Code:
package com.bionx.res.catalyst;
import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment;
import com.bionx.res.R;
import com.bionx.res.helpers.CMDProcessor;
import com.bionx.res.helpers.Helpers;
public abstract class Navbar extends PreferenceFragment implements OnPreferenceChangeListener {
Preference mReboot;
ListPreference mStockValue;
int newStockValue;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.navbarchanger);
mStockValue = (ListPreference) findPreference("stock_value");
mStockValue.setOnPreferenceChangeListener(this);
mReboot = findPreference("reboot");
}
public boolean onPreference(Preference preference) {
if (preference == mReboot) {
PowerManager pm = (PowerManager) getActivity()
.getSystemService(Context.POWER_SERVICE);
pm.reboot("Setting Navbar");
}
return false;
}
[user=439709]@override[/user]
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mStockValue) {
newStockValue = Integer.parseInt((String) newValue);
setNavbarValue(newStockValue);
mStockValue.setSummary(getResources().getString(R.string.navbar_changer) + newStockValue);
return true;
}
return false;
}
private void setNavbarValue(int newNavbar) {
Helpers.getMount("rw");
new CMDProcessor().su.runWaitFor("busybox sed -i 's|qemu.hw.mainkeys=.*|"
+ "qemu.hw.mainkeys" + "=" + newNavbar + "|' " + "/system/build.prop");
Helpers.getMount("ro");
}
}
Code:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<Preference
android:title="System Properties"
android:summary="User System Tweaks" />
<ListPreference
android:entries="@array/navbar_stock_entries"
android:entryValues="@array/navbar_stock_values"
android:key="stock_value"
android:title="NavBar Enabler"
android:summary="Toggle the system navbar" />
<Preference
android:key="reboot"
android:title="Reboot"
android:summary="Applies tweaks and reboots" />
</PreferenceScreen>
Where I launch the fragment.
Code:
...
<header
android:fragment="com.bionx.res.catalyst.Navbar"
android:icon="@drawable/ic_changelog"
android:title="System Ui Tweaks"
android:summary="Developers soup of the week" />
...
Click to expand...
Click to collapse
please post the Log you get on Eclipse !
the log will tell you exactly where the error is
I've published an app in Play Store (https://play.google.com/store/apps/details?id=com.pikotech.bo2guide), so I've seen the number of updates is so slow, and this is a problem because I release a lot of them. I would show a "New updated available" dialog that redirect the user to my app's PlayStore tab. To do this I've thought a system to parse the source(Command+Alt+U in OS X Chrome) of my app's PlayStore Web Page. The info that stores my app's version available is this
Version Name:
Code:
itemprop="softwareVersion"> 1.0.7
How to compare on of these values with the version installed of the app? If the content parsed will be higher of the version installed, I will show a dialog with "new updated avaialble", that can redirect the user on PlayStore to updated my app.
Or there is a simple method or a library that show new "New update available" dialog
This should help you get your application version:
http://stackoverflow.com/questions/6593592/get-application-version-programatically-in-android
zalez said:
This should help you get your application version:
http://stackoverflow.com/questions/6593592/get-application-version-programatically-in-android
Click to expand...
Click to collapse
Thanks,
this is the second part of my desired dialog Code.
The first part is how to get versionName (or versionCode) off the App's Google Play Store Web Page.
rampo said:
Thanks,
this is the second part of my desired dialog Code.
The first part is how to get versionName (or versionCode) off the App's Google Play Store Web Page.
Click to expand...
Click to collapse
This is how to get the source of the Google Play page:
Code:
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 4000);
HttpConnectionParams.setSoTimeout(params, 5000);
HttpClient client = new DefaultHttpClient(params);
HttpGet request = new HttpGet("https://play.google.com/store/apps/details?id=" + pkg); //your package goes here
HttpResponse response = client.execute(request);
InputStream is = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line = null;
while((line = reader.readLine()) != null) {
//do something with the information
Log.d("line", line);
}
GitHub library coming soon
nikwen said:
This is how to get the source of the Google Play page:
Code:
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 4000);
HttpConnectionParams.setSoTimeout(params, 5000);
HttpClient client = new DefaultHttpClient(params);
HttpGet request = new HttpGet("https://play.google.com/store/apps/details?id=" + pkg); //your package goes here
HttpResponse response = client.execute(request);
InputStream is = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line = null;
while((line = reader.readLine()) != null) {
//do something with the information
Log.d("line", line);
}
Click to expand...
Click to collapse
Thanks man. I'm creating a Library to show the dialog. Follow me on GitHub.
rampo said:
Thanks man. I'm creating a Library to show the dialog. Follow me on GitHub.
Click to expand...
Click to collapse
Welcome.
You might also be interested in this library: https://github.com/MartinvanZ/Inscription
(You could fork it.)
nikwen said:
Welcome.
You might also be interested in this library: https://github.com/MartinvanZ/Inscription
(You could fork it.)
Click to expand...
Click to collapse
I already use it in my commercial app.
It's a Changelog library. I'll instead implement Styled Dialogs for the New Updated Available dialog.
rampo said:
I already use it in my commercial app.
It's a Changelog library. I'll instead implement Styled Dialogs for the New Updated Available dialog.
Click to expand...
Click to collapse
Ah, sorry. Forgot that. :silly:
Published today:
Update Checker
hello friends i'm new here and sorry for my question i'm big beginner and an autolearner.
i'm doing an app for android basicaly mock up. and i created a projectwith drawer menu and menu item are stocked in string not in array.
when i run it if i click on an item the number of row of the item appear in the mainactivity.xml what i realy want is to start a new activity here is my code i hope i can get help here,
Code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
}
@Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
.commit();
}
public void onSectionAttached(int number) {
switch (number) {
case 1:
mTitle = getString(R.string.title_section1);
break;
case 2:
mTitle = getString(R.string.title_section2);
break;
case 3:
mTitle = getString(R.string.title_section3);
break;
canempire said:
hello friends i'm new here and sorry for my question i'm big beginner and an autolearner.
i'm doing an app for android basicaly mock up. and i created a projectwith drawer menu and menu item are stocked in string not in array.
when i run it if i click on an item the number of row of the item appear in the mainactivity.xml what i realy want is to start a new activity here is my code i hope i can get help here,
Click to expand...
Click to collapse
Modify your onNavigationDrawerItemSelected method as follows
PHP:
@Override
public void onNavigationDrawerItemSelected(int position) {
switch (position) {
case 0:
//For loading a fragment
Fragment yourfragment = new Yourfragment();
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
,beginTransaction();
fragmentTransaction.replace(R.id.container, yourfragment );
onSectionAttached(0);
fragmentTransaction.commit();
break;
case 1:
//To start a new activity
Intent intent = new Intent(this,destination.class);
startActivity(intent);
break;
case 2:
//To do something else like a dialog or a toast
Toast.maketext(context,"Sample Toast",Tosat.LENGTH_LONG).show();
break;
}
}
hello friend thank you very much for your response i edited my code like this
Code:
@Override
public void onNavigationDrawerItemSelected(int position) {
switch (position) {
case 0:
//For loading a fragment
FragmentVue1 FragmentVue1 = new FragmentVue1();
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentManager fragmentTransaction = fragmentManager;
beginTransaction();
fragmentTransaction.replace(R.id.container, FragmentVue1 );
onSectionAttached(0);
fragmentTransaction.commit();
break;
case 1:
//To start a new activity
Intent intent = new Intent(this,FragmentVue1.class);
startActivity.intent();
break;
FragmentVue1 is the name of my activity 1 and the activity load the layout, the code i posted up is little edited than than that you gave me on up reply, because eclipse stress it that suggested me some code to change for exemple
HTML:
Fragment Frgment1 = new FragmentVue1();
raplace in this code is still empty and eclipse ask me to Add cast method receiver
HTML:
fragmentTransaction.replace(R.id.container, FragmentVue1 );
and in this code too fro commit
HTML:
fragmentTransaction.commit();
for this code
HTML:
startActivity.intent();
eclipse is asking me to crete local variable startActivity, create field starActivity,create parameter startActivity create class, and constant .
i'm sorry if i bring to difficult place i really need it to change layout(fragment) to start it just for show a mock up
canempire said:
hello friend thank you very much for your response i edited my code like this
Code:
@Override
public void onNavigationDrawerItemSelected(int position) {
switch (position) {
case 0:
//For loading a fragment
FragmentVue1 FragmentVue1 = new FragmentVue1();
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentManager fragmentTransaction = fragmentManager;
beginTransaction();
fragmentTransaction.replace(R.id.container, FragmentVue1 );
onSectionAttached(0);
fragmentTransaction.commit();
break;
case 1:
//To start a new activity
Intent intent = new Intent(this,FragmentVue1.class);
startActivity.intent();
break;
FragmentVue1 is the name of my activity 1 and the activity load the layout, the code i posted up is little edited than than that you gave me on up reply, because eclipse stress it that suggested me some code to change for exemple
HTML:
Fragment Frgment1 = new FragmentVue1();
raplace in this code is still empty and eclipse ask me to Add cast method receiver
HTML:
fragmentTransaction.replace(R.id.container, FragmentVue1 );
and in this code too fro commit
HTML:
fragmentTransaction.commit();
for this code
HTML:
startActivity.intent();
eclipse is asking me to crete local variable startActivity, create field starActivity,create parameter startActivity create class, and constant .
i'm sorry if i bring to difficult place i really need it to change layout(fragment) to start it just for show a mock up
Click to expand...
Click to collapse
I guess using
"startActivity(intent);"
instead of
"startActivity.intent();" will please eclipse
and not to mention will solve the issue
I bet u didn google that
Sent from my GT-S5302 using Tapatalk 2
canempire said:
hello friend thank you very much for your response i edited my code like this
Code:
@Override
public void onNavigationDrawerItemSelected(int position) {
switch (position) {
case 0:
//For loading a fragment
FragmentVue1 FragmentVue1 = new FragmentVue1();
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentManager fragmentTransaction = fragmentManager;
beginTransaction();
fragmentTransaction.replace(R.id.container, FragmentVue1 );
onSectionAttached(0);
fragmentTransaction.commit();
break;
case 1:
//To start a new activity
Intent intent = new Intent(this,FragmentVue1.class);
startActivity.intent();
break;
FragmentVue1 is the name of my activity 1 and the activity load the layout, the code i posted up is little edited than than that you gave me on up reply, because eclipse stress it that suggested me some code to change for exemple
HTML:
Fragment Frgment1 = new FragmentVue1();
raplace in this code is still empty and eclipse ask me to Add cast method receiver
HTML:
fragmentTransaction.replace(R.id.container, FragmentVue1 );
and in this code too fro commit
HTML:
fragmentTransaction.commit();
for this code
HTML:
startActivity.intent();
eclipse is asking me to crete local variable startActivity, create field starActivity,create parameter startActivity create class, and constant .
i'm sorry if i bring to difficult place i really need it to change layout(fragment) to start it just for show a mock up
Click to expand...
Click to collapse
you don't need to use any code present in case 0 if you are not loading a fragment. I just wrote that to make sure you know the difference between starting an activity and a fragment.
If you just want too start an activity just use what is inside case 1.
and as @sak-venom1997 said it should be startActivity(intent) instead of startActivity.intent(). My bad (i am a confused person )
so suppose FragmentVue1 is your activity's name and you want to open it on clicking nth item of navigation drawer use
PHP:
case n:
Intent intent = new Intent(this,FragmentVue1.class);
startActivity(intent);
break;
gh0stslayer said:
you don't need to use any code present in case 0 if you are not loading a fragment. I just wrote that to make sure you know the difference between starting an activity and a fragment.
If you just want too start an activity just use what is inside case 1.
and as @sak-venom1997 said it should be startActivity(intent) instead of startActivity.intent(). My bad (i am a confused person )
so suppose FragmentVue1 is your activity's name and you want to open it on clicking nth item of navigation drawer use
PHP:
case n:
Intent intent = new Intent(this,FragmentVue1.class);
startActivity(intent);
break;
Click to expand...
Click to collapse
thank you very much for yours reply both are usefully @sak-venom1997
yes FragmentVue1 is my activity it load a layout the reality is i know difference between Activity and Layout but no the both with Fragment.
now it working but the MainActivity is empty when i start the app and i find a warning in code below case 1 break i copied the warning in message in the below code in the line of warning
PHP:
private void onSectionAttached(int i) {
// TODO Auto-generated method stub
}
private void beginTransaction() { // WARNING: The method beginTransaction() from the type MainActivity is never used locally
// TODO Auto-generated method stub
}
private FragmentManager getSupportFragmentManager() {//WARNING:The method getSupportFragmentManager() from the type MainActivity is never used locally
// TODO Auto-generated method stub
return null;
}
canempire said:
thank you very much for yours reply both are usefully @sak-venom1997
yes FragmentVue1 is my activity it load a layout the reality is i know difference between Activity and Layout but no the both with Fragment.
now it working but the MainActivity is empty when i start the app and i find a warning in code below case 1 break i copied the warning in message in the below code in the line of warning
PHP:
private void onSectionAttached(int i) {
// TODO Auto-generated method stub
}
private void beginTransaction() { // WARNING: The method beginTransaction() from the type MainActivity is never used locally
// TODO Auto-generated method stub
}
private FragmentManager getSupportFragmentManager() {//WARNING:The method getSupportFragmentManager() from the type MainActivity is never used locally
// TODO Auto-generated method stub
return null;
}
Click to expand...
Click to collapse
If i understand you the right way, you are extending Fragment. In this case you are overriding some methods, but dont modify them. How did you get the code? Via the eclipse menu saying "override/implement methods"? Or did you copy the code from somewhere? If you really need to keep the code, i think you have to call super in the method.
Gesendet von meinem SM-N9005 mit Tapatalk
GalaxyInABox said:
If i understand you the right way, you are extending Fragment. In this case you are overriding some methods, but dont modify them. How did you get the code? Via the eclipse menu saying "override/implement methods"? Or did you copy the code from somewhere? If you really need to keep the code, i think you have to call super in the method.
Gesendet von meinem SM-N9005 mit Tapatalk
Click to expand...
Click to collapse
the code is generated when i created the project it is a part of MainActivity.java code it didn't have warning message before i add
PHP:
case 1:
//To start a new activity
Intent intent = new Intent(this,FragmentVue1.class);
startActivity(intent);
break;
but why the main activity (fragment) is empty?? now :crying:
can someone help me please???
FragmentVue1 isi an Activity it is FragmentVue1.java and the code is
PHP:
package com.projectmockup.cypruscityguide;
import com.projectmockup.cypruscityguide.R;
import android.app.Activity;
import android.os.Bundle;
public class FragmentVue1 extends Activity{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.hotel);
}
}
please help when i start the application the Fragment_main.xml is empty but before i use this code in MainActivity
PHP:
case 1:
//To start a new activity
Intent intent = new Intent(this,FragmentVue1.class);
startActivity(intent);
break;
the content of Fragment_main.xml was visible
i check below in the MainActivity and i found this code with alert
PHP:
private void beginTransaction() { // WARNING: The method beginTransaction() from the type MainActivity is never used locally
// TODO Auto-generated method stub
}
private FragmentManager getSupportFragmentManager() {//WARNING:The method getSupportFragmentManager() from the type MainActivity is never used locally
// TODO Auto-generated method stub
return null;
}
canempire said:
FragmentVue1 isi an Activity it is FragmentVue1.java and the code is
PHP:
package com.projectmockup.cypruscityguide;
import com.projectmockup.cypruscityguide.R;
import android.app.Activity;
import android.os.Bundle;
public class FragmentVue1 extends Activity{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.hotel);
}
}
please help when i start the application the Fragment_main.xml is empty but before i use this code in MainActivity
PHP:
case 1:
//To start a new activity
Intent intent = new Intent(this,FragmentVue1.class);
startActivity(intent);
break;
the content of Fragment_main.xml was visible
i check below in the MainActivity and i found this code with alert
PHP:
private void beginTransaction() { // WARNING: The method beginTransaction() from the type MainActivity is never used locally
// TODO Auto-generated method stub
}
private FragmentManager getSupportFragmentManager() {//WARNING:The method getSupportFragmentManager() from the type MainActivity is never used locally
// TODO Auto-generated method stub
return null;
}
Click to expand...
Click to collapse
You don't need to add these lines, they are for opening a fragment. I just provided them to help you know how to open a fragment from navigation drawer.
Hello!
I'm trying to develop my first game in java for android(actually, the game itself is practically done), but now I decided to add admob ads.
The problem is, that when I add to my class "extends Activity", which is neccessary, I get an error "Can't create handler inside thread that has not called Looper.prepare()".
Here is full error:
Code:
06-25 08:55:09.523: E/AndroidRuntime(583): FATAL EXCEPTION: GLThread 5679
06-25 08:55:09.523: E/AndroidRuntime(583): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
06-25 08:55:09.523: E/AndroidRuntime(583): at android.os.Handler.<init>(Handler.java:121)
06-25 08:55:09.523: E/AndroidRuntime(583): at android.app.Activity.<init>(Activity.java:735)
06-25 08:55:09.523: E/AndroidRuntime(583): at com.my.game.GameScreen.<init>(GameScreen.java:67)
06-25 08:55:09.523: E/AndroidRuntime(583): at com.my.game.MainMenuScreen.render(MainMenuScreen.java:157)
06-25 08:55:09.523: E/AndroidRuntime(583): at com.badlogic.gdx.Game.render(Game.java:46)
06-25 08:55:09.523: E/AndroidRuntime(583): at com.my.game.render(MyGame.java:74)
06-25 08:55:09.523: E/AndroidRuntime(583): at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:422)
06-25 08:55:09.523: E/AndroidRuntime(583): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1462)
06-25 08:55:09.523: E/AndroidRuntime(583): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
I read that this error is something with background threads, which I'm not using.
In GameScreen the error occurs here:
Code:
public GameScreen(final MyGame gam) {
In MainMenuScreen:
Code:
game.setScreen(new GameScreen(game));
When I remove "extends Activity" from here(in GameScreen):
Code:
public class GameScreen extends Activity implements Screen {
final MyGame game;
//Defining some textures and variables here
public GameScreen(final MyGame gam) {
this.game = gam;
//some stuff here
if(MyGame.versionStatus == 0)
{
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("TEST_DEVICE_ID")
.build();
adView.loadAd(adRequest);
}
//more stuff here
}
...the problem disappears, but ads don't show
Can you please help me solve it?
You need to add this
runOnUiThread(new Runnable() { public void run() {
// add your stuff here
} });
Hm... I'm not quite sure where exactly should I put it...
I tried that way:
Code:
public GameScreen(final MyGame gam) {
this.game = gam;
runOnUiThread(new Runnable() { public void run() {
//some stuff here
if(MyGame.versionStatus == 0)
{
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("TEST_DEVICE_ID")
.build();
adView.loadAd(adRequest);
}
//more stuff here
}});
}
But it didn't work :/
Still the same error...
urban07 said:
Hm... I'm not quite sure where exactly should I put it...
I tried that way:
Code:
public GameScreen(final MyGame gam) {
this.game = gam;
runOnUiThread(new Runnable() { public void run() {
//some stuff here
if(MyGame.versionStatus == 0)
{
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("TEST_DEVICE_ID")
.build();
adView.loadAd(adRequest);
}
//more stuff here
}});
}
But it didn't work :/
Still the same error...
Click to expand...
Click to collapse
Hello,
Maybe try using getApplicationContext() intead this here:
Code:
AdView adView = (AdView)this.findViewById(R.id.adView);
Try commenting your //some stuff
and see if you still have the problem.
Also, where is your onCreate() method? You should create the AdView there (you are extending an Activity). Create it inside the onCreate method after the setContentView with your xml.
If you still need help, feel free to ask
@mmdeveloper said:
Hello,
Maybe try using getApplicationContext() intead this here:
Code:
AdView adView = (AdView)this.findViewById(R.id.adView);
Try commenting your //some stuff
and see if you still have the problem.
Also, where is your onCreate() method? You should create the AdView there (you are extending an Activity). Create it inside the onCreate method after the setContentView with your xml.
If you still need help, feel free to ask
Click to expand...
Click to collapse
Oh, right... I forgot to say that I moved ad creating to onCreate method Instead of main method.
And how should I use getApplicationContext() in this case?
EDIT: Oh, and yes, when I put all my stuff into comment, I still get this error :/
I suppose I have a really dumb mistake somewhere in code that I can't find... But maybe it's something else.
However, when I remove "extends Activity", there is no error(as well as ads) so I think it is some little, invisible bug :<
Take a look here
I have no experience in libgdx, but it seems that you need to create a layout, create the libgdx View and the AdView and add both of them to the layout in your AndroidApplication
@mmdeveloper said:
Take a look here
I have no experience in libgdx, but it seems that you need to create a layout, create the libgdx View and the AdView and add both of them to the layout in your AndroidApplication
Click to expand...
Click to collapse
Hm... Thanks, I'll be sure to check it out
Maybe it'll help
EDIT:
I've moved all ads-connected commands to AndroidLauncher.java and removed "extends Activity" from GameScreen, and it seems to be working - in logcat, not on my phone
In logcat I can see info like:
06-26 15:41:09.165: I/Ads(25106): Starting ad request.
06-26 15:41:20.766: I/Ads(25106): Scheduling ad refresh 150000 milliseconds from now.
06-26 15:41:21.216: I/Ads(25106): Ad finished loading.
Click to expand...
Click to collapse
.... but then:
06-26 15:43:50.792: I/Ads(25106): Ad is not visible. Not refreshing ad.
06-26 15:43:50.792: I/Ads(25106): Scheduling ad refresh 60000 milliseconds from now.
06-26 15:44:50.791: I/Ads(25106): Ad is not visible. Not refreshing ad.
06-26 15:44:50.791: I/Ads(25106): Scheduling ad refresh 60000 milliseconds from now.
Click to expand...
Click to collapse
Ok, the ad is fully working now - somehow I figured it out, but thanks for a great trace - it really helped me