gpt4 book ai didi

启用推送通知时,Android 应用程序突然崩溃

转载 作者:太空宇宙 更新时间:2023-11-03 11:57:46 26 4
gpt4 key购买 nike

当我关闭我的应用程序并等待一段时间时,我收到一条警告,提示“应用程序名称已停止”。这只会在我添加接收器和服务标签后发生,您可以在下面的代码中看到。如果我删除它们,这不会发生,但我没有收到推送通知。我使用来自 parse.com 的推送通知,因此 GCM 的权限和其他内容稍后添加。

 <?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="4" android:versionName="1.3.0" android:windowSoftInputMode="adjustPan" package="com.guessSound.guessSound" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<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.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application android:debuggable="false" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="GuessThisSound" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar">
<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.USER_PRESENT" />
<!-- <category android:name="com.guessSound.guessSound" /> -->
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.android.vending.BILLING" />
</manifest>

更新

如果我使用下面的代码,将不会显示警报。所以它实际上只是导致错误的服务标签。 com.parse.PushService 是来自 parse.jar 的文件

 <manifest android:hardwareAccelerated="true" android:versionCode="4" android:versionName="1.3.0" android:windowSoftInputMode="adjustPan" package="com.guessSound.guessSound" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<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.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<application android:debuggable="false" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="GuessThisSound" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.android.vending.BILLING" />
</manifest>

更新 2.0这是我的 log cat,我对使用 log cat 很菜鸟,因为我是从终端使用它的,所以我不知道如何过滤。我希望这能让我对可能发生的事情有所了解

D/widget  (23903): [MSC_HERO_Accu_JB]>>> WC:975 [0:0]  onResume :: fU = true  cEUi = false
D/widget (23903): [MSC_HERO_Accu_JB]>>> WC:2165 [0:0] AR_S_T : 3
D/widget (23903): [MSC_HERO_Accu_JB]>>> WC:1011 [0:0] onResume :: mFAR = false, cC = false, cEUI = false
D/widget (23903): [MSC_HERO_Accu_JB]>>> WC:1329 [0:0] cUI : cnt = 1, mRC = true
D/widget (23903): [MSC_HERO_Accu_JB]>>> WC:1477 [0:0] MSL : cityId:current mCL : [CityListItem >>
D/widget (23903): CityListItemgetCity() = Rosenborg
D/widget (23903): CityListItemgetLocation() = cityId:current
D/widget (23903): CityL

D/widget (23903): [MSC_HERO_Accu_JB]>>> WC:1477 [1:128] istItemgetLatitude() = 634343143
D/widget (23903): CityListItemgetLongitude() = 104151998
D/widget (23903): CityListItemgetProvider() = 1
D/widget (23903): CityListItemgetState() = S
D/widget (23903): [MSC_HERO_Accu_JB]>>> WC:1477 [2:256] or-Trondelag, Norway
D/widget (23903): CityListItemgetRealLocation() =cityId:255551
D/widget (23903): ]
D/Launcher(23903): ACCESSIBILITY-talkback: false
D/Launcher.HomeFragment(23903): onResume
D/MenuAppsGridFragment(23903): onResume
D/Launcher(23903): onTrimMemory. Level: 15
D/AbsListView(23903): unregisterIRListener() is called
E/EnterpriseContainerManager( 2347): ContainerPolicy Service is not yet ready!!!
D/EnterpriseDeviceManager( 2347): ContainerId: 0
W/InputMethodManagerService( 2347): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4394bba8 attribute=android.view.inputmethod.EditorInfo@431f3630, token = android.os.BinderProxy@42fbc8b0
W/LicenseLogService( 2347): log() is called by non admin
D/widget (23903): [MSC_HERO_Accu_JB]>>> U:127 [0:0] widget 1396278960000
D/widget (23903): [MSC_HERO_Accu_JB]>>> WC:2118 [0:0] nt=1396278960000
D/widget (23903): [MSC_HERO_Accu_JB]>>> WC:2119 [0:0] [ARH] now = [1396260420042] lt = [1396278960000] need RF = [false]
D/widget (23903): [MSC_HERO_Accu_JB]>>> WC:2124 [0:0] nt - now =18539958
D/widget (23903): [MSC_HERO_Accu_JB]>>> WC:2125 [0:0] now : 14/03/31 12:07:00 lt : 14/03/31 17:16:00
D/widget (23903): [MSC_HERO_Accu_JB]>>> U:338 [0:0] win : 7
D/widget (23903): [MSC_HERO_Accu_JB]>>> WC:721 [0:0] mSUDH(): current loc id = cityId:255551, tZ=GMT+2
D/widget (23903): [MSC_HERO_Accu_JB]>>> DI:565 [0:0] W Icon : 7
D/widget (23903): [MSC_HERO_Accu_JB]>>> WC:734 [0:0] ===== mSetUIDataHandler(): day = 6:47 AM, night=8:02 PM
D/widget (23903): [MSC_HERO_Accu_JB]>>> U:338 [0:0] win : 7
D/widget (23903): [MSC_HERO_Accu_JB]>>> U:338 [0:0] win : 7
D/widget (23903): [MSC_HERO_Accu_JB]>>> SM:1259 [0:0] sta ani iPA = false, flkDir = 0, iFA = false
D/widget (23903): [MSC_HERO_Accu_JB]>>> WC:1800 [0:0] drw all Tm dt
D/widget (23903): [MSC_HERO_Accu_JB]>>> SM:500 [0:0] set BG2 : false
D/widget (23903): [MSC_HERO_Accu_JB]>>> SM:519 [0:0] IR : false, IPR : false
D/widget (23903): [MSC_HERO_Accu_JB]>>> DI:423 [0:0] isd : true nu : 7
D/CellLayoutChildren(23903): setCellDimensions. width: 144, height: 200, gapX: 0, gapY: 0
V/WindowManager( 2347): Window{43202888 u0 Keyguard EXITING}mOrientationRequetedFromKeyguard=false
D/dalvikvm(13113): GC_CONCURRENT freed 510K, 14% free 10797K/12492K, paused 3ms+5ms, total 44ms
D/Launcher(23903): onTrimMemory. Level: 15
D/AndroidRuntime(14166): Shutting down VM
W/dalvikvm(14166): threadid=1: thread exiting with uncaught exception (group=0x41b54700)
D/KeyguardClockWidgetService(32341): onReceive action=android.intent.action.TIME_TICK
E/AndroidRuntime(14166): FATAL EXCEPTION: main
E/AndroidRuntime(14166): java.lang.RuntimeException: Unable to start receiver com.parse.ParseBroadcastReceiver: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.
E/AndroidRuntime(14166): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2541)
E/AndroidRuntime(14166): at android.app.ActivityThread.access$1600(ActivityThread.java:159)
E/AndroidRuntime(14166): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1392)
E/AndroidRuntime(14166): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(14166): at android.os.Looper.loop(Looper.java:176)
E/AndroidRuntime(14166): at android.app.ActivityThread.main(ActivityThread.java:5419)
E/AndroidRuntime(14166): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(14166): at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime(14166): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
E/AndroidRuntime(14166): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
E/AndroidRuntime(14166): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(14166): Caused by: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.
E/AndroidRuntime(14166): at com.parse.Parse.checkContext(Parse.java:519)
E/AndroidRuntime(14166): at com.parse.Parse.getApplicationContext(Parse.java:139)
E/AndroidRuntime(14166): at com.parse.ManifestInfo.getContext(ManifestInfo.java:221)
E/AndroidRuntime(14166): at com.parse.ManifestInfo.getPackageManager(ManifestInfo.java:229)
E/AndroidRuntime(14166): at com.parse.ManifestInfo.getPackageInfo(ManifestInfo.java:240)
E/AndroidRuntime(14166): at com.parse.ManifestInfo.deviceSupportsGcm(ManifestInfo.java:325)
E/AndroidRuntime(14166): at com.parse.ManifestInfo.getPushType(ManifestInfo.java:109)
E/AndroidRuntime(14166): at com.parse.PushService.startServiceIfRequired(PushService.java:150)
E/AndroidRuntime(14166): at com.parse.ParseBroadcastReceiver.onReceive(ParseBroadcastReceiver.java:20)
E/AndroidRuntime(14166): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2525)
E/AndroidRuntime(14166): ... 10 more
V/AlarmManager( 2347): ClockReceiver onReceive() ACTION_TIME_TICK
I/SurfaceFlinger( 1935): id=1760 Removed Leyguard (4/5)
I/SurfaceFlinger( 1935): id=1760 Removed Leyguard (-2/5)
I/ActivityManager( 2347): Notify an ApplicationCrash
I/dumpstate(14182): begin
D/STATUSBAR-IconMerger( 8423): checkOverflow(288), More:false, Req:false Child:2
E/android.os.Debug( 2347): !@Dumpstate > sdumpstate -k -t -z -d -o /data/log/dumpstate_app_error
D/SensorService( 2347): [AR] -0.3 4.4 8.4
D/SensorService( 2347): AutoRotationSensor::process: Ar_SensorChanged oldrotation = [0], rotation = [255]
D/SSRMv2:Monitor( 2347): SIOP:: AP = 330 (read only)
I/InputReader( 2347): Touch event's action is 0x0 (deviceType=0) [pCnt=1, s=0.11685 ] when=86013816393000
I/InputDispatcher( 2347): Delivering touch to: action: 0x0
I/InputDispatcher( 2347): Delivering touch to: action: 0x0
I/power ( 2347): *** acquire_dvfs_lock : lockType : 1 freq : 1400000
D/SSRMv2:CustomFrequencyManagerService( 2347): acquireDVFSLockLocked : type : DVFS_MIN_LIMIT frequency : 1400000 uid : 10001 pid : 23903 pkgName : com.sec.android.app.launcher@419
I/InputReader( 2347): Touch event's action is 0x1 (deviceType=0) [pCnt=1, s=] when=86013953671000
I/InputDispatcher( 2347): Delivering touch to: action: 0x1
I/InputDispatcher( 2347): Delivering touch to: action: 0x1
E/DatabaseUtils( 2347): Writing exception to parcel
E/DatabaseUtils( 2347): java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
E/DatabaseUtils( 2347): at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:13140)
E/DatabaseUtils( 2347): at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2038)
E/DatabaseUtils( 2347): at com.android.providers.settings.SettingsProvider.callFromPackage(SettingsProvider.java:607)
E/DatabaseUtils( 2347): at android.content.ContentProvider$Transport.call(ContentProvider.java:279)
E/DatabaseUtils( 2347): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:273)
E/DatabaseUtils( 2347): at android.os.Binder.execTransact(Binder.java:388)
E/DatabaseUtils( 2347): at dalvik.system.NativeStart.run(Native Method)
W/ActivityManager( 2347): Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
D/SSRMv2:CustomFrequencyManagerService( 2347): acquireDVFSLockLocked : type : DVFS_MIN_LIMIT frequency : 1400000 uid : 10001 pid : 23903 pkgName : LAUNCHER_APP_BOOSTER_CPU@20
D/lights ( 2347): button : 0 +
D/lights ( 2347): button : 0 -
D/SensorService( 2347): [AR] -0.6 5.0 8.4
D/SensorService( 2347): AutoRotationSensor::process: Ar_SensorChanged oldrotation = [255], rotation = [0]
D/SensorService( 2347): AutoRotationSensor::process: Acc eventTimestamp = 86016098377000, previousAccTimestamp = 86015758897000, difference = 339480000
D/SSRMv2:Monitor( 2347): SIOP:: AP = 330 (read only)
D/SSRMv2:Monitor( 2347): SIOP:: AP = 330 (read only)
E/Watchdog( 2347): !@Sync 2865
D/SensorService( 2347): -0.9 5.7 7.8
D/STATUSBAR-NetworkController( 8423): onSignalStrengthsChanged signalStrength=SignalStrength: 9 -1 -1 -1 -1 -1 -1 99 -140 -20 -200 -1 2147483647 gsm|lte 0x3 level=3
I/dumpstate(14182): done
D/SSRMv2:CustomFrequencyManagerService( 2347): acquireDVFSLockLocked : type : DVFS_MIN_LIMIT frequency : 1200000 uid : 1000 pid : 2347 pkgName : ACTIVITY_RESUME_BOOSTER@5
W/ActivityManager( 2347): mDVFSHelper.acquire()
D/dalvikvm( 2347): GC_FOR_ALLOC freed 1515K, 13% free 48161K/54804K, paused 182ms, total 182ms
I/dalvikvm-heap( 2347): Grow heap (frag case) to 49.263MB for 1127536-byte allocation
D/dalvikvm( 2347): GC_FOR_ALLOC freed 0K, 12% free 49262K/55908K, paused 133ms, total 133ms
V/WindowManager( 2347): Thread ID Thread[Binder_B,5,main]
D/SSRMv2:CustomFrequencyManagerService( 2347): releaseDVFSLockLocked : Getting Lock type frm List : DVFS_MIN_LIMIT frequency : 1400000 uid : 10001 pid : 23903 tag : com.sec.android.app.launcher@419
I/power ( 2347): *** acquire_dvfs_lock : lockType : 1 freq : 1400000
I/power ( 2347): *** acquire_dvfs_lock : lockType : 1 freq : 1200000
D/Launcher.HomeFragment(23903): onPause
D/SSRMv2:CustomFrequencyManagerService( 2347): releaseDVFSLockLocked : Getting Lock type frm List : DVFS_MIN_LIMIT frequency : 1400000 uid : 10001 pid : 23903 tag : LAUNCHER_APP_BOOSTER_CPU@20
D/SSRMv2:CustomFrequencyManagerService( 2347): FrequencyrequestList.getNextMaxCPUCoreRequest, index: 1
D/CrashAnrDetector( 2347): processName: com.guessSound.guessSound
D/CrashAnrDetector( 2347): broadcastEvent : com.guessSound.guessSound data_app_crash
D/LSO ( 2347): Unregistered Intent: android.intent.action.sec.LSO_CONFIG_CHANGED , android.intent.action.MEDIA_MOUNTED
I/KeyguardBackgroundView( 2347): *** KeyguardEffectView getInstance ***
V/WindowOrientationListener( 2347): Rotation Sensor : x=255.0
D/GetJar SDK [com.jb.gosms](13841): CONFIG: GetJarConfig()::getInstance() -- re-using existing GetJarConfig instance
V/WindowOrientationListener( 2347): Rotation Sensor : x=0.0
I/InputDispatcher( 2347): Window spent 7203.2ms processing the last input event: MotionEvent(action=0, deviceId=5, source=0x00001002, displayId=0)
V/GetJar SDK [com.jb.gosms](13841): CONFIG: GetJarConfig getDirectiveValue() START [key='usage.package_filter.regex']
I/InputDispatcher( 2347): Window spent 7098.9ms processing the last input event: MotionEvent(action=2, deviceId=5, source=0x00001002, displayId=0)
I/InputDispatcher( 2347): Window spent 7088.3ms processing the last input event: MotionEvent(action=2, deviceId=5, source=0x00001002, displayId=0)
V/GetJar SDK [com.jb.gosms](13841): CONFIG: GetJarConfig getDirectiveValue() Using SERVER defined value: 'usage.package_filter.regex' = '^(com\.)?(android|sec|htc|sonyericsson|motorola|lge|pantech|huawei|asus)(\..*|$)'
I/InputDispatcher( 2347): Window spent 7077.2ms processing the last input event: MotionEvent(action=2, deviceId=5, source=0x00001002, displayId=0)
I/InputDispatcher( 2347): Window spent 7067.2ms processing the last input event: MotionEvent(action=1, deviceId=5, source=0x00001002, displayId=0)
V/GetJar SDK [com.jb.gosms](13841): CONFIG: GetJarConfig getDirectiveValue() FINISHED [key='usage.package_filter.regex']
I/Choreographer( 2347): Skipped 490 frames! The application may be doing too much work on its main thread.
D/GetJar SDK [com.jb.gosms](13841): USAGE|CONFIG: UsageManager getFilterRegex: ^(com\.)?(android|sec|htc|sonyericsson|motorola|lge|pantech|huawei|asus)(\..*|$)
D/widget (23903): [MSC_HERO_Accu_JB]>>> WC:1087 [0:0] onPause
D/Launcher.Workspace(23903): exitWidgetResizeMode State: NORMAL, newDragStarted: false
V/WindowManager( 2347): Window{43202888 u0 Keyguard}mOrientationRequetedFromKeyguard=false
V/TAG ( 2347): bug 7643792: fitSystemWindows([0,0][0,0])
V/WindowManager( 2347): rotationForOrientationLw(orient=-1, last=0); user=0 sensorRotation=0 isCoverOpen=true mLidState=-1 mDockMode=0 mHdmiPlugged=false mAccelerometerDefault=false
V/WindowManager( 2347): Application requested orientation -1, got rotation 0 which has compatible metrics

最佳答案

经过毫 headless 绪的研究,我意识到以下几点:

首先,您必须在应用程序 Activity 类的创建时调用您的 Parse.initialize(ctx, app_id, clientkey)。

import android.content.res.Configuration;
import android.widget.Toast;


public class ActivityClass extends Application
{

@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
}

@Override
public void onCreate()
{

super.onCreate();

if(Utils.checkInternetConnection(this))
{
Parse.initialize(getApplicationContext(), "aaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
PushService.setDefaultPushCallback(this, Splash.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
}

}

@Override
public void onLowMemory()
{
// TODO Auto-generated method stub
super.onLowMemory();
}

@Override
public void onTerminate()
{
// TODO Auto-generated method stub
super.onTerminate();
}



}

然后将其添加到您的 manifest.xml 中

  <application
android:name="PackageName.AplicationClassName"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>

然后我也意识到,当没有互联网连接时,Parse.BroadCastReceiver 无法进行初始化,这就是出现此问题的原因。 java.lang.RuntimeException:applicationContext 为空。在使用 Parse 库之前,您必须调用 Parse.initialize(context, applicationId, clientKey)。

所以,我在互联网上找到了 Parse.BroadcastReceiver 类:

package com.parse;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class ParseBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "com.parse.ParseBroadcastReceiver";

@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "received " + intent.getAction());
PushService.startServiceIfRequired(context);
}
}

然后我将它放在我的类中,然后我修改了整个类以仅在设备具有互联网连接时操纵何时启动“PushServices.startServices”操作。

-

public class ParseBroadcastReceiverCustom extends BroadcastReceiver {
private static final String TAG = "com.parse.ParseBroadcastReceiver";

@Override
public void onReceive(final Context context, Intent intent) {
Log.d(TAG, "received " + intent.getAction());
Utils.checkInternetConnection2(context, new CallBackFunction()
{
@Override
public void FunctionToCall(String obj)
{
if(obj.equals("true"))
{
PushService.startServiceIfRequired(context);
}

}
});

}
}

这是我用来检查互联网连接的 Utils 函数

public static void checkInternetConnection2(Context ctx,final CallBackFunction call)
{
boolean response = false;

ConnectivityManager conMgr = (ConnectivityManager) ctx
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo i = conMgr.getActiveNetworkInfo();
if (i == null)
response = false;
else if (!i.isConnected())
response = false;
else if (!i.isAvailable())
response = false;
else
response = true;

if(response)
{

CustomAsynctask TestTask = new CustomAsynctask(new CallBackFunction()
{

@Override
public void FunctionToCall(String obj)
{
String url = "http://www.parse.com";
String test = Utils.getStringFromUrl(url);

if(test.equals(""))
{
real_answer = false;
}
else
{
real_answer = true;
}
call.FunctionToCall(real_answer+"");

}
});

TestTask.execute((Void[])null);

}
else
{
call.FunctionToCall(response+"");
}

}

然后,在 list 中我添加了我自己的自定义 Parse.BroadcastReceiver。

<receiver android:name="com.mypackagename.ParseBroadcastReceiverCustom">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED"/>
<action android:name="android.net.wifi.STATE_CHANGE"/>
</intent-filter>
</receiver>

它对我有用,我的设备屏幕上没有更多错误消息!!!! :)

如果对您有用,请给个评价!!!在我找到这个之前,没有解决方案....谢谢!!!!

PD我使用的其他类(class)!!!

Java 回调函数

package com.wigilabs.Utils;

public interface CallBackFunction {

public void FunctionToCall(String obj);

}

CustomAsyncTask Java

package com.wigilabs.Utils;



import android.os.AsyncTask;

public class CustomAsynctask extends AsyncTask<Void, Void, String>{

private CallBackFunction functionToCall;

public CustomAsynctask(CallBackFunction f) {
this.functionToCall = f;
}

@Override
protected String doInBackground(Void... params) {
functionToCall.FunctionToCall("");
return null;
}

}

关于启用推送通知时,Android 应用程序突然崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22749151/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com