This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 2 years ago.
Build version: 2.9
Build date: 1979-11-30 00:00:00
Current date: 2020-12-12 17:01:30
Device: Samsung SM-N970U
OS version: Android 10 (SDK 29)
Stack trace:
java.lang.RuntimeException: Unable to destroy activity {com.jmctstudios.vibe/com.jmctstudios.vibe.ActivitiesFragment.Splash_A}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.CountDownTimer.cancel()' on a null object reference
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5456)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5493)
at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:44)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.CountDownTimer.cancel()' on a null object reference
at com.jmctstudios.vibe.ActivitiesFragment.Splash_A.onDestroy(Splash_A.java:83)
at android.app.Activity.performDestroy(Activity.java:8225)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1342)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5441)
... 11 more
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.jmctstudios.vibe">
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature
android:name="android.hardware.camera2.full"
android:required="false" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.MANAGE_DOCUMENTS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:name=".SimpleClasses.VIBE"
android:allowBackup="false"
android:hardwareAccelerated="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:networkSecurityConfig="#xml/network_security_config"
android:requestLegacyExternalStorage="true"
android:roundIcon="#mipmap/ic_launcher"
android:screenOrientation="portrait"
android:supportsRtl="false"
android:theme="#style/AppTheme"
tools:replace="allowBackup,supportsRtl">
<activity android:name=".ActivitiesFragment.Accounts.Forgot_Pass_A"
android:theme="#style/transparent_status"/>
<activity
android:name=".ActivitiesFragment.Video_Recording.Trim_video_A"
android:theme="#style/black_status" />
<activity
android:name=".ActivitiesFragment.Video_Recording.Video_Recoder_Duet_A"
android:theme="#style/black_status" />
<activity
android:name="cat.ereza.customactivityoncrash.activity.DefaultErrorActivity"
android:process=":error_activity"
android:theme="#style/error_activity_theme" />
<activity
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:screenOrientation="portrait"
android:theme="#style/Base.Theme.AppCompat"
tools:ignore="LockedOrientationActivity" />
<activity android:name=".ActivitiesFragment.SoundLists.VideoSound_A" />
<activity
android:name=".ActivitiesFragment.Video_Recording.DraftVideos_A"
android:screenOrientation="portrait"
android:theme="#style/white_status"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".ActivitiesFragment.Video_Recording.GallerySelectedVideo_A"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".ActivitiesFragment.Accounts.Login_A"
android:screenOrientation="portrait"
android:theme="#style/Transparent"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".ActivitiesFragment.Splash_A"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Main_Menu.MainMenuActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="#style/transparent_status"
android:windowSoftInputMode="stateAlwaysHidden|adjustNothing"
tools:ignore="LockedOrientationActivity"/>
<activity
android:name=".ActivitiesFragment.WatchVideos_F"
android:parentActivityName=".Main_Menu.MainMenuActivity"
android:screenOrientation="portrait"
android:theme="#style/transparent_status"
android:windowSoftInputMode="stateAlwaysHidden|adjustNothing"
tools:ignore="LockedOrientationActivity">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="bringthings.com"
android:scheme="http" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.jmctstudios.vibe.Main_Menu.MainMenuActivity" />
</activity>
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="#string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<activity
android:name=".ActivitiesFragment.Video_Recording.Video_Recoder_A"
android:screenOrientation="portrait"
android:theme="#style/black_status"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".ActivitiesFragment.Video_Recording.Preview_Video_A"
android:screenOrientation="portrait"
android:theme="#style/black_status"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".ActivitiesFragment.Video_Recording.Post_Video_A"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".ActivitiesFragment.SoundLists.SoundList_Main_A"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="#string/ad_app_id"/>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/ic_tic" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/redcolor" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
<service
android:name=".Services.Upload_Service"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="startservice" />
</intent-filter>
</service>
<service android:name=".Firebase_Notification.Notification_Receive">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
</application>
</manifest>
package com.jmctstudios.vibe.ActivitiesFragment;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.CountDownTimer;
import androidx.appcompat.app.AppCompatActivity;
import android.provider.Settings;
import android.view.Window;
import android.view.WindowManager;
import com.jmctstudios.vibe.Main_Menu.MainMenuActivity;
import com.jmctstudios.vibe.R;
import com.jmctstudios.vibe.ApiClasses.ApiLinks;
import com.jmctstudios.vibe.ApiClasses.ApiRequest;
import com.jmctstudios.vibe.Interfaces.Callback;
import com.jmctstudios.vibe.SimpleClasses.Variables;
import org.json.JSONException;
import org.json.JSONObject;
public class Splash_A extends AppCompatActivity {
CountDownTimer countDownTimer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
Variables.sharedPreferences = getSharedPreferences(Variables.pref_name, MODE_PRIVATE);
if(Variables.sharedPreferences.getString(Variables.device_id,"0").equals("0")) {
Call_api_register_device();
}
else
Set_Timer();
}
public void Set_Timer(){
countDownTimer = new CountDownTimer(2500, 500) {
public void onTick(long millisUntilFinished) {
// this will call on every 500 ms
}
public void onFinish() {
Intent intent=new Intent(Splash_A.this, MainMenuActivity.class);
if(getIntent().getExtras()!=null) {
intent.putExtras(getIntent().getExtras());
setIntent(null);
}
startActivity(intent);
overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
finish();
}
}.start();
}
#Override
protected void onDestroy() {
countDownTimer.cancel();
super.onDestroy();
}
public void Call_api_register_device(){
String androidId = Settings.Secure.getString(getContentResolver(),
Settings.Secure.ANDROID_ID);
JSONObject param=new JSONObject();
try {
param.put("key",androidId);
} catch (JSONException e) {
e.printStackTrace();
}
ApiRequest.Call_Api(this, ApiLinks.registerDevice, param, new Callback() {
#Override
public void Responce(String resp) {
try {
JSONObject jsonObject=new JSONObject(resp);
String code=jsonObject.optString("code");
if(code.equals("200")){
Set_Timer();
JSONObject msg=jsonObject.optJSONObject("msg");
JSONObject Device=msg.optJSONObject("Device");
SharedPreferences.Editor editor2 = Variables.sharedPreferences.edit();
editor2.putString(Variables.device_id, Device.optString("id")).commit();
}else {
Call_api_show_register_device();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
public void Call_api_show_register_device(){
String androidId = Settings.Secure.getString(getContentResolver(),
Settings.Secure.ANDROID_ID);
JSONObject param=new JSONObject();
try {
param.put("key",androidId);
} catch (JSONException e) {
e.printStackTrace();
}
ApiRequest.Call_Api(this, ApiLinks.showDeviceDetail, param, new Callback() {
#Override
public void Responce(String resp) {
try {
JSONObject jsonObject=new JSONObject(resp);
String code=jsonObject.optString("code");
if(code.equals("200")){
Set_Timer();
JSONObject msg=jsonObject.optJSONObject("msg");
JSONObject Device=msg.optJSONObject("Device");
SharedPreferences.Editor editor2 = Variables.sharedPreferences.edit();
editor2.putString(Variables.device_id, Device.optString("id")).commit();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
}
Your object is null during onDestroy, maybe wrap it around a check like
#Override
protected void onDestroy() {
super.onDestroy();
if (countDownTimer!=null) {
countDownTimer.cancel();
}
}
Related
This question already has answers here:
What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?
(18 answers)
Closed 1 year ago.
I'm integrating admob ads in my application with java but getting this
cannot find symbol mInterstitialAd = new InterstitialAd(this); symbol:
variable mInterstitialAd location: class Ads
. Please check the util/Ads.java & AndroidManifest.xml file and help me to fix it. I'm not able to fix this.
util/Ads.java
package com.indiapps.documentscanner.util;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import com.google.android.gms.ads.InterstitialAd;
public class Ads {
public static void showAds(Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
long currentTimeMillis = System.currentTimeMillis();
long lastTime = sharedPreferences.getLong("lastTime", 0);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
if (currentTimeMillis - lastTime > 60000) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putLong("lastTime", currentTimeMillis);
editor.apply();
Log.d("AAA","showAds");
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.indiapps.documentscanner">
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:requestLegacyExternalStorage="true"
android:name="com.MainApplication"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="#string/admod_app_id"/>
<!-- HUNGDH -->
<activity
android:name="com.indiapps.documentscanner.camscanner.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:noHistory="true" />
<activity
android:name="com.facebook.ads.AudienceNetworkActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:noHistory="true" />
<meta-data
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="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/file_paths" />
</provider>
<activity
android:name="com.indiapps.documentscanner.camscanner.MyPDFActivity"
android:label="#string/my_pdf"
android:theme="#style/AppTheme" />
<activity
android:name="com.indiapps.documentscanner.camscanner.FilterImageActivity"
android:label="#string/filter_image"
android:theme="#style/AppTheme" />
<activity
android:name="com.indiapps.documentscanner.camscanner.KnifeActivity"
android:theme="#style/AppTheme"
android:windowSoftInputMode="adjustResize|stateHidden" />
<activity
android:name="com.indiapps.documentscanner.camscanner.MySettingsActivity"
android:label="#string/action_settings"
android:theme="#style/AppTheme" />
<!-- DOCUMENT SCANNER -->
<activity
android:name="com.gpaddyv1.documentscanner.activities.SimpleDocumentScannerActivity"
android:label="#string/from_gallery"
android:theme="#style/AppTheme" />
<!-- IMAGE TO PDF -->
<activity
android:name="com.gun0912.tedpicker.ImagePickerActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme_picker" />
<!-- OPEN NOTE SCANNER -->
<activity
android:name=".OpenNoteScannerActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/title_activity_open_note_scanner"
android:screenOrientation="portrait"
android:theme="#style/FullscreenTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".GalleryGridActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/my_gallery"
android:screenOrientation="portrait"
android:theme="#style/FullscreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".FullScreenViewActivity"
android:theme="#style/FullscreenTheme" />
<activity
android:name=".SettingsActivity"
android:label="#string/settings"
android:theme="#style/AppTheme" />
<!-- PHOTO EDITOR -->
<activity android:name="com.gpaddyv1.documentscanner.process.view.ProcessImageActivity" />
<activity android:name="com.joshuabutton.queenscanner.sign.view.SignActivity" />
<activity android:name="com.joshuabutton.queenscanner.process.view.CombineBitMapActivity" />
<activity android:name="com.gpaddyv1.documentscanner.document.DocumentActivity" />
<activity android:name="com.joshuabutton.queenscanner.handle.HandleActivity" />
<activity android:name="com.indiapps.documentscanner.listdoc.DocsActivity" />
<activity
android:name=".AccountActivity"
android:theme="#style/AppTheme.NoActionBar1">
</activity>
</application>
</manifest>
You forgot to declare mIntersitialAd, you can do that right after the class opening braces.
public class Ads {
private InterstitialAd mInterstitialAd;
public static void showAds(Context context) {
//your code
}
}
I am trying to add snap-kit in my application and I have integrated everything as their documentation. App successfully launched Snapchat app but it's not login it shows an error Something is wrong Here is my complete code and other implementation. This is the official documentation that I have followed https://kit.snapchat.com/docs/login-kit-android
MainActivity
public class MainActivity extends AppCompatActivity {
private ActivityMainBinding binding;
private static final String TAG = "MAIN_ACTIVITY";
String query = "{me{bitmoji{avatar},displayName}}";
String variables = null;
boolean isUserLoggedIn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
isUserLoggedIn = SnapLogin.isUserLoggedIn(this);
if (isUserLoggedIn)
binding.btnLogin.setText("Logout");
else
binding.btnLogin.setText("Logout");
binding.btnLogin.setOnClickListener(v -> {
SnapLogin.getAuthTokenManager(this).startTokenGrant();
binding.progress.setVisibility(View.VISIBLE);
});
SnapLogin.getLoginStateController(this).addOnLoginStateChangedListener(mLoginStateChangedListener);
SnapLogin.fetchUserData(this, query, null, new FetchUserDataCallback() {
#Override
public void onSuccess(#Nullable UserDataResponse userDataResponse) {
if (userDataResponse == null || userDataResponse.getData() == null) {
return;
}
MeData meData = userDataResponse.getData().getMe();
if (meData == null) {
return;
}
binding.txtName.setText(userDataResponse.getData().getMe().getDisplayName());
if (meData.getBitmojiData() != null) {
Glide.with(MainActivity.this)
.load(meData.getBitmojiData().getAvatar())
.into(binding.imgProfile);
}
}
#Override
public void onFailure(boolean isNetworkError, int statusCode) {
}
});
}
final LoginStateController.OnLoginStateChangedListener mLoginStateChangedListener =
new LoginStateController.OnLoginStateChangedListener() {
#Override
public void onLoginSucceeded() {
// Here you could update UI to show login success
binding.progress.setVisibility(View.VISIBLE);
Log.d(TAG, "onLoginSucceeded: ");
binding.btnLogin.setText("Logout");
}
#Override
public void onLoginFailed() {
// Here you could update UI to show login failure
binding.progress.setVisibility(View.VISIBLE);
Log.d(TAG, "onLoginFailed: ");
}
#Override
public void onLogout() {
// Here you could update UI to reflect logged out state
binding.progress.setVisibility(View.VISIBLE);
Log.d(TAG, "onLogout: ");
}
};
}
Manifests
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iotait.snapchatandroid">
<uses-permission android:name="android.permission.INTERNET" />
<queries>
<package android:name="com.snapchat.android" />
</queries>
<application
android:name=".application.AppController"
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.SnapchatAndroidDemo">
<meta-data
android:name="com.snapchat.kit.sdk.clientId"
android:value="**********************" />
<meta-data
android:name="com.snapchat.kit.sdk.redirectUrl"
android:value="*********************" />
<meta-data
android:name="com.snapchat.kit.sdk.scopes"
android:resource="#array/snap_connect_scopes" />
<activity android:name=".ui.sign.SigninActivity"
android:screenOrientation="nosensor"/>
<activity android:name=".ui.intro.IntroActivity"
android:screenOrientation="nosensor"/>
<activity android:name=".ui.login.LoginActivity"
android:screenOrientation="nosensor"/>
<activity
android:name=".ui.splash.SplashActivity"
android:screenOrientation="nosensor"
android:theme="#style/Theme.splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.MainActivity"
android:screenOrientation="nosensor" />
<activity
android:name="com.snapchat.kit.sdk.SnapKitActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="lmk"
android:path="/oauth2"
android:scheme="lmk" />
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
</application>
</manifest>
Dependencies
implementation([
'com.snapchat.kit.sdk:login:1.1.4',
'com.snapchat.kit.sdk:core:1.1.4'
])
You need to add these line in the application tag
<meta-data android:name="com.snapchat.kit.sdk.clientId" android:value="1aab4ace-3f06-487d-bc85************"/>
<meta-data android:name="com.snapchat.kit.sdk.redirectUrl" android:value="https:********"/>
<meta-data android:name="com.snapchat.kit.sdk.scopes" android:resource="#array/snap_connect_scopes"/>
Use like this
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iotait.snapchatandroid">
<uses-permission android:name="android.permission.INTERNET" />
<queries>
<package android:name="com.snapchat.android" />
</queries>
<application
android:name=".application.AppController"
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.SnapchatAndroidDemo">
<meta-data android:name="com.snapchat.kit.sdk.clientId" android:value="1aab4ace-3f06-487d-bc85************"/>
<meta-data android:name="com.snapchat.kit.sdk.redirectUrl" android:value="https:********"/>
<meta-data android:name="com.snapchat.kit.sdk.scopes" android:resource="#array/snap_connect_scopes"/>
<activity android:name=".intro.IntroActivity"/>
<activity android:name=".login.LoginActivity"/>
<activity
android:name=".splash.SplashActivity"
android:theme="#style/Theme.splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
<activity
android:name="com.snapchat.kit.sdk.SnapKitActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="lmk" android:host="lmk" android:path="/oauth2"/>
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
</application>
</manifest>
This is my GPS service that I'm using to obtain GPS coordinates in the background. I have logged at various areas of the code to see which bits are being called and which aren't. This service is called from a button being clicked. Nothing seems to be logged for the location and the main issue is regarding the location updates which is not returning anything.
public class SetGPS extends Service {
private LocationListener listener;
private LocationManager locationManager;
#Nullable
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
//this is logged successfully
Log.i("LocationListener","is called");
listener = new LocationListener() {
#Override
public void onLocationChanged(Location location) {
Intent i = new Intent("location_update");
i.putExtra("coordinates", location.getLongitude() + " " + location.getLatitude());
sendBroadcast(i);
String latitude = String.valueOf(location.getLatitude());
//this is NOT logged successfully
Log.i("coordinates SetGPS",latitude);
}
#Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
#Override
public void onProviderEnabled(String s) {
}
#Override
public void onProviderDisabled(String s) {
Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
//this is NOT logged successfully
Log.i("onProviderDisabled","is logged");
}
};
locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
try {
//does NOT successfully log
Log.i("testing","testing");
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 0, listener);
}
catch (SecurityException e){
e.printStackTrace();
}
}
#Override
public void onDestroy() {
super.onDestroy();
if(locationManager != null){
locationManager.removeUpdates(listener);
}
}
}
And here is my manifest file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a_phi.nowswap">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.WRITE_CONTACTS"
android:required="true" />
<uses-permission
android:name="android.permission.READ_CONTACTS"
android:required="true" />
<meta-data
android:name="firebase_crash_collection_enabled"
android:value="false" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<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">
<service
android:name=".HceService"
android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE">
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
</intent-filter>
<meta-data
android:name="android.nfc.cardemulation.host_apdu_service"
android:resource="#xml/apduservice" />
</service>
<service android:name=".SetGPS"
android:permission="android.permission.ACCESS_FINE_LOCATION"/>
<activity
android:name=".LoginActivity"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
<data android:scheme="file" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.CATEGORY_DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Pilot"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
<data android:scheme="file" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.CATEGORY_DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".personalHome"
android:label="#string/title_activity_personal_home"
android:theme="#style/AppTheme.NoActionBar"></activity>
<activity
android:name=".ProfessionalHome"
android:label="professionalHome"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.CATEGORY_DEFAULT" />
<data android:mimeType="text/plain`" />
<data android:scheme="file" />
</intent-filter>
</activity>
<activity
android:name=".EditDetailsPersonal"
android:label="editDetails"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".EditDetailsProfessional"
android:label="editDetailsProfessional"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".receivedContact"
android:label="#string/title_activity_received_contact"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".RegisterActivity"
android:label="RegisterActivity"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".AddContact"
android:label="#string/add_contact_button"
android:theme="#style/Theme.AppCompat.Light" />
<activity
android:name=".DrawerActivity"
android:label="#string/title_activity_drawer"
android:theme="#style/Theme.AppCompat.DayNight.DarkActionBar"></activity>
</application>
</manifest>
It returns the following stacktrace.
08-31 11:44:47.710 1399-1411/? W/System.err: java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.
at com.android.server.LocationManagerService.checkResolutionLevelIsSufficientForProviderUse(LocationManagerService.java:1321)
at com.android.server.LocationManagerService.getProviderProperties(LocationManagerService.java:2334)
at android.location.ILocationManager$Stub.onTransact(ILocationManager.java:378)
at com.android.server.HwLocationManagerService.onTransact(HwLocationManagerService.java:379)
08-31 11:44:47.711 1399-1411/? W/System.err: at android.os.Binder.execTransact(Binder.java:565)
08-31 11:44:47.712 1399-2192/? W/System.err: java.lang.SecurityException: "network" location provider requires ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission.
at com.android.server.LocationManagerService.checkResolutionLevelIsSufficientForProviderUse(LocationManagerService.java:1324)
at com.android.server.LocationManagerService.getProviderProperties(LocationManagerService.java:2334)
at android.location.ILocationManager$Stub.onTransact(ILocationManager.java:378)
at com.android.server.HwLocationManagerService.onTransact(HwLocationManagerService.java:379)
at android.os.Binder.execTransact(Binder.java:565)
08-31 11:45:06.132 17192-17192/com.example.a_phi.nowswap W/System.err: java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.
at android.os.Parcel.readException(Parcel.java:1665)
at android.os.Parcel.readException(Parcel.java:1618)
at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:614)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:952)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:536)
at com.example.a_phi.nowswap.SetGPS.onCreate(SetGPS.java:72)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3350)
at android.app.ActivityThread.-wrap5(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1670)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6623)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
which indicates there is an issue with
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 0, listener);
I am doing a chat application . In the app i have to do chatting with help of push notifications using parse andorid sdk. I am successfull to generate push notications between different users . But not able to recieve push and add their data in list view . Here is code of maifest file
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:name="example.chat.ChatApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.facebook.LoginActivity"
android:label="#string/app_name" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/app_id" />
<activity
android:name="example.chat.LoginActivity"
android:label="#string/app_name"
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="example.chat.FriendslIst"
android:label="Friend list"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="example.chat.RegisterActivity"
android:label="#string/title_activity_register"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="example.chat.FriendListActivity"
android:label="#string/title_activity_friend_list"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="example.chat.ChatActivity"
android:label="#string/title_activity_chat"
android:screenOrientation="portrait" >
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.RECEIVE_BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="example.chat.MyCustomReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="example.chat.UPDATE_STATUS" />
</intent-filter>
</receiver>
</application>
and code for my custom reciever
public class MyCustomReceiver extends BroadcastReceiver {
private static final String TAG = "MyCustomReceiver";
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, ""+intent, Toast.LENGTH_LONG).show();
}
}
and from java code I am sending push like this :
ParseQuery<ParseInstallation> query = ParseInstallation.getQuery();
query.whereEqualTo("device_id", target);
ParsePush push = new ParsePush();
push.setQuery(query);
push.setMessage(message);
push.setExpirationTimeInterval(86400);
push.sendInBackground();
Please tell me where I am wrong for recieving data using reciever and what to do when i recive push means any logic or idea to move further . Thanks in advance
here is the manifiest file.....
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your package name"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="your package name.YourActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.RECEIVE_BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="your package name.YourCustomReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="your package name.UPDATE_STATUS" />
</intent-filter>
</receiver>
</application>
</manifest>
use this code to receive the push...
public class MyCustomReceiver extends BroadcastReceiver {
String title, from, msg;
#Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
String message = extras != null ? extras.getString("com.parse.Data")
: "";
Log.e("message ", " " + message);
JSONObject jObject;
try {
if (message != null && !message.equals("")) {
jObject = new JSONObject(message);
from = jObject.getString("from");
msg = jObject.getString("title");
title = jObject.getString("msg");
GCMMessage gcmMessage = new GCMMessage();
gcmMessage.setMsg_body(msg);
gcmMessage.setMsg_title(title);
gcmMessage.setType(0);
gcmMessage.setDateTime(time);
DatabaseUtil.insertMessage(context, gcmMessage);
}
}
catch (JSONException e) {
e.printStackTrace();
}
}
}
and here is the code to send push...
JSONObject obj;
try {
obj =new JSONObject();
obj.put("alert","oman expert ");
obj.put("action","Your Package name.UPDATE_STATUS");
data.put("from", ParseUser.getCurrentUser().getUsername());
obj.put("msg","hi");
obj.put("title","msg");
ParsePush push = new ParsePush();
ParseQuery query = ParseInstallation.getQuery();
push.setQuery(query);
push.setData(obj);
push.sendInBackground();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for any further query please let me know....
In the above code example, you have missed out few things,
Check your AndroidManifest.xml file, and add c2dm permissions,
permission android:name="your package.permission.C2D_MESSAGE" android:protectionLevel="signature"
uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"
uses-permission android:name="your package.permission.C2D_MESSAGE"
While sending the data, set the action in your data,
JSONObject data = new JSONObject();
try {
data.put("action", "your package.GOT_MESSAGE");
data.put("ya", ya);
data.put("from", ParseUser.getCurrentUser().getUsername());
}catch (Exception e){
e.printStackTrace();
return;
}
ParsePush parsePush = new ParsePush();
parsePush.setData(data);
manifest code for the built in search, using the searchview.
can anyone tell me please what is wrong with it?
the SearchableActivity is created in the scr -> presentation, and it is using an xml layout called search.xml. I am new to android and can't find out what is wrong with my code. when launching the search view typing a word and press on "Go" on the keyboard the debugger opens a ActivityThread.perfor.... and tells me source not found.
here is my hole manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="myTV.Android"
android:versionCode="4"
android:versionName="1.12" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="12" />
<uses-feature
android:name="com.google.android.tv"
android:required="true" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:icon="#drawable/mytv"
android:label="#string/app_name"
android:theme="#style/Theme.Transparent" >
<activity android:name="myTV.Presentation.Main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="myTV.Presentation.Player" >
</activity>
<activity android:name="myTV.Presentation.VODCatalogGenre" >
</activity>
<activity android:name="myTV.Presentation.VODCatalog" >
</activity>
<activity android:name="myTV.Presentation.HomePage" >
</activity>
<activity android:name="myTV.Presentation.Programs" >
</activity>
<activity android:name="myTV.Presentation.Episodes" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
</activity>
<activity android:name="myTV.Presentation.ChannelsListing" >
</activity>
<activity android:name="myTV.Presentation.Packages" >
</activity>
<activity android:name="myTV.Presentation.SpecialOfferContent" >
</activity>
<activity android:name="myTV.Presentation.linkedpage" >
</activity>
<activity android:name="myTV.Presentation.howtolinkdevice" >
</activity>
<activity android:name="myTV.Presentation.OnlineRegister" >
</activity>
<activity android:name="myTV.Presentation.SpecialOffer" >
</activity>
<activity android:name="myTV.Presentation.MyVOD" >
</activity>
<activity android:name="myTV.Presentation.SearchEpisodes" >
</activity>
<activity android:name=".Countries" />
<activity android:name=".Genres" />
<activity android:name=".WeeklyRecap" />
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchableActivity" />
<activity android:name=".SearchableActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
</application>
import myTV.Android.R;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
public class SearchableActivity extends Activity{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
// Get the intent, verify the action and get the query
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doMySearch(query);
}
}
public void doMySearch(String query){
//new Request().Search(query);
//new SearchEpisodes().Search(query);
Context context = getApplicationContext();
CharSequence text = query;
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}
Here is my searchable.xml:
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/app_name"
android:hint="#string/SearchHint" >
</searchable>
Try adding the below in your <intent-filter>.
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
I think, your activity is not visible outside your Application.
Try android:exported="true".