I'm working on an app that will allow users to report potholes and other roadside issues easily. My specific issue is in the map I included; in the report activity that will allow users to pinpoint where the problem is by using google maps and some markers. To do this I'm basically copying code word for word from the google maps api and my problem is that the permission utils object isn't being inherited from google play services. I had put this code down for a while (out of frustration) so i dont exactly remember what the other issues were but i remember getting the code around permission utils to not give me an error was kind of a bitch. Anyway so please help ;_;. I apologize for how i space my code, it is just visually easier for me, the first block is the message activity, the second is my manifest. please let me know if I should post anything else.
package com.example.fixmytown;
import java.util.List;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMyLocationButtonClickListener;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.ContextCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.maps.SupportMapFragment;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
public class Message extends FragmentActivity implements OnMyLocationButtonClickListener,
OnMapReadyCallback,
ActivityCompat.OnRequestPermissionsResultCallback {
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1;
private boolean mPermissionDenied = false;
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maps_frag);
MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
//----------------------------[Don't Mess with the above]------------------------------------------------------------
android.app.ActionBar actionBar = getActionBar();
//-------------------------------------------------------------------------------------------------------------------
//you were trying to figure out why the action bar isnt changing title. beinga bitch
String subject = " ";
if (Black.activityType == 1){
subject = "Pothole";
}
else if (Black.activityType == 2){
subject = "Roadkill";
}
else if (Black.activityType == 3){
subject = "Pollution";
}
else if(Black.activityType == 4){
// getActionBar().setTitle("Email Public Servant ");
}
}
//-------------------------------------------------------------------------------------------------------------------
#Override
public void onMapReady(GoogleMap map) {
mMap = map;
mMap.setOnMyLocationButtonClickListener(this);
enableMyLocation();
}
private void enableMyLocation() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// Permission to access the location is missing.
PermissionUtils.requestPermission(this, LOCATION_PERMISSION_REQUEST_CODE,
Manifest.permission.ACCESS_FINE_LOCATION, true);
} else if (mMap != null) {
// Access to the location has been granted to the app.
mMap.setMyLocationEnabled(true);
}
}
//-------------------------------------------------------------------------------------------------------------------
public void sendMessage(View view) {
EditText text = (EditText)findViewById(R.id.MessageText);
String Description = text.getText().toString();
String subject = "";
if (Black.activityType == 1){
subject = "Pothole";
}
else if (Black.activityType == 2){
subject = "Roadkill";
}
else if (Black.activityType == 3){
subject = "Pollution";
}
else if(Black.activityType == 4){
// getActionBar().setTitle("Email Public Servant ");
}
//-------------------------------------------------------------------------------------------------------------------
//email ability
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"mckippy#gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, subject);
i.putExtra(Intent.EXTRA_TEXT , Description);
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Message.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
//-------------------------------------------------------------------------------------------------------------------
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.message, 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.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public boolean onMyLocationButtonClick() {
// TODO Auto-generated method stub
return false;
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fixmytown"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="com.google.android.providers.gsf.permisson.READ_GSERVICES"/>
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission
android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:screenOrientation="portrait"
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:screenOrientation="portrait"
android:name=".Black"
android:label="#string/title_activity_black" >
</activity>
<activity
android:screenOrientation="portrait"
android:name=".Green"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/title_activity_green"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:screenOrientation="portrait"
android:name=".Message"
android:label="#string/title_activity_message" >
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyA0e26vc4-YGqmvOQSA6lQfnZyt3dmmbek"/>
</application>
</manifest>
Related
FATAL EXCEPTION: main
Process: org.example.easyparking, PID: 6371
java.lang.RuntimeException: Unable to start activity
ComponentInfo{org.example.easyparking/org.example.easyparking.MapActivity}:
android.view.InflateException: Binary XML file line #0: Binary XML
file line #0: Error inflating class fragment
This is my mapactivity
package org.example.easyparking;
import android.app.Dialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
public class MapActivity extends AppCompatActivity implements
OnMapReadyCallback {
GoogleMap mGoogleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
if(googleServicesAvailable()){
setContentView(R.layout.activity_map);
initMap();
}else{
//No Google Map Layout
}
}
private void initMap() {
MapFragment mapFragment = (MapFragment) getFragmentManager().
findFragmentById(R.id.mapFragment);
mapFragment.getMapAsync(this);
}
public boolean googleServicesAvailable(){
GoogleApiAvailability api = GoogleApiAvailability.getInstance();
int isAvailable = api.isGooglePlayServicesAvailable(this);
if(isAvailable == ConnectionResult.SUCCESS){
return true;
}else if (api.isUserResolvableError(isAvailable)){
Dialog dialog = api.getErrorDialog(this, isAvailable, 0);
dialog.show();
}else{
Toast.makeText(this, "Can't connect", Toast.LENGTH_LONG)
.show();
}
return false;
}
#Override
public void onMapReady(GoogleMap googleMap) {
mGoogleMap = googleMap;
}
}
This is menifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.example.easyparking">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<permission android:name="org.example.easyparking.permission.MAP_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="org.example.easyparking.permission.MAP_RECEIVE"/>
<uses-permission android:name="com.google.android.providers.gsf.permissions.READ_GSERVICES"/>
<uses-feature android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".FirstActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MapActivity" />
<activity
android:name=".SecondActivity">
</activity>
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDGpV3ndPQ1Z4zf1nXi5AW1c7jGPL1La7Q"/>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
</application>
</manifest>
This is the first activity
package org.example.easyparking;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class FirstActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
Button button = (Button) this.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(),
"Make sure that your location is turned on",
Toast.LENGTH_LONG).show();
Intent newacti = new Intent(FirstActivity.this, MapActivity.class);
startActivity(newacti);
}
});
Button button_parking_owner = (Button) this.findViewById(R.id.button2);
button_parking_owner.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent newacti = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(newacti);
}
});
}
}
In your MapActivity you are checking if googleServicesAvailable() is available and if not you are not providing a default content to render
if(googleServicesAvailable()){
setContentView(R.layout.activity_map);
initMap();
}else{
//No Google Map Layout
}
try creating a basic layout to render that says something like No Google Map
i.e you should have something like
if(googleServicesAvailable()){
setContentView(R.layout.activity_map);
initMap();
}else{
//No Google Map Layout
setContentView(R.layout.no_activity_map);
}
then create a no_activity_map layout
What would be the proper way to Implement a Google Search with SearchView. For example, I press the Search button, and enter a query, and then after I hit enter button, it would do a google search in which I can get JSON data. All the examples I've seen are with lists or something similar. I'm trying figure out how to implement a Web search into SearchView
try using Google Custom Search api
I know this is old, but you should not put your SearchView searchView as a global variable, as that can lead to memory leaks. Instead, keep it as a local variable inside of onCreateOptionsMenu.
Figured it out! It was probably something to do with my Android Manifest or something:
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alexoladele.testingshit">
<!-- Permissions's -->
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchActivity" />
<!-- Main Activity -->
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- SearchActivity -->
<activity
android:name=".SearchActivity"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
</application>
</manifest>
SearchActivity.java:
package com.alexoladele.testingshit;
import android.app.ListActivity;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import com.google.api.services.customsearch.Customsearch;
public class SearchActivity extends ListActivity {
private static final String TAG = "SearchActivity";
private String qry;
private Customsearch customsearch;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
Log.i(TAG, "onCreate: ContentView was set to activity_search");
Intent intent = getIntent();
Log.i(TAG, "onCreate: Got Intent");
Log.i(TAG, "onCreate: Handling Intent!");
handleIntent(intent);
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
handleIntent(intent);
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// Call detail activity for clicked entry
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
qry = intent.getStringExtra(SearchManager.QUERY);
Log.i(TAG, "handleIntent: QUERY: " + qry + "\n Starting the doSearch Method!");
doSearch(qry);
} else {
Log.i(TAG, "handleIntent: Intent WAS NOT search");
}
}
private void doSearch(String query) {
Log.i(TAG, "doSearch: In doSearch Method!");
}
}
MainActivity.java:
package com.alexoladele.testingshit;
import android.Manifest;
import android.app.SearchManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
import layout.WelcomeScreenFragment;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
SearchView searchView;
final static String[] NEEDED_PERMISSIONS = {Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.INTERNET,
Manifest.permission.ACCESS_NETWORK_STATE};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 0);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(toolbar);
if (ContextCompat.checkSelfPermission(getApplicationContext(), NEEDED_PERMISSIONS[0])
!= PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(getApplicationContext(), NEEDED_PERMISSIONS[1])
!= PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(getApplicationContext(), NEEDED_PERMISSIONS[2])
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, NEEDED_PERMISSIONS, 808);
Log.i(TAG, "onCreate: Requesting Permissions");
}
// Makes sure that the root_layout view is not null before doing anything
if (findViewById(R.id.root_layout) != null) {
// Makes sure that there's no saved instance before proceeding
if (savedInstanceState == null) {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction manager = fm.beginTransaction();
manager
.add(R.id.root_layout, WelcomeScreenFragment.newInstance(), "welcomeScreen")
.commit();
}
}
}
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
switch (808) {
case 808:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(), "Permissions GRANTED", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Permissions NOT GRANTED", Toast.LENGTH_SHORT).show();
}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu);
// VARIBLES TO USE
MenuItem searchItem = menu.findItem(R.id.search);
searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
// Set Up the search Function
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String query) {
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
ComponentName componentName = new ComponentName(getApplicationContext(), SearchActivity.class);
searchView.setSearchableInfo(searchManager.getSearchableInfo(componentName));
searchView.setIconifiedByDefault(false);
return true;
}
}
Am trying to implement a google map on my app that has other activities but it is not working. When i compile the apk and run it in my phone the map appears blank anybody with an idea.
I tried to check my API key but it appears to be okay. I have been working on this for 3days any help?
This are my files
androidmanifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="#mipmap/kaps"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".models.StartWatchActivity"
android:label="#string/title_activity_start_watch" >
</activity>
<activity
android:name=".models.PaymentActivity"
android:label="#string/title_activity_payment" >
</activity>
<activity
android:name=".models.LocationActivity"
android:label="#string/title_activity_location" >
</activity>
<activity
android:name=".models.GetCurrentLocation"
android:label="#string/title_activity_get_current_location" >
</activity>
<activity
android:name=".models.ConfirmRegistration"
android:label="#string/title_activity_confirm_registration" >
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="*******************************" />
<activity
android:name=".models.MapsActivity"
android:label="#string/title_activity_maps" >
</activity>
</application>
MapActivity.java
import android.location.Address;
import android.location.Geocoder;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import org.w3c.dom.Text;
import java.io.IOException;
import java.util.List;
public class MapsActivity extends FragmentActivity {
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
}
#Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
public void onSearch(View view){
EditText location_tf=(EditText)findViewById(R.id.TFaddress);
String location=location_tf.getText().toString();
List<Address> addressList=null;
if(location !=null ||!location.equals(""))
{
Geocoder geocoder=new Geocoder(this);
try {
addressList=geocoder.getFromLocationName(location, 1);
} catch (IOException e) {
e.printStackTrace();
}
Address address=addressList.get(0);
LatLng latLng=new LatLng(address.getLatitude(),address.getLongitude());
mMap.addMarker(new MarkerOptions().position(latLng).title("Marker"));
mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
}
}
public void onZoom(View view)
{
if (view.getId()==R.id.Bzoomin)
{
mMap.animateCamera(CameraUpdateFactory.zoomIn());
}
if (view.getId()==R.id.Bzoomout)
{
mMap.animateCamera(CameraUpdateFactory.zoomOut());
}
}
public void changeType(View view)
{
if(mMap.getMapType()==GoogleMap.MAP_TYPE_NORMAL)
{
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
}
else
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
mMap.setMyLocationEnabled(true);
}
}
locationactivity.java
when a button is clicked takes you to the MapActivity
import android.content.Intent;
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.Button;
import com.example.barbegambino.parkcar.R;
public class LocationActivity extends AppCompatActivity {
Button button4,button,button5;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_location);
button4 = (Button) findViewById(R.id.button4);
button = (Button) findViewById(R.id.button);
button5 = (Button) findViewById(R.id.button5);
button4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(LocationActivity.this, GetCurrentLocation.class);
startActivity(intent);
}
});
button5.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(LocationActivity.this, StartWatchActivity.class);
startActivity(intent);
}
});
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent=new Intent(LocationActivity.this,MapsActivity.class);
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_location, 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);
}
}
Your problem occurs due to missing of Google Play Service.
3 step process:-
4.4 Kitkat
5.0 Lollipop
5.1 Lollipop
6.0 Marshmallow
7.0 Nougat
7.1 Nougat (webview patch)
Download from above link
Just drag & drop downloaded zip file to genymotion and restart
Add google account and download Google Play Service and Run.
Note :- The above process can be automated if you install OpenGapps apk in your device.
Download link for apk
I have been recently trying to make an Android app that simply calls a number . I came up with the following code .main activity:
package com.example.irdeesmughal.callapp;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity
{
public void call()
{
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:03335975321"));
try{
startActivity(callIntent);
}
catch (android.content.ActivityNotFoundException ex){
Toast.makeText(getApplicationContext(),"yourActivity is not founded", Toast.LENGTH_SHORT).show();
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
#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);
}
}
problem is when I run this app on my Galaxy Note 5 and click the call button, the app crashes.
android manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.irdeesmughal.callapp">
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
putting this in your call method may helps:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:03335975321"));
try
{
startActivity(callIntent);
}
catch (Exception e)
{
e.printStackTrace();
}
You should request runtime permission on Android 6.0+ Documentation
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) ==
PackageManager.PERMISSION_GRANTED){
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + phoneNumber));
startActivity(callIntent);
} else {
snackWithOk(R.string.please_enable_call_permission);
}
This question already has an answer here:
Permission from manifest doesn't work in Android 6
(1 answer)
Closed 7 years ago.
I am trying to build a simple app to send message, but its giving error:
java.langSecurityException:Sending SMS message:uid 10057 does not
have`android.permission.SEND_SMS
even though i have added android.permission.SEND_SMS in manifest, help me solve this problem
main-activity.java
package com.example.manju.helpme;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.content.Intent;
import android.widget.Edit
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
/* called when user clicks ALERT! button*/
public final static String EXTRA_MESSAGE = "com.example.HelpMe.Message";
public void sendMessage(){
String phoneNo = "5556";
String message = "hi";
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, message, null, null);
Toast.makeText(getApplicationContext(), "SMS sent",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS failed, please try again.",
Toast.LENGTH_LONG).show();
e.printStackTrace();
Intent intent = new Intent(this,DisplayMessageActivity.class);
String Message = e.toString();
intent.putExtra(EXTRA_MESSAGE, Message);
startActivity(intent);
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnAlert = (Button)findViewById(R.id.btn_Alert);
Button btnAddGuardian = (Button)findViewById(R.id.btn_Add_Guardian);
Button btnRemoveGuardian = (Button)findViewById(R.id.btn_Remove_Guardian);
btnAlert.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sendMessage();
}
});
btnAddGuardian.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
btnRemoveGuardian.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
#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();
//no inspection Simplifiable If Statement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Android Manifest.XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.manju.helpme" >
<uses-permission android:name="android.permission.SEND_SMS"> </uses-permission>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Guardians"
android:label="#string/title_activity_guardians"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.manju.helpme.MainActivity" />
</activity>
<activity
android:name=".DisplayMessageActivity"
android:label="#string/title_activity_display_message" >
</activity>
</application>
</manifest>
In my case, I changed the targeted sdk to 19 and also find that you didn't define the uses-sdk in the manifest...!
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
Try changing the uses-permission syntax like this:
<uses-permission android:name="android.permission.SEND_SMS"/>