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.
Related
Hi y'all. I have recently been trying to make a calculator app in AS. However, the app stops when I click the calculate button. I also wanted to have it notify the user the result contained in the result variable, but the setContentText doesn't want to work. Code:
Code:
package firstapp.stars.com.firstapp;
import android.os.Bundle;
import android.app.Notification;
import android.app.NotificationManager;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class AddScrn extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add);
final Button button4;
button4 = (Button) findViewById(R.id.button4);
button4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
TextView textView4 = (TextView) findViewById(R.id.textView4);
EditText editText7 = (EditText) findViewById(R.id.editText7);
EditText editText8 = (EditText) findViewById(R.id.editText8);
String mynum1=editText7.getText().toString();
String mynum2=editText8.getText().toString();
int result = Integer.parseInt(mynum1) + Integer.parseInt(mynum2);
textView4.setText(Integer.toString(result));
textView4.setText(result);
Notification notification = new Notification.Builder(getApplicationContext())
.setContentTitle("Calculator - Calculation result:")
String content = String.valueOf(result);
.setContentText(content);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
}
});
}
@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_add_scrn, 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);
}
}
Help.
Whats-a-username? said:
Hi y'all. I have recently been trying to make a calculator app in AS. However, the app stops when I click the calculate button. I also wanted to have it notify the user the result contained in the result variable, but the setContentText doesn't want to work. Code:
Code:
package firstapp.stars.com.firstapp;
import android.os.Bundle;
import android.app.Notification;
import android.app.NotificationManager;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class AddScrn extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add);
final Button button4;
button4 = (Button) findViewById(R.id.button4);
button4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
TextView textView4 = (TextView) findViewById(R.id.textView4);
EditText editText7 = (EditText) findViewById(R.id.editText7);
EditText editText8 = (EditText) findViewById(R.id.editText8);
String mynum1=editText7.getText().toString();
String mynum2=editText8.getText().toString();
int result = Integer.parseInt(mynum1) + Integer.parseInt(mynum2);
textView4.setText(Integer.toString(result));
textView4.setText(result);
Notification notification = new Notification.Builder(getApplicationContext())
.setContentTitle("Calculator - Calculation result:")
String content = String.valueOf(result);
.setContentText(content);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
}
});
}
@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_add_scrn, 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);
}
}
Help.
Click to expand...
Click to collapse
Regarding the following code:
textView4.setText(Integer.toString(result));
textView4.setText(result);
Why you assign the value twice?
The first assignment is OK, but the second one need to removed.
The result variable is an Integer type, and when you assign Integer to TextView, it will look for a sting resource id (in the strings xml).
If the id is not found, it can throw an exception.
Yes, but the app still crashes when the button is clicked and still doesn't want to notify me.
Still Active Errors
1. In the setContentTitle it says" ; expected", but when ; is placed, it highlights everything.
2. "Cannot resolve method setContentText".
Whats-a-username? said:
1. In the setContentTitle it says" ; expected", but when ; is placed, it highlights everything.
2. "Cannot resolve method setContentText".
Click to expand...
Click to collapse
Your code is incorrect.
Change you code to the following:
String content = String.valueOf(result);
Notification notification = new Notification.Builder(this)
.setContentTitle("Calculator - Calculation result:")
.setContentText(content).build();
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.
Hi guy this is my first application android, i using android studio and i need the help. i long press in not show context menu to download the image, below I leave the code if someone is kind enough to give me help.
Code:
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
WebView webView;
ProgressBar progressBar;
private AudioManager audio;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setSupportZoom(true);
webView.setVerticalScrollBarEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setHorizontalScrollBarEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
//webView.getSettings().setBuiltInZoomControls(true);
webView.loadUrl("https://alpha.wallhaven.cc/");
//Barra de progreso
progressBar = (ProgressBar) findViewById(R.id.progressBar);
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int progress) {
progressBar.setProgress(0);
progressBar.setVisibility(View.VISIBLE);
MainActivity.this.setProgress(progress * 1000);
progressBar.incrementProgressBy(progress);
if (progress == 100) {
progressBar.setVisibility(View.GONE);
}
}
});
/*Adding shortcut for MainActivity
//on Home screen
Intent shortcutIntent = new Intent(getApplicationContext(),
MainActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "HelloWorldShortcut");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.drawable.ic_launcher));
addIntent.putExtra("duplicate", false);
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);*/
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
return true;
case KeyEvent.KEYCODE_BACK:
if (webView.canGoBack()) {
//if Back key pressed and webview can navigate to previous page
webView.goBack();
// go back to previous page
return true;
} else {
finish();
// finish the activity
}
return super.onKeyDown(keyCode, event);
default:
return false;
}
}
}
Hello everybody. I created a contextual action bar with list view with my own adapter. It works perfectly. Now I want to add a check box to select the row, when user click anywhere. I added checkbox to row layout (it contains textview, textview and checkbox) and setEnable(false) because I will programaticaly set clicked/unclicked. But I have a problem how to add a listener to each row in an adapter which will be checking if the row was clicked and set checkbox clicked and change the object value click to true(I only need help with adding listener). Could anybody help me
Here is my adapter code
package com.example.micha.shoppinglist;
import android.app.Activity;
import android.content.Context;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
/**
* Created by MichaĆ on 26.04.2017.
*/
public class RowAdapter extends ArrayAdapter<ProductList>{
private Context context;
private int resource;
private ArrayList<ProductList> data = null;
private RowBeanHolder holder = null;
private boolean longPressed=false;
public RowAdapter @Nonnull Context context, @layoutRes int resource, @Nonnull List<ProductList> data) {
super(context, resource, data);
this.context=context;
this.resource=resource;
this.data=(ArrayList<ProductList>)data;
}
@override
public View getView(int position, final View convertView, ViewGroup parent) {
View row = convertView;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(resource, parent, false);
holder = new RowBeanHolder();
holder.txtTitle=(TextView) row.findViewById(R.id.name);
holder.indicator=(TextView) row.findViewById(R.id.indicator);
holder.checkBox=(CheckBox) row.findViewById(R.id.checkBoxDelete);
row.setTag(holder);
}
else
{
holder = (RowBeanHolder)row.getTag();
}
if(longPressed){
showCheckbox();
}
else{
hideCheckbox();
uncheck();
}
ProductList object = data.get(position);
holder.txtTitle.setText(object.getName());
holder.indicator.setText(object.getToBuy() + "/" + object.getBought());
return row;
}
static class RowBeanHolder {
TextView txtTitle;
TextView indicator;
CheckBox checkBox;
}
public void showCheckbox() {
holder.checkBox.setVisibility(View.VISIBLE);
longPressed=true;
notifyDataSetChanged();
}
public void hideCheckbox() {
holder.checkBox.setVisibility(View.GONE);
longPressed=false;
notifyDataSetChanged();
}
public void uncheck(){
holder.checkBox.setChecked(false);
notifyDataSetChanged();
}
}
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);
}
}