Error when sharing a CSV file saved in internal storage - java

I'm creating a contact tracing application using Java, the results of tracing are saved as detections.csv inside /storage/emulated/0/Android/media/com.idcta.proj.app/Sensor/ folder.
I'm trying to share this file on a button click, and my Manifest looks like this
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.idcta.proj.app">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
/>
<application
android:name="com.idcta.proj.app.AppDelegate"
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"
android:hardwareAccelerated="true"
android:requestLegacyExternalStorage="true">
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths" />
</provider>
.....</appliction>
provider_paths.xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
and inside my Contactlogs.java file inside the onCreate method
//request permissions for storage
requestPermissions();
//share button event
btn_share =(ImageButton)findViewById(R.id.btn_sharelogs);
btn_share.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),"detection.csv");
Uri path = FileProvider.getUriForFile(Contactlogs.this,BuildConfig.APPLICATION_ID+".provider",file);
Intent fileIntent = new Intent(Intent.ACTION_SEND);
fileIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
Intent.FLAG_GRANT_READ_URI_PERMISSION);
fileIntent.setType("text/*");
fileIntent.putExtra(Intent.EXTRA_STREAM, path);
Toast.makeText(Contactlogs.this," "+path,Toast.LENGTH_LONG).show();
startActivity(Intent.createChooser(fileIntent, "Send"));
}
});
But I keep getting the error:
E/ContentProviderNative: onTransact error from {P:29044;U:1000}
E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri content://com.idcta.proj.app.provider/external_files/detection.csv from pid=29044, uid=1000 requires the provider be exported, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:873)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:714)
at android.content.ContentProvider$Transport.query(ContentProvider.java:245)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:120)
at android.os.Binder.execTransactInternal(Binder.java:1165)
at android.os.Binder.execTransact(Binder.java:1134)
Any idea what I'm doing wrong here?
My Build.Gradle settings:
compileSdkVersion 30
buildToolsVersion "30.0.1"
defaultConfig {
applicationId 'com.idcta.proj.app'
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.2.0"

detections.csv inside /storage/emulated/0/Android/media/com.idcta.proj.app/Sensor/ folder.
That you got using getExternalMediaDirs()[0].
/storage/emulated/0/Android/media/com.idcta.proj.app/Sensor/detections.csv
So what did you code to have that path while saving?
Now when you want to serve the file you could use:
File file = new File(getExternalMediaDirs()[0], "Sensor/detections.csv");
Now you are hard coding your package name in the path.
Hardcoding should be avoided.

Related

W/System.err: com.parse.ParseRequest$ParseRequestException: i/o failure

I am trying to run the app that uses Anonymous login in the Parse server, but I get the Following in the log cat.
The app runs on only one of my device with android oreo 8.1, but when tried it on other device with Android pie the log cat gives the.
And this happens only with this app, other apps where I take the username and password from the user there also I get the same error.
I have tried all possible solution given to this problem on stackoverflow but the error doesn't goes.
Does anyone know is the Parse server which allows only one device to connect?
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.parse.starter.uber">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name=".StarterApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<activity
android:name=".DriverLocationActivity"
android:label="#string/title_activity_driver_location"></activity>
<activity android:name=".ViewRequestsActivity" />
<activity
android:name=".RiderActivity"
android:label="#string/title_activity_rider" />
<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>
</application>
</manifest>
StarterApplication file that connects to parse server
package com.parse.starter.uber;
import android.app.Application;
import android.util.Log;
import com.parse.Parse;
import com.parse.ParseACL;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseUser;
import com.parse.SaveCallback;
public class StarterApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.enableLocalDatastore(this);
// Add your initialization code here
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
.applicationId("MY_APP_ID")
.clientKey("MY_CLIENT_ID")
.server("http://13.126.179.137:80/parse/")
.build()
);
ParseACL defaultACL = new ParseACL();
defaultACL.setPublicReadAccess(true);
defaultACL.setPublicWriteAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
}
}
project gradle
buildscript {
repositories {
mavenCentral()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
}
}
allprojects {
repositories {
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
app gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.parse.starter.uber"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "4g"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.parse.bolts:bolts-tasks:1.4.0'
implementation 'com.parse:parse-android:1.17.3'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
}
log cat
2020-03-17 12:14:14.349 26020-26020/com.parse.starter.uber W/System.err: com.parse.ParseRequest$ParseRequestException: i/o failure
2020-03-17 12:14:14.353 26020-26020/com.parse.starter.uber W/System.err: at com.parse.ParseRequest.newTemporaryException(ParseRequest.java:292)
2020-03-17 12:14:14.353 26020-26020/com.parse.starter.uber W/System.err: at com.parse.ParseRequest$2.then(ParseRequest.java:146)
2020-03-17 12:14:14.353 26020-26020/com.parse.starter.uber W/System.err: at com.parse.ParseRequest$2.then(ParseRequest.java:140)
2020-03-17 12:14:14.354 26020-26020/com.parse.starter.uber W/System.err: at bolts.Task$15.run(Task.java:917)
2020-03-17 12:14:14.354 26020-26020/com.parse.starter.uber W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2020-03-17 12:14:14.354 26020-26020/com.parse.starter.uber W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2020-03-17 12:14:14.354 26020-26020/com.parse.starter.uber W/System.err: at java.lang.Thread.run(Thread.java:764)
2020-03-17 12:14:14.355 26020-26020/com.parse.starter.uber W/System.err: Caused by: java.net.UnknownServiceException: CLEARTEXT communication to 13.126.179.137 not permitted by network security policy
.
.
.
.
.
2020-03-17 12:14:14.363 26020-26020/com.parse.starter.uber I/Info: Anonymous Login Failed
Heading
Manifest merger failed : Attribute application#appComponentFactory - Androidx
option 1 -
Create file res/xml/network_security_config.xml -
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">Your URL(ex: 127.0.0.1)</domain>
</domain-config>
</network-security-config>
AndroidManifest.xml -
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:networkSecurityConfig="#xml/network_security_config"
...>
...
</application>
</manifest>
Option 2 -
AndroidManifest.xml -
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:usesCleartextTraffic="true"
...>
...
</application>
</manifest>

Linking Error - No Write Permission

I have a problem with a project I am working on in Android Studio. The goal is to save a basic string into a .csv file then attach that file as an email attachment.
I cant write to the file, but I can share the file via FileProvider.getUriForFile.
I think the problem has something to do with these two linker error messages I get, the streamsavvy-1 is concerning bc my package name is com.team6.rifflegroup.streamsavvy
11-13 16:20:39.775 10286-10286/com.team6.rifflegroup.streamsavvy E/linker: readlink('') failed: No such file or directory [fd=31]
11-13 16:20:39.775 10286-10286/com.team6.rifflegroup.streamsavvy E/linker: warning: unable to get realpath for the library "/data/app/com.team6.rifflegroup.streamsavvy-1/oat/arm64/base.odex". Will use given name.
I build the file like this
File dataPath = new File(this.getFilesDir(), "xml");
File newData = new File(dataPath, FILE_NAME);
I have a paths.xml file within an xml directory under res that looks like this
<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path
name="my_files"
path="/"/>
</paths>
my write function looks like this
try {
FileWriter writer = new FileWriter(newData);
writer.append(csv);
writer.flush();
writer.close();
Toast.makeText(this, "SAVED", Toast.LENGTH_SHORT).show();
}catch (IOException e){
e.printStackTrace();
}
My Email intent looks like this
Uri contentUri = FileProvider.getUriForFile(this, "com.team6.rifflegroup.streamsavvy.FileProvider", newData);
this.grantUriPermission(getPackageName(), contentUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.setType("vnd.android.cursor.dir/email");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"myEmail#gmail.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, "File Attached");
emailIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
startActivity(Intent.createChooser(emailIntent, "Send email..."));
I give permission in my manifest here
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<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=".dataLayout">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.team6.rifflegroup.streamsavvy.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/paths"/>
</provider>
</application>
I feel like this is a problem with the way java builds its projects but I am not very familiar with the process. Any help or pointers would be greatly appreciated.
This is my first time posting here so I am so sorry if my post is out of context or improperly formatted.
Apologize for the long post. Figured it out.
had to declare the .mkdirs() call (not .mkdir()) after specifying the file.

Getting URI instead of File when using FileProvider

I am creating an app in which I let the user to share an audio file that is presen on the external storage.
I try to use this code but it is not working.
//This is getting the absolute path of the parent folder where the
//file is situated
File mFolder= new File(m_sdcard+m_confi);
// This take us to folder where the file is situated
File mAbFolder = new File(mFolder, "temp");
// Taking the files in an array
File[] mAllFiles= mAbFolder.listFiles();
//Getting the URI
Uri contentUri = FileProvider.getUriForFile(mContext, "com.androidpackagename.fileprovider", mImageFiles[1]);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setDataAndType(contentUri, mContext.getContentResolver().getType(contentUri));
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
mContext.startActivity(intent);
Now when I am running this code, it shows me the share menu. But when I click on any item such as Gmail, it put the uri into the "TO" field.
And I also tried to share it on Whatsapp. When I select a user to share this, nothing happens and I get back to my app.
My manifest is :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidpackagename">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.androidpackagename.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/filepath" />
</provider>
</application>
</manifest>
My filepath xml is having
<external-path
name="external"
path="Android/data/com.androidpackagename/temp/" />
</paths>
Please help on this, thanks in advance.
I try to use this code but it is not working.
That is not how you use ACTION_SEND. Quoting the documentation:
Input: getType() is the MIME type of the data being sent. get*Extra can have either a EXTRA_TEXT or EXTRA_STREAM field, containing the data to be sent. If using EXTRA_TEXT, the MIME type should be "text/plain"; otherwise it should be the MIME type of the data in EXTRA_STREAM.
So, replace:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setDataAndType(contentUri, mContext.getContentResolver().getType(contentUri));
with:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(mContext.getContentResolver().getType(contentUri));
intent.putExtra(Intent.EXTRA_STREAM, contentUri);
(though it would be much more efficient for you to just put in the MIME type directly in setType(), rather than using getContentResolver().getType(contentUri), since hopefully you know what this file is and what its MIME type is)

Failed to install Map.apk on device 'emulator-5554'

I'm new to the Android world, and I need to create an app using Google Maps Android API. I follow the instructions in:
https://developers.google.com/maps/documentation/android/start
and whenever I start the AVD I get an error:
[2013-12-05 21:04:37 - Map] Failed to install Map.apk on device 'emulator-5554!
[2013-12-05 21:04:37 - Map] (null)
[2013-12-05 21:04:38 - Map] Launch canceled!
My MainActivity code:
package com.example.map;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
my MainActivity XML file:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
and my Manifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.map"
android:versionCode="1"
android:versionName="1.0" >
<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"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="19" />
<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.xxxxxxxxxHIDDENxxxxxxxx"
android:value="xxxxxxxxxHIDDENxxxxxxxx"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.map.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>
</application>
</manifest>
Also tried the code that it's provided here:
https://developers.google.com/maps/documentation/android/
being the MainActivity file code:
package com.example.map;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.*;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_activity);
// Get a handle to the Map Fragment
GoogleMap map = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.map)).getMap();
LatLng sydney = new LatLng(-33.867, 151.206);
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));
map.addMarker(new MarkerOptions()
.title("Sydney")
.snippet("The most populous city in Australia.")
.position(sydney));
}
}
Any Ideas?
The first thing I would recommend is to not show your API key to the public; this are supposed to be private to whomever is developing the application.
Also the format of this meta tag is wrong:
<meta-data
android:name="com.google.android.maps.v2.AIzaSyB7AMKbYsVajgb6D0zpq9wUODX9gdR2DhE"
android:value="AIzaSyB7AMKbYsVajgb6D0zpq9wUODX9gdR2DhE"/>
You are copying your API key at the end of the name. I strongly suggest you create a new API key and do not use this one that you have exposed to the public. There might be other errors, but without the stack trace is hard to say.
See this page: http://developer.android.com/google/play-services/setup.html
Specifically:
To test your app when using the Google Play services SDK, you must use
either:
A compatible Android device that runs Android 2.3 or higher and includes Google Play Store.
The Android emulator with an AVD that runs the Google APIs platform based on Android 4.2.2 or higher.
So make sure the emulator you're using is Android 4.2.2 or greater. If it is below this level, Google Play Services is not available on the emulator, and you must use a physical android device to test it out.
If you have to test on a lower-end device emulator, there are workarounds to this but they aren't officially supported by Google so your mileage may vary.
See this link:
Custom emulator that supports Google Maps API

Blank Screen Android 2.2 Google Maps v2

EDIT :
I transferred my 20+ projects that tries to use Google Maps for Android v2. After changing keys and stuff, now, it works. I don't know what made this work, but thank you all. I got one keystore, the key is right. I guess it magically fixed somehow. Well, thanks guys.
I'm doing searches for 2 days and I couldn't fix this problem. I did everything, yet, this application can not work.
I want my application to work on Android 2.2 and above. Like it says "if you create your app in level 8, it'll support 95% of market".
Here are my screenshots and source codes:
I'm pasting the source code which is the easiest to get. I took this from web.
Here's the output of the command
keytool -list -keystore <path>
***************** WARNING WARNING WARNING *****************
* The integrity of the information stored in your keystore *
* has NOT been verified! In order to verify its integrity, *
* you must provide your keystore password. *
***************** WARNING WARNING WARNING *****************
Keystore type: JKS Keystore provider: SUN
Your keystore contains 1 entry
androiddebugkey, 15.Mar.2013, PrivateKeyEntry,
Certificate fingerprint (SHA1): xxx
main.xml file:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="AIzaSyDim-x5Gxxx"
/>
manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidhive.googlemaps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<!-- Add Google Map Library -->
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".AndroidGoogleMapsActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<!-- Allow to connect with internet -->
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
java file (no need to paste it all, but I guess it's best to paste it all)
http://pastebin.com/yF95Rcbd
Here are my screenshots:
http://i.imgur.com/gExHpUG.png
http://i.imgur.com/AMOXKhr.png
http://i.imgur.com/Aqon97Y.png
I'm trying to compile this app to Android 4.2.2, but I tried and want to make it work in 2.2 and above.
Here's the Android tab of the properties window just to make sure:
http://i.imgur.com/ht0CQwT.png
Here's my log
03-20 07:01:20.145: W/System.err(956): at java.lang.Thread.run(Thread.java:856)
03-20 07:01:20.665: W/System.err(956): IOException processing: 26
03-20 07:01:20.665: W/System.err(956): java.io.IOException: Server returned: 3
03-20 07:01:20.665: W/System.err(956): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
03-20 07:01:20.675: W/System.err(956): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
03-20 07:01:20.675: W/System.err(956): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
03-20 07:01:20.675: W/System.err(956): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
03-20 07:01:20.675: W/System.err(956): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
These lines repeat all the time.
Thank you very much.
Your post appears to contain code that is not properly formatted as code" error made
me delete the blank lines. Sorry for the messed up codes.
http://i.imgur.com/ht0CQwT.png
See the snapshot. You did not add Google Play Services library that is require for displaying Google Android Map V2. Please download and add that library and then try again.
Please also see the target. Your target is 4.2.2 and your are accessing it on 2.2. Change the target to 2.2 and use support fragment.
Thanks,
I have solved this issue,
Open your Google APIs Console
Choose API Access
Edit allowed Android apps from your API Key
Change the package name with your package name
Example: 00:06:A5:0E:04:A2:1E:8F:FE:6B:7F:46:23:C3:xx:xx:xx:xx:xx:xx;com.example.androidmapview
You are missing permissions and meta-data for API KEY.
Read this carefully: https://developers.google.com/maps/documentation/android/start
Working with android mapapi v2 ,the main reason is you must add play service to your app,like below :
<permission
android:name="com.example.androidmapview.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.androidmapview.permission.MAPS_RECEIVE" />
Use fragment class in Layout:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
And change your manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidmapview"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<permission
android:name="com.example.androidmapview.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.androidmapview.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.androidmapview.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"></meta-data>
</application>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
</manifest>
in activity:
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SupportMapFragment fragment = new SupportMapFragment();
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, fragment).commit();
}
}
For more info check the link which will explain you in details about api v2
I solved my blank screen problem with zoom in/out buttons like that.(it happens after I changed my package name)
Delete the keystore file
Create a new keystore file
Get SHA1 fingerprint
Go to API Console
Create a new Android App.
Paste your fingerprint
Use the given API Key in your Manifest File
That worked for me

Categories