Has anyone been able to successfully implement the google Maps API on Glass? I am having an issue regarding the manifest xml file.
So, the problem arises when I include:
Code:
<uses-library android:name="com.google.android.maps"/>
in the Manifest file. I get the error:
Code:
Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY
So if I remove the line in the manifest, the application will crash upon getting to the map activity which reads:
Main_Activity if needed:
Code:
package com.example.mapping;
import android.app.Activity;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.*;
import android.app.Activity;
import android.os.Bundle;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MapActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
// Get a handle to the Map Fragment
GoogleMap map = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.mapView)).getMap();
LatLng war = new LatLng(-33.867, 151.206);
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(war, 13));
map.addMarker(new MarkerOptions()
.title("Mission Drop Zone")
.snippet("Navigate to Enemy Hideout")
.position(war));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.map, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.mapView) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_map, container,
false);
return rootView;
}
}
}
If you require my AndroidManifest let me know. It is not letting me post it because it thinks it is a link to an external page.
Thanks for any help
Solved.
Turns out that glass has limited or no integration with google play services, as a result google maps api is irrelevant. I have solved my issue by integrating MapQuest rather than google maps, and have found it to be much easier to implement into a glass app than trying to hack a maps api integration. Hope this helps anyone else that has had this issue.
I work at a casting company & sometimes have to calculate weights. I am building a simple app in android studio to do this & was hoping someone could help as im struggling. I have 3 user inputs set, but I want to take those inputs & run them through a calculation & the have the result displayed at the end. I want to set a button so when I have the 3 imputs & can click go, & the result gets displayed. This is my code at present.
Code:
package com.example.nealu.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onButtonClick(View V) {
EditText e1 = (EditText)findViewById(R.id.editText);
EditText e2 = (EditText)findViewById(R.id.editText2);
EditText e3 = (EditText)findViewById(R.id.editText3);
TextView t1 = (TextView) findViewById(R.id.textView);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
I think im going wrong on the edit text bit but I have searched around & tried taking bits out of code for a calculator, but I need to do a little more than 10*5 etc when working a weight of a casting out so need to take the input & run it through a formula.
Any help would be greatly appreciated.
Thanks.
Can anybody help me. I have developed a quiz app. At the end of the quiz the result activity must show up but the scores activity shows up. The scores activity only shows up when the scores button is selected on the MainActivity.
Quiz.java
Code:
package app.mobiledevicesecurity;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Quiz extends Activity
{
List<Question> questionList;
int score = 0;
int qid = 0;
Question currentQuest;
TextView txtQuestion, scored;
Button button1, button2, button3;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
QuizHelper db = new QuizHelper(this);
questionList = db.getAllQuestions();
currentQuest = questionList.get(qid);
txtQuestion = (TextView) findViewById(R.id.txtQuestion);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
scored = (TextView) findViewById(R.id.score);
setQuestionView();
button1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
getAnswer(button1.getText().toString());
}
});
button2.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
getAnswer(button2.getText().toString());
}
});
button3.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
getAnswer(button3.getText().toString());
}
});
}
public void getAnswer(String AnswerString)
{
if (currentQuest.getAnswer().equals(AnswerString))
{
score++;
scored.setText("Score : " + score);
}
else
{
Intent intent = new Intent(Quiz.this,
Result.class);
Bundle b = new Bundle();
b.putInt("score", score);
intent.putExtras(b);
startActivity(intent);
finish();
}
if (qid < questionList.size()) {
currentQuest = questionList.get(qid);
setQuestionView();
}
else
{
Intent intent = new Intent(Quiz.this,
Result.class);
Bundle b = new Bundle();
b.putInt("score", score);
intent.putExtras(b);
startActivity(intent);
finish();
}
}
private void setQuestionView()
{
txtQuestion.setText(currentQuest.getQuest());
button1.setText(currentQuest.getOption1());
button2.setText(currentQuest.getOption2());
button3.setText(currentQuest.getOption3());
qid++;
}
}
Result.java
Code:
package app.mobiledevicesecurity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Result extends Activity {
private static Button playbtn;
private static Button menubutton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
OnClickPlayButtonListener();
OnClickMenuButtonListener();
TextView textResult = (TextView) findViewById(R.id.textResult);
Bundle b = getIntent().getExtras();
int score = b.getInt("score");
textResult.setText("You scored" + " " + score + " for the quiz.");
Intent intent2 = new Intent(Result.this,
Scores.class);
Bundle bun = new Bundle();
bun.putInt("score", score);
intent2.putExtras(bun);
startActivity(intent2);
finish();
}
public void OnClickPlayButtonListener() {
playbtn = (Button) findViewById(R.id.btn);
playbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Quiz");
startActivity(intent);
}
}
);
}
public void OnClickMenuButtonListener() {
menubutton = (Button) findViewById(R.id.menubtn);
menubutton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
}
);
}
}
Scores.java
Code:
package app.mobiledevicesecurity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.content.Intent;
public class Scores extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scores);
TextView txtScore1 = (TextView) findViewById(R.id.txtScore1);
Bundle bun = getIntent().getExtras();
int score = bun.getInt("score");
txtScore1.setText("score:" + " " + score + " for the quiz.");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_scores, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
You are doing it wrong once you send the intent to start the Result Activity you have this code on your onCreate method:
Intent intent2 = new Intent(Result.this,
Scores.class);
Bundle bun = new Bundle();
bun.putInt("score", score);
intent2.putExtras(bun);
startActivity(intent2);
finish();
Which causes the Result activity to launch Scores and close Result
Please move this code out of your onCreate method and only call it when you need to!
Can you maybe help me with this. I am in the process of learning this application development. The score must be passed over to the Scores.java activity
This is what I tried but it do not work:
Result.java:
Code:
package app.mobiledevicesecurity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Result extends Activity {
private static Button playbtn;
private static Button menubutton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
OnClickPlayButtonListener();
OnClickMenuButtonListener();
TextView textResult = (TextView) findViewById(R.id.textResult);
Bundle b = getIntent().getExtras();
int score = b.getInt("score");
textResult.setText("You scored" + " " + score + " for the quiz.");
}
public void getScore()
{
Bundle b = getIntent().getExtras();
int score = b.getInt("score");
Intent intent2 = new Intent(Result.this,
Scores.class);
Bundle bun = new Bundle();
bun.putInt("score", score);
intent2.putExtras(bun);
startActivity(intent2);
finish();
}
public void OnClickPlayButtonListener() {
playbtn = (Button) findViewById(R.id.btn);
playbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Quiz");
startActivity(intent);
}
}
);
}
public void OnClickMenuButtonListener() {
menubutton = (Button) findViewById(R.id.menubtn);
menubutton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
}
);
}
}
Scores.java:
Code:
package app.mobiledevicesecurity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.content.Intent;
public class Scores extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scores);
Result res = new Result();
res.getScore();
TextView txtScore1 = (TextView) findViewById(R.id.txtScore1);
Bundle bun = getIntent().getExtras();
int score = bun.getInt("score");
txtScore1.setText("Last quiz score:" + " " + score + ".");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_scores, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Logcat:
Code:
09-08 20:47:51.143 1050-1050/app.mobiledevicesecurity E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: app.mobiledevicesecurity, PID: 1050
java.lang.RuntimeException: Unable to start activity ComponentInfo{app.mobiledevicesecurity/app.mobiledevicesecurity.Scores}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Bundle android.content.Intent.getExtras()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Bundle android.content.Intent.getExtras()' on a null object reference
at app.mobiledevicesecurity.Result.getScore(Result.java:31)
at app.mobiledevicesecurity.Scores.onCreate(Scores.java:18)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
************at android.app.ActivityThread.access$800(ActivityThread.java:151)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
************at android.os.Handler.dispatchMessage(Handler.java:102)
************at android.os.Looper.loop(Looper.java:135)
************at android.app.ActivityThread.main(ActivityThread.java:5257)
************at java.lang.reflect.Method.invoke(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:372)
************at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
This is wrong:
Result res = new Result();
res.getScore();
You are instantiating a new Result Activity which of course will have a null bundle because its not the same original Result Activity! What you are doing is the same has storing something on your box object named "box1" and then create a new box named "box2" and hope the object you stored will be on this new box!
If i understood correctly you want to show the result activity on the end of the quiz which you seemed to have working. And now you want to show the scores activity on press of a button on the main activity correct?
For that create a listener for the scores button on your Main Activity and add code to launch the Scores Activity with an intent where you pass the score. And then retrieve the bundle on your onCreate method on your ScoresActivity!
Can you maybe help me. I understand what you say but do not know how to do it.
Here is my main activity:
Code:
package app.mobiledevicesecurity;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
DatabaseHelper myDb;
private static Button readbtn;
private static Button quizbtn;
private static Button scoresbtn;
private static Button settingsbtn;
private static Button helpbtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myDb = new DatabaseHelper(this);
myDb.insertData();
OnClickReadButtonListener();
OnClickQuizButtonListener();
OnClickScoresButtonListener();
OnClickSettingsButtonListener();
OnClickHelpButtonListener();
}
public void OnClickReadButtonListener() {
readbtn = (Button) findViewById(R.id.readbutton);
readbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Read_Category");
startActivity(intent);
}
}
);
}
public void OnClickQuizButtonListener() {
quizbtn = (Button) findViewById(R.id.quizbutton);
quizbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Quiz");
startActivity(intent);
}
}
);
}
public void OnClickScoresButtonListener() {
scoresbtn = (Button) findViewById(R.id.scoresbutton);
scoresbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Scores");
startActivity(intent);
}
}
);
}
public void OnClickSettingsButtonListener() {
settingsbtn = (Button) findViewById(R.id.settingsbutton);
settingsbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Settings");
startActivity(intent);
}
}
);
}
public void OnClickHelpButtonListener() {
helpbtn = (Button) findViewById(R.id.helpbutton);
helpbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Help");
startActivity(intent);
}
}
);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Android Studio Eclipse - 1
I wonder if I 10 of the many many who call to use FDI. In my 20 years I have been on 1: MS Visual Studio, 2: Eclipse 3: STS (spring version of Eclipse), 4: RAD (IBM Websphere version eclipse commercially), 5: and now Netbeans 6: IntelliJ. The last one is my favorite by far far away. When you say many many Suppose you can take a little more to the list?
I let Visual Studio, because I. To Java instead of C ++ I went into eclipse, because that's what everyone else was doing, so I thought it was the only tool. I moved to STS because I look for alternatives, because eclipse was anything but stable, if you use EJB, Spring, Hibernate and one of the usual suspects in the application server where the debugging and publishing is a very regular basis. I had to use RAD, because a customer forced me. RAD6.2 and if the company that I was, I was probably still sued IBM as RAD6.2 is not even worth called a beta version. Since none of the releabed of the Eclipse-based IDE agony I have so hard to avoid, tried, I tried NetBeans. And things clarified. By integrating Maven was better than the eclipse. Honesty I admit liable that I never really know him so well, because professional, everyone was from Eclipse moving to IntelliJ, and I felt nothing but relief, where once swore. And so I joined the hive.
And I'm glad that I did it. IntelliJ is not perfect, but in my humble opinion, approaches. And if you have a problem, send an email to get these people and nine out of ten an answer within an hour. In the worst case within a day. At least in my case, as a paying customer.
I can not comment on Eclipse with the development of Android. I am pleased to talk about Java developers. For me, the Eclipse is a past long forgotten. Never again.
#Eclipse.
The Wrong Activity Shows Up Android Studio OK - we have it, you hate Eclipse. Personally, I find that the argument pointless. I do not like Eclipse, but I have many, many IDEs that were much worse used. Many developers - including myself - to live well with Eclipse for the daily work, either by choice or simply because we have to. Is set correctly Eclipse IDE a solid. Arguing that it fragile, even if the "stable" version of Android Studio still hangs / freezes it seems quite often rather disingenuous.
The other thing, this article makes completely useless is that they are all reasons (mostly true) for the reason why Android Studio is listed size. They forget to mention the various reasons - equally valid - because Android Studio is terrible (in the same way that we speak only bad problems with Eclipse, but none of its strengths).
Personally, I think Android Studio is practically dead, and is never more than a footnote in the history of the development of Android to be. One reason is due to the fact the unit - another is simply the inevitable course of development.
# 1 Android libraries
More than a year has passed since the AS was launched, and Google has not yet developed a sensible approach with Android libraries. Never tried above also brings a relatively simple configuration library? I tried to explain how to install the libraries in Android as for a new developer? There are zero relevant documents on the website and 50% of what it is out of date on the Internet - the remaining 50% is a terrible reading. Re usability of the code is the cornerstone of good development practices, but there are exercises that suggest in all seriousness physically copy code between projects in Android Studio. 1970 called ...
Inability of Google to provide a simple and intuitive code reuse mechanical - especially after (finally) it did work in Eclipse, IMO is the only major flaw Android Studio. At the same time makes it impossible for developers to have a choice (for example, everything is in Eclipse or AS) is just icing on the cake.
Even if - if you can just explain how multiple applications with multiple libraries Androdi (and some libraries use each other) set up, then I would see such a blog post. More than that - I would be very impressed. I tried it myself and it failed - and I have not seen anyone doing it. IMO - when a build tool is only for experts, it is a poor tool of creation. Gradle for Android is just that. Few can the software companies, technology that afford to introduce to understand only 1-2 people at home.
# 2 Google is not interested in having Android SDK to survive
For me, this is the largest study problem Android. It is an IDE for what developed a dying language. Android Studio is already dead.
Why? Since cross-platform (ie, at least Android + IOS) is the only sensible choice if you want to start the development of mobile applications today. Limit yourself to a single platform is just silly - and especially for the Games (which is - I would remind you - 90% of sales in the App Store), there are many, many excellent multi-platform tools like unit and Cocos2dx. None of them have Java or the Android SDK as a development language.
If Google wanted Android Java must be more than a footnote in history, they would have made an effort - any effort - it is Java Android cross-compiled on other platforms. At least one could the Android SDK can create programs Chrome, or even Android applications compiled directly from desktop applications. Both would be relatively simple. They will not, though. Instead dithering about Android and Chrome OS they want to support.
Of course - some argue that Google has already decided, and the choice is Chrome OS. Soon you can applications can run Chrome either in Chrome OS, Android, iOS and Google (has already announced that, based on Apache Cordoba) Personally, I'm not quite sure that Google has not to develop their minds yet, but ultimately developing the Community to make the choice for them, and is not to be Android SDK.
I'm not saying that he die this year or next - but at some point it becomes very clear that Google is not interested in who became the development of native Android (in typical Google approach, it does not surprise me if it even makes it Studio to Android 1.0). And I say this not because I hate Android - I love the strengths of the Android SDK, and I would no more joy love to hear Google ads to make I / O to show that they are going to the Android SDK build. I doubt that will happen when.
Ironically, starting as a developer, leaving Android SDK (Android and Studio), one of the languages that are likely to encounter, JavaScript (the language of choice for Google Chrome OS), which often lead people back in .... Eclipse.
Loading interstitial admob after 5 seconds. İ have a code for interstitial admob. now in my app it loads interstitial admob when i click about menu. But this makes problem for google admob. So they stopped my admob in this app. İ want to solve this with loading interstitial admob after 5 second when i click about menu. How can i change the code.
i dont know any code. please say me to add which code to my code.
This is "about java file" code:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.WindowManager;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
public class About extends AppCompatActivity {
private String TAG = About.class.getSimpleName();
InterstitialAd mInterstitialAd;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_game_layout);
setContentView(R.layout.activity_about);
mInterstitialAd = new InterstitialAd(this);
// set the ad unit ID
mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
AdRequest adRequest = new AdRequest.Builder()
.build();
// Load ads into Interstitial Ads
mInterstitialAd.loadAd(adRequest);
mInterstitialAd.setAdListener(new AdListener() {
public void onAdLoaded() {
showInterstitial();
}
});
}
private void showInterstitial() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
@override
protected void onStop() {
super.onStop();
finish();
}
}
I am creating a simple application in Android Studio for managing a device connected via wifi using the Volley library.
The app must do this: when you click on the On button the device must turn on and consequently show the image of a light bulb on, while when I click on the Off button the device must turn off and show the image of a light bulb off on the screen . In Postman the interaction with the device works correctly.
When I start the app and click on the on/off button nothing happens, that is, it always shows me an image of an unlit light bulb. The logcat gives me no errors.
By debugging I notice that when the sendAndRequestResponse() method is executed it does not enter the onResponse method but jumps directly to the setRetryPolicy method.
Can you kindly help me? I am a beginner.
MainActivity.java
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SwitchCompat;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import java.text.BreakIterator;
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getName();
SwitchCompat switchButton;
LinearLayout imageViewLight;
private RequestQueue mRequestQueue;
TextView buttonState;
private StringRequest mStringRequest;
private String url = "https://192.168.130.13:8081/zeroconf/switch";
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
switchButton=findViewById(R.id.switchButton);
imageViewLight=findViewById(R.id.linearL);
TextView buttonState;
buttonState = findViewById(R.id.buttonState);
switchButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
sendAndRequestResponse();
}
});
}
private void sendAndRequestResponse() {
mRequestQueue = Volley.newRequestQueue(this);
mStringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@override
public void onResponse(String response) {
TextView myTextView;
if (switchButton.isChecked()) {
imageViewLight.setBackgroundResource(R.drawable.light__02);
buttonState.setText("State : ON");
} else {
imageViewLight.setBackgroundResource(R.drawable.light__01);
buttonState.setText("State : OFF");
}
}
}, new Response.ErrorListener() {
@override
public void onErrorResponse(VolleyError error) {
Log.i(TAG,"Error :" + error.toString());
}
});
mStringRequest.setRetryPolicy(new RetryPolicy() {
@override
public int getCurrentTimeout() {
return 50000;
}
@override
public int getCurrentRetryCount() {
return 50000;
}
@override
public void retry(VolleyError error) throws VolleyError {
}
});
mRequestQueue.add(mStringRequest);
}
}