java.lang.ClassCastException: android.app.Application - casting - java

java.lang.ClassCastException: android.app.Application cannot be cast to com.example.project.DataDevice
My code:
public class Project extends Activity{
private boolean connection = false;
public Tag tagFromIntent = null;
private Button textRead;
private NFCForegroundUtil nfcForegroundUtil;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.project);
nfcForegroundUtil = new NFCForegroundUtil(this);
this.textRead= (Button) findViewById(R.id.button2);
initListeners();
}
private void initListeners() {
textRead.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
if (connection == true)
{
DataDevice dataDevice = (DataDevice) getApplication();
dataDevice.setCurrentTag(tagFromIntent);
IsoDep nfca = IsoDep.get(dataDevice.getCurrentTag());
try
{
byte[] read= new byte[] { 0x00};
byte[] ans = null;
nfca.setTimeout(2000);
nfca.connect();
nfca.setTimeout(2000);
if (nfca.isConnected())
{
nfca.setTimeout(2000);
ans = nfca.transceive(read);
try
{
Thread.sleep(1500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
nfca.close();
String textRead = HexBin.encode(ans);
}
catch (IOException e)
{
Log.i("A", "IOException is: " + e.getMessage());
e.printStackTrace();
}
if (nfca.isConnected())
{
try
{
nfca.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
});
}
#Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
action = intent.getAction();
tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
connection = true;
}
public void onPause()
{
super.onPause();
nfcForegroundUtil.disableForeground();
}
public void onResume()
{
super.onResume();
nfcForegroundUtil.enableForeground();
if (!nfcForegroundUtil.getNfc().isEnabled())
{
Toast.makeText(
getApplicationContext(),
"Please activate NFC and press Back to return to the application!",
Toast.LENGTH_LONG).show();
startActivity(new Intent(
android.provider.Settings.ACTION_WIRELESS_SETTINGS));
}
}
}
My manifest code:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.project"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature
android:name="android.hardware.nfc"
android:required="true" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name="android.app.Application">
<activity
android:name=".StartActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:screenOrientation="portrait"
android:name=".Project"
android:label="#string/title_activity_main" />
</application>
My error:
FATAL EXCEPTION: main
java.lang.ClassCastException: android.app.Application cannot be cast to com.example.Project.DataDevice
at com.example.project.Project$1.onClick(Project.java:67)
at android.view.View.performClick(View.java:3511)
at android.view.View$PerformClick.run(View.java:14105)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
DataDevice class:
public class DataDevice extends Application
{
private Tag currentTag;
public void setCurrentTag(Tag currentTag) {
this.currentTag = currentTag;
}
public Tag getCurrentTag() {
return currentTag;
}
//(...)
}
I looked for answer on stackOverflow, nothing helped.
Anyone knows what's going on?
DataDevice and NFCUtilForeground works good (in other applications).

The android:name attribute in application tag in your manifest file should point to your DataDevice class. Like:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name="your.package.DataDevice">
.........
..........
</application>

Related

keep getting error E/MediaRecorder: stop called in an invalid state: 4, I am not sure what is wrong

I tried to use a media recorder, but it keeps giving me errors, I have added permission request and this is my manifest. When I goes to Logcat it says:
2020-04-23 18:23:46.754 12665-12665/com.example.soundmedi E/MediaRecorder: stop called in an invalid state: 4
2020-04-23 18:23:46.754 12665-12665/com.example.soundmedi D/AndroidRuntime: Shutting down VM
2020-04-23 18:23:46.767 12665-12665/com.example.soundmedi E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.soundmedi, PID: 12665
java.lang.IllegalStateException
at android.media.MediaRecorder.stop(Native Method)
at com.example.soundmedi.Activity4$1.onClick(Activity4.java:69)
at android.view.View.performClick(View.java:7125)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27336)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.soundmedi">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<application
android:allowBackup="true"
android:requestLegacyExternalStorage="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=".Activity5"></activity>
<activity android:name=".Activity4" />
<activity android:name=".Activity3" />
<activity android:name=".Activity2" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
package com.example.soundmedi;
import android.Manifest;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import java.io.File;
import java.io.IOException;
public class Activity4 extends AppCompatActivity {
private Button record, stop;
private MediaRecorder mediaRecorder;
private String outputFile;
private boolean permissionToRecordAccepted = false;
private String [] permissions = {Manifest.permission.RECORD_AUDIO};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_4);
record = (Button) findViewById(R.id.record);
stop = (Button) findViewById(R.id.stop);
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, getPackageManager().PERMISSION_GRANTED);
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, getPackageManager().PERMISSION_GRANTED);
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File dir = new File(path + "/soundmedi/");
outputFile = String.valueOf(dir);/**Environment.getExternalStorageDirectory().getAbsolutePath() + "/recording.3gp";*/
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setOutputFile("first.3gp");
mediaRecorder.setOutputFile("/0/Download/soundmedi/");
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
stop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (null != mediaRecorder) {
try{
mediaRecorder.stop();
mediaRecorder.reset();
mediaRecorder.release();
mediaRecorder = null;
Toast.makeText(getApplicationContext(), "done", Toast.LENGTH_LONG).show();
} catch(RuntimeException stopException) {
}
}
}
});
record.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
mediaRecorder.prepare();
mediaRecorder.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();// make something
}
Toast.makeText(getApplicationContext(), "Recording started", Toast.LENGTH_LONG).show();
record.setEnabled(false);
//recording for 10s
/**final Handler handler = new Handler();
final boolean b = handler.postDelayed(new Runnable() {
#Override
public void run() {
}
}, 10000);*/
}
});
}
}
enter image description here

NoClassFound com.google.android.gms.gcm.GcmReceiver on Nexus 5->Android 5.1.1

I am trying to modify and implement GCM (hmkode) in eclipse.I have imported project in eclipse and performed the necessary steps for setup.
http://hmkcode.com/android-google-cloud-messaging-tutorial/
After going through GCM sample on developer.google.com .The link says google includes GcmReceiver class by default.I removed old GcmBroadcastReceiver from hmkode sample and changed GcmMessageHandler to extend GcmListenerService instead of IntentService(in hmkode/original code).
Link:
https://developers.google.com/cloud-messaging/android/client
Problem:
When I try to send message to the client the client crashes with following exception in logcat
E/AndroidRuntime(20573): java.lang.RuntimeException: Unable to instantiate receiver com.google.android.gms.gcm.GcmReceiver: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.gcm.GcmReceiver" on path: DexPathList[[zip file "/data/app/com.hmkcode.android.gcm-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
E/AndroidRuntime(20573):
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2590)
My Class structure-
public class GcmMessageHandler extends GcmListenerService {
String mes;
private Handler handler;
public GcmMessageHandler() {
super();
}
//com.hmkcode.android.gcm.
#Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
handler = new Handler();
}
public void showToast(){
handler.post(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(),mes , Toast.LENGTH_LONG).show();
}
});
}
}
Activity class
public class MainActivity extends Activity implements OnClickListener {
Button btnRegId;
EditText etRegId;
GoogleCloudMessaging gcm;
String regid;
String PROJECT_NUMBER = "164502923904";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnRegId = (Button) findViewById(R.id.btnGetRegId);
etRegId = (EditText) findViewById(R.id.etRegId);
btnRegId.setOnClickListener(this);
}
public void getRegId(){
new AsyncTask<Void, Void, String>() {
#Override
protected String doInBackground(Void... params) {
String msg = "";
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
}
regid = gcm.register(PROJECT_NUMBER);
msg = "Device registered, registration ID=" + regid;
Log.i("GCM", msg);
} catch (IOException ex)
{
msg = "Error :" + ex.getMessage();
}
return msg;
}
#Override
protected void onPostExecute(String msg) {
etRegId.setText(msg + "\n");
}
}.execute(null, null, null);
}
#Override
public void onClick(View v) {
getRegId();
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hmkcode.android.gcm"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.hmkcode.android.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.hmkcode.android.gcm.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name="com.hmkcode.android.gcm.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>
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.hmkcode.android.gcm" />
</intent-filter>
</receiver>
<service android:name="com.hmkcode.android.gcm.GcmMessageHandler" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
Also gcm.jar has been added as dependency and exported.
If you use Eclipse with regular android gcm jar, u need to add com.google.android.gcm.GcmReceiver instead of com.google.android.gcm.GCMBroadcastReceiver. This worked for me (at least temporarily)

Libgdx - IllegalStateException at unknown location

I am using android studio 1.3, and libgdx 1.6.2 to create a game. I want to incorporate google play services to my game and I have completed everything in one step, because I did it before without problem. However, this time it gave me an exception:
java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information.
at com.google.android.gms.common.internal.zzi$zza.zzc(Unknown Source)
at com.google.android.gms.common.internal.zzi$zza.zzr(Unknown Source)
at com.google.android.gms.common.internal.zzi$zzc.zznQ(Unknown Source)
at com.google.android.gms.common.internal.zzi$zzb.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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)
So here is what I changed other than adding baseGameUtils (which was sucessfully added).
EDIT:
The Full Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bearfishapps.cells.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="#string/app_id" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/GdxTheme" >
<activity
android:name="com.example.app.android.AndroidLauncher"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.purplebrain.adbuddiz.sdk.AdBuddizActivity"
android:theme="#android:style/Theme.Translucent" />
</application>
</manifest>
And here is my android main activity.
public class AndroidLauncher extends AndroidApplication implements GameHelper.GameHelperListener{
private GameHelper gameHelper;
#Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (gameHelper == null) {
gameHelper = new GameHelper(this, GameHelper.CLIENT_GAMES);
}
gameHelper.setup(this);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new Cells(new ActionResolver() {
#Override
public boolean getSignedInGPGS() {
return gameHelper.isSignedIn();
}
#Override
public void loginGPGS() {
try {
runOnUiThread(new Runnable() {
public void run() {
gameHelper.beginUserInitiatedSignIn();
}
});
} catch (final Exception ex) {
}
}
#Override
public void submitScoreGPGS(int score) {
Games.Leaderboards.submitScore(gameHelper.getApiClient(), "CgkI6ZHYr9IEEAIQBg", score);
}
#Override
public void getLeaderboardGPGS() {
if (gameHelper.isSignedIn()) {
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(gameHelper.getApiClient(), "CgkI6ZHYr9IEEAIQBg "), 100);
}
else if (!gameHelper.isConnecting()) {
loginGPGS();
}
}
#Override
public void unlockAchievementGPGS(String achievementId) {
Games.Achievements.unlock(gameHelper.getApiClient(), achievementId);
}
#Override
public void getAchievementsGPGS() {
if (gameHelper.isSignedIn()) {
startActivityForResult(Games.Achievements.getAchievementsIntent(gameHelper.getApiClient()), 101);
}
else if (!gameHelper.isConnecting()) {
loginGPGS();
}
}
}), config);
}
#Override
public void onStart(){
super.onStart();
gameHelper.onStart(this);
}
#Override
public void onStop(){
super.onStop();
gameHelper.onStop();
}
#Override
public void onActivityResult(int request, int response, Intent data) {
super.onActivityResult(request, response, data);
gameHelper.onActivityResult(request, response, data);
}
#Override
public void onSignInFailed() {
}
#Override
public void onSignInSucceeded() {
}
}
I can't tell whats wrong here.
Thanks in advance.
You need to use <meta-data> inside your <application> tag in the AndroidManifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bearfishapps.cells.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/GdxTheme" >
<activity
android:name="com.example.app.android.AndroidLauncher"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.purplebrain.adbuddiz.sdk.AdBuddizActivity"
android:theme="#android:style/Theme.Translucent" />
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="#string/app_id" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
Clear your data and uninstall updates on Google Play Services.
Then, reinstall it.

GCM service not avalible

I follow the example of http://hmkcode.com/android-google-cloud-messaging-tutorial/ , every thing is fine but its alway response SERVICE_NOT_AVALIBLE
The device time is correctly setup, package name is correct,too.
could anyone help me in this case
my MainActivity.java
Button btnRegId;
EditText etRegId;
GoogleCloudMessaging gcm;
String regid;
String PROJECT_NUMBER = "943411953393";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnRegId = (Button) findViewById(R.id.btnGetRegId);
etRegId = (EditText) findViewById(R.id.etRegId);
btnRegId.setOnClickListener(this);
}
public void getRegId(){
new AsyncTask<Void, Void, String>() {
#Override
protected String doInBackground(Void... params) {
String msg = "";
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
}
regid = gcm.register(PROJECT_NUMBER);
msg = "Device registered, registration ID=" + regid;
Log.i("GCM", msg);
} catch (IOException ex) {
msg = "Error :" + ex.getMessage();
}
return msg;
}
#Override
protected void onPostExecute(String msg) {
etRegId.setText(msg + "\n");
}
}.execute(null, null, null);
}
#Override
public void onClick(View v) {
getRegId();
}
My AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gmc"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="14" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.example.gmc.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.gmc.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/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>
<receiver
android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.gmc" />
</intent-filter>
</receiver>
<service android:name=".GcmMessageHandler" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
try this
#Override
protected String doInBackground(Void... params) {
String msg = "";
int backoff = 2000;
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
}
}
catch (IOException ex) {
ex.printStackTrace()
}
for(int i=0;i<5;i++){
try {
regid = gcm.register(PROJECT_NUMBER);
msg = "Device registered, registration ID=" + regid;
Log.i("GCM", msg);
break;
}
catch (IOException ex) {
msg = "Error :" + ex.getMessage();
backoff =backoff * 2;
Thread.sleep(backoff);
}
}
return msg;
}
you need to try several attempts increasing the wait time for each try.

Unable to start activity in inner class and activity class

I've got an android project from another developer. He can launch this project on his machine successfully, but when I try to launch it on my machine, I've got this exception when application trying load map in a fragment. The logcat with exception:
09-29 07:37:50.298 2442-2442/nz.co.tish.android.coffeetime E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{nz.co.tish.android.coffeetime/nz.co.tish.android.coffeetime.fragment.MapFragment$InnerActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.startActivityNow(ActivityThread.java:2054)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
at nz.co.tish.android.coffeetime.fragment.MapFragment.onCreate(MapFragment.java:132)
at android.support.v4.app.Fragment.performCreate(Fragment.java:1477)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:893)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
at android.view.View.measure(View.java:15848)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:651)
at android.view.View.measure(View.java:15848)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15848)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:302)
at android.view.View.measure(View.java:15848)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2189)
at android.view.View.measure(View.java:15848)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1905)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1104)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1284)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
at android.app.Activity.setContentView(Activity.java:1895)
at nz.co.tish.android.coffeetime.fragment.MapFragmen
09-29 07:42:50.399 2442-2442/nz.co.tish.android.coffeetime I/Process﹕ Sending signal. PID: 2442 SIG: 9
Android manifest:
android:versionCode="7"
android:versionName="1.3" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.VIBRATE" />
<permission
android:name="nz.co.tish.android.coffeetime.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="nz.co.tish.android.coffeetime.permission.C2D_MESSAGE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:name="nz.co.tish.android.coffeetime.CoffeetimeApplication"
android:allowBackup="true"
android:description="#string/app_desc"
android:icon="#drawable/app_logo57"
android:label="Coffeetime TISH Limited"
android:screenOrientation="portrait"
android:theme="#style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDMx6IbAJEWnHuKv_yv4Pkwgx_U1mF2Qkc" />
<!--Debug: AIzaSyDMx6IbAJEWnHuKv_yv4Pkwgx_U1mF2Qkc-->
<!--Live: AIzaSyCnNpNptAzaBdtF9GOAVw-POo1gt2Tsw-Q-->
<meta-data
android:name="com.google.android.gms.versionCode"
android:value="#integer/google_play_services_version" />
<activity
android:name="nz.co.tish.android.coffeetime.MainActivity"
android:label="#string/title_activity_main"
android:screenOrientation="portrait"
android:theme="#style/AppMainTheme" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.PlaceActivity"
android:label="#string/title_activity_place"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.ForgotPasswordActivity"
android:label="#string/title_activity_forgot_password"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.CVCInfoActivity"
android:label="#string/cvc_text_header"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.CategoryActivity"
android:label="#string/title_activity_category"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="nz.co.tish.android.coffeetime.MainActivity" />
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.ProductActivity"
android:label="#string/title_activity_product"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="nz.co.tish.android.coffeetime.CategoryActivity" />
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.CheckoutActivity"
android:label="#string/title_activity_checkout"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="nz.co.tish.android.coffeetime.PlaceActivity" />
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.TopupActivity"
android:label="#string/title_activity_topup"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.RegisterCardActivity"
android:label="#string/title_activity_register_card"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.StoreMapActivity"
android:label="#string/store_map_title_activity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.AuthActivity"
android:label="#string/title_activity_auth"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.VersionInfoActivity"
android:label="#string/title_activity_version"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="nz.co.tish.android.coffeetime.AuthActivity" />
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.TermsActivity"
android:label="#string/title_activity_terms"
android:screenOrientation="portrait" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="launch.TermsActivity" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="nz.co.tish.android.coffeetime.AuthActivity" />
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.fragment.MapFragment$InnerActivity"
android:screenOrientation="portrait" />
<activity
android:name=".LogoutActivity"
android:label="#string/title_activity_logout"
android:screenOrientation="portrait" />
<activity
android:name=".LikeUsOnFacebookActivity"
android:label="Like Us On Facebook Activity"
android:screenOrientation="portrait" />
</application>
The code of fragment with map(MapFragment):
public class MapFragment extends Fragment implements LocationListener {
private static GoogleMap mapView;
private static final String MAP_ACTIVITY_ID = "map-activity";
private static final String ACTIVITY_MANAGER_BUNDLE_KEY = "activity-manager-bundle-key";
private LocalActivityManager localActivityManager;
private LocationManager locationManager = null;
private Window window;
private ProgressDialog dialog = null;
private String bestProvider = null;
private Criteria criteria = null;
private String keyword = "";
private Place[] places;
private HashMap<String, Place> currentPlaces;
private AsyncTask<Object, Object, CallResult<List<Place>>> location_task;
public static class InnerActivity extends
FragmentActivity {
#Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.fragment_map);
mapView = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.mapv2)).getMap();
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = window.getDecorView();
keyword = ((MainActivity) getActivity()).getSearchString();
locationManager = (LocationManager) view.getContext().getSystemService(
Activity.LOCATION_SERVICE);
if (locationManager == null) {
DialogUtil.showAlert(view.getContext(),
"Sorry, you do not seem to have GPS!");
return null;
}
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
criteria = new Criteria();
bestProvider = locationManager.getBestProvider(criteria, false);
return view;
}
#Override
public void onDestroyView() {
super.onDestroyView();
((ViewGroup) window.getDecorView().getParent()).removeAllViews();
}
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBundle(ACTIVITY_MANAGER_BUNDLE_KEY,
localActivityManager.saveInstanceState());
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = null;
if (savedInstanceState != null) {
bundle = savedInstanceState.getBundle(ACTIVITY_MANAGER_BUNDLE_KEY);
}
localActivityManager = new LocalActivityManager(getActivity(), true);
localActivityManager.dispatchCreate(bundle);
window = localActivityManager.startActivity(MAP_ACTIVITY_ID,
new Intent(getActivity(), InnerActivity.class));
}
#Override
public void onResume() {
super.onResume();
localActivityManager.dispatchResume();
places = ((MainActivity) getActivity()).getPlaces();
location_task = null;
if (places == null) {
AsyncTask<Object, Object, Location> task = new AsyncTask<Object, Object, Location>() {
#Override
protected Location doInBackground(Object... params) {
return locationManager.getLastKnownLocation(bestProvider);
}
#Override
protected void onPostExecute(Location result) {
onLocationChanged(result);
}
};
task.execute();
locationManager.requestLocationUpdates(bestProvider, 1000 * 60 * 5,
25, this);
} else {
setUpMapview(places);
}
}
private void setUpMapview(Place[] places) {
// List<Overlay> mapOverlays = mapView.getOverlays();
Drawable openPlace = this.getResources().getDrawable(R.drawable.opened);
Drawable closedPlace = this.getResources().getDrawable(
R.drawable.closed);
List<GeoPoint> items = new ArrayList<GeoPoint>();
currentPlaces = new HashMap<String, Place>();
mapView.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker coffe) {
if (currentPlaces != null) {
Intent intent = new Intent(getActivity(),
PlaceActivity.class);
intent.putExtra("place",
currentPlaces.get(coffe.getTitle()));
startActivity(intent);
}
}
});
for (Place place : places) {
GeoPoint point = new GeoPoint((int) (place.getLatitude()),
(int) (place.getLongitude()));
items.add(point);
Marker placeMarker = mapView
.addMarker(new MarkerOptions()
.position(
new LatLng(place.getLatitude(), place
.getLongitude()))
.title(place.getName())
.icon(BitmapDescriptorFactory.fromResource(place
.isOpen() ? R.drawable.opened
: R.drawable.closed)));
currentPlaces.put(place.getName(), place);
// itemizedOverlay.addOverlay(overlayitem);
// mapOverlays.add(itemizedOverlay);
}
MapUtils.animateToCenter(mapView, items, false);
}
#Override
public void onPause() {
super.onPause();
localActivityManager.dispatchPause(getActivity().isFinishing());
}
#Override
public void onStop() {
super.onStop();
localActivityManager.dispatchStop();
}
#Override
public void onDestroy() {
super.onDestroy();
localActivityManager.dispatchDestroy(getActivity().isFinishing());
}
#Override
public void onDetach() {
super.onDetach();
localActivityManager = null;
}
private class DialogOverlay extends SimpleItemizedOverlay {
public DialogOverlay(Drawable defaultMarker, MapView mapView) {
super(defaultMarker, mapView);
}
#Override
protected boolean onBalloonTap(int index, OverlayItem item) {
/*
* Intent intent = new Intent(mapView.getContext(),
* PlaceActivity.class); intent.putExtra("place",
* ((DialogOverlayItem)item).getCurrentPlace());
* startActivity(intent);
*/
return true;
}
}
private class DialogOverlayItem extends OverlayItem {
private Place currentPlace;
public DialogOverlayItem(GeoPoint point, String title, String snippet,
Place place) {
super(point, title, snippet);
setCurrentPlace(place);
}
private Place getCurrentPlace() {
return currentPlace;
}
private void setCurrentPlace(Place currentPlace) {
this.currentPlace = currentPlace;
}
}
}
fragment_map.xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapv2"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
MainActivity:
public class MainActivity extends FragmentActivity implements
ActionBar.TabListener {
private ListView mDrawerList;
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
private CharSequence mDrawerTitle;
private CharSequence mTitle;
private SectionsPagerAdapter mSectionsPagerAdapter;
CustomViewPager mViewPager;
private Place[] places;
private String keyword = "";
private boolean checkedOut;
public Place[] getPlaces() {
return places;
}
public void setPlaces(Place[] places) {
this.places = places;
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return new MyFavoritesFragment();
case 1:
return new NearMeFragment();
case 2:
return new MapFragment();
case 3:
return new HistoryFragment(checkedOut);
case 4:
return new WalletFragment();
}
return null;
}
#Override
public int getCount() {
return 5;
}
public int getPageIcon(int position) {
switch (position) {
case 0:
return R.drawable.icon_fav;
case 1:
return R.drawable.icon_near;
case 2:
return R.drawable.icon_map;
case 3:
return R.drawable.icon_hist;
case 4:
return R.drawable.icon_wallet;
}
return 0;
}
#Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return getString(R.string.title_activity_my_favorites).toUpperCase();
case 1:
return getString(R.string.title_activity_near_me).toUpperCase();
case 2:
return getString(R.string.title_activity_map).toUpperCase();
case 3:
return getString(R.string.title_activity_history).toUpperCase();
case 4:
return getString(R.string.title_activity_wallet).toUpperCase();
}
return null;
}
}
}
This application also has another Activity with map , and the app is crashing on it too. The logcat:
09-29 08:33:50.559 2604-2604/nz.co.tish.android.coffeetime E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{nz.co.tish.android.coffeetime/nz.co.tish.android.coffeetime.StoreMapActivity}: android.view.InflateException: Binary XML file line #3: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4242000 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
at com.google.android.gms.maps.internal.q.v(Unknown Source)
at com.google.android.gms.maps.internal.q.u(Unknown Source)
at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment$b.ex(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
at com.google.android.gms.dynamic.a.a(Unknown Source)
at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
           
StoreMapActivity:
public class StoreMapActivity extends FragmentActivity {
private Place place = null;
private GoogleMap mapView;
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return (true);
}
return (super.onOptionsItemSelected(item));
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.store_map_activity);
mapView = (GoogleMap) ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.store_mapv2)).getMap();
Serializable placeSer = getIntent().getSerializableExtra("place");
if (placeSer == null
|| !Place.class.isAssignableFrom(placeSer.getClass())) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
return;
}
place = (Place) placeSer;
setUpMapview();
/*List<Overlay> mapOverlays = mapView.getOverlays();
Drawable openPlace = this.getResources().getDrawable(R.drawable.opened);
Drawable closedPlace = this.getResources().getDrawable(
R.drawable.closed);
List<GeoPoint> items = new ArrayList<GeoPoint>();
SimpleItemizedOverlay itemizedOverlay = new SimpleItemizedOverlay(
place.isOpen() ? openPlace : closedPlace, mapView);
GeoPoint point = new GeoPoint(
(int) (place.getLatitude() * Const.GEOPOINT_CONST),
(int) (place.getLongitude() * Const.GEOPOINT_CONST));
items.add(point);
OverlayItem overlayitem = new OverlayItem(point, place.getName(), "");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
// MapUtils.animateToCenter(mapView, items, true);*/
}
private void setUpMapview() {
Drawable openPlace = this.getResources().getDrawable(R.drawable.opened);
Drawable closedPlace = this.getResources().getDrawable(
R.drawable.closed);
List<GeoPoint> items = new ArrayList<GeoPoint>();
mapView.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker coffe) {
if (place != null) {
Intent intent = new Intent(StoreMapActivity.this,
PlaceActivity.class);
intent.putExtra("place", place);
startActivity(intent);
}
}
});
GeoPoint point = new GeoPoint((int) (place.getLatitude()),(int)(place.getLongitude()));
items.add(point);
Marker placeMarker = mapView.addMarker(new MarkerOptions().position(
new LatLng(place.getLatitude(), place.getLongitude()))
.title(place.getName())
.icon(BitmapDescriptorFactory.fromResource(place
.isOpen() ? R.drawable.opened
: R.drawable.closed)));
MapUtils.animateToCenter(mapView, items, false);
}
}
store_map_activity.xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/store_mapv2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
When I commented the code initializing the maps on these parts of application, it will start working normally.
Please verify that you have added the exceptions to your proguard configuration file. How and what to add is explained in Setting up Google Play Services
For the first, change your fragment from this:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapv2"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
to this:
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
the main difference in this case is
class="com.google.android.gms.maps.SupportMapFragment"
to this:
android:name="com.google.android.gms.maps.SupportMapFragment"
For the second: add the following to the end of your manifest (but beforde the end-tag application!)
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
In your code you can ask for the service with the following:
// check status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
try {
if (status != ConnectionResult.SUCCESS)
{
GooglePlayServicesUtil.getErrorDialog(status, this, RQS_GooglePlayServices).show();
}
} catch (Exception e) {
Log.e("Error: ", + e);
}

Categories

Resources