Android:我的应用程序每次第一次打开应用程序时都会崩溃,我无法将我的消息应用程序设置为默认值

时间:2016-08-03 07:23:38

标签: android sms message

我正在尝试将我的应用程序作为默认消息传递应用程序,因此第一次打开应用程序时,我会提示用户是否要将应用程序作为默认应用程序。如果是,它将更改我的应用程序成为默认值。但是现在,每当我第一次打开应用程序时,它总会崩溃。任何人都可以指导我。由于它在第一次打开应用程序时总是崩溃,因此不会显示提示更改默认应用程序的对话框,因此我的应用程序永远不会成为默认应用程序。

logcat的:

08-03 14:43:09.498 816-816/? W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1686 com.android.server.accessibility.AccessibilityManagerService$DirectAccessBrocastReceiver.onReceive:383 android.app.LoadedApk$ReceiverDispatcher$Args.run:923 android.os.Handler.handleCallback:739 android.os.Handler.dispatchMessage:95 
08-03 14:43:10.448 816-1061/? W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1686 com.android.internal.policy.impl.PhoneWindowManager.notifyToSSRM:5628 com.android.internal.policy.impl.PhoneWindowManager.access$600:192 com.android.internal.policy.impl.PhoneWindowManager$PolicyHandler.handleMessage:811 android.os.Handler.dispatchMessage:102 
08-03 14:43:11.978 816-1061/? W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1686 com.android.internal.policy.impl.PhoneWindowManager.notifyToSSRM:5628 com.android.internal.policy.impl.PhoneWindowManager.access$600:192 com.android.internal.policy.impl.PhoneWindowManager$PolicyHandler.handleMessage:811 android.os.Handler.dispatchMessage:102 
08-03 14:43:14.388 816-1061/? W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1686 com.android.internal.policy.impl.PhoneWindowManager.notifyToSSRM:5628 com.android.internal.policy.impl.PhoneWindowManager.access$600:192 com.android.internal.policy.impl.PhoneWindowManager$PolicyHandler.handleMessage:811 android.os.Handler.dispatchMessage:102 
08-03 14:43:15.008 816-1061/? W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1686 com.android.internal.policy.impl.PhoneWindowManager.notifyToSSRM:5628 com.android.internal.policy.impl.PhoneWindowManager.access$600:192 com.android.internal.policy.impl.PhoneWindowManager$PolicyHandler.handleMessage:811 android.os.Handler.dispatchMessage:102 
08-03 14:43:18.398 4316-4316/? W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1525)
08-03 14:43:18.398 4316-4316/? W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
08-03 14:43:19.178 816-1256/? I/ActivityManager: Start proc com.android.mms for broadcast com.android.mms/.freemessage.FreeMessageReceiver: pid=8209 uid=10053 gids={50053, 9997, 3003, 1028, 1015, 1023, 1003} abi=armeabi-v7a
08-03 14:43:19.528 8209-8209/? D/Mms/MmsConfig: setFreeMessageEnabled, getSupportedFeatures = -1 isAuth = false
08-03 14:43:19.558 8209-8209/? E/Mms/MessageUtils: setCountryDetector : update country detector info 
08-03 14:43:19.558 8209-8209/? E/Mms/MessageUtils: updateCountryIso : update country iso info 
08-03 14:43:19.658 1415-1653/? D/TP/MmsSmsProvider: delete URI_CONVERSATIONS_MESSAGES affectedRows=0
08-03 14:43:19.708 8209-8209/? D/Mms/MessagingNotification: [start]    init() consume time = 39.299062
08-03 14:43:19.708 8209-8209/? D/Mms/MessagingNotification: [end]    init consume time = 2.640261
08-03 14:43:19.728 8209-8209/? D/Mms/FreeMessageReceiver: onReceive, action : android.intent.action.PACKAGE_REMOVED
08-03 14:43:19.758 8209-8233/? D/Mms/FreeMessageReceiverService: onHandleIntent, action : android.intent.action.PACKAGE_REMOVED
08-03 14:43:19.758 8209-8233/? D/Mms/FreeMessageReceiverService: onHandleIntent: ACTION_PACKAGE_REMOVED
08-03 14:43:19.798 8209-8231/? D/Mms/MessagingNotification: checkBadgeCount unreadCount=1 badgeCount=1
08-03 14:43:19.938 8209-8231/? I/Mms/ReservationManager: getReservedSendMessageCount(): retMessageCount=0
08-03 14:43:20.868 816-1322/? D/SecContentProvider2: uri = 15 selection = getSealedHideNotificationMessages
08-03 14:43:20.868 8291-8291/? I/PopupuiReceiver_KNOX: getSealedHideNotificationMessages : 1
08-03 14:43:21.558 816-1463/? W/ActivityManager: Scheduling restart of crashed service flipboard.app/flipboard.remoteservice.MessengerService in 1000ms
08-03 14:43:21.748 8209-8209/? D/Mms/ComposeMessageFragment: [start]    fillCache consume time = 1972.000208
08-03 14:43:21.748 8209-8209/? D/Mms/ComposeMessageFragment: fillCache, easy = false
08-03 14:43:21.898 8209-8209/? D/Mms/ComposeMessageFragment: [end]    fillCache consume time = 147.638385
08-03 14:43:21.908 1101-1101/? I/TZ: qc_tlc_communication: max_message_size = 38912 = 0x9800
08-03 14:43:22.648 816-1045/? I/ActivityManager: Start proc flipboard.app for service flipboard.app/flipboard.remoteservice.MessengerService: pid=8448 uid=10124 gids={50124, 9997, 3003, 1028, 1015} abi=armeabi-v7a
08-03 14:43:23.158 8417-8433/? W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1686 android.content.ContextWrapper.sendBroadcast:391 com.samsung.android.app.filterinstaller.FilterUninstaller.uninstallFilters:44 com.samsung.android.app.filterinstaller.FilterPackageService$ServiceHandler.handleMessage:149 android.os.Handler.dispatchMessage:102 
08-03 14:43:23.268 5327-5327/? E/Finsky: [1] com.google.android.finsky.wear.bo.a(837): onConnectionFailed: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null, message=null}
08-03 14:43:28.828 816-1099/? D/TimaService: TimaServiceHandler.handleMessage what =1
08-03 14:43:35.998 816-1060/? D/UsbDeviceManager: handleMessage -> MSG_POWER_STATE = 1
08-03 14:43:36.028 816-816/? I/CAE: handleMessage(CaPowerManager.java:193) - POWER_CONNECTED
08-03 14:43:36.058 816-1423/? D/SecContentProvider2: uri = 15 selection = getSealedHideNotificationMessages
08-03 14:43:36.058 8291-8291/? I/PopupuiReceiver_KNOX: getSealedHideNotificationMessages : 1
08-03 14:43:36.458 816-1060/? D/UsbDeviceManager: handleMessage -> MSG_UPDATE_STATE connected = 1,configured = 0
08-03 14:43:36.658 816-1060/? D/UsbDeviceManager: handleMessage -> MSG_UPDATE_STATE connected = 1,configured = 1
08-03 14:43:39.188 9080-9116/? E/MtpService: handleMessage. msg= { when=0 what=0 arg1=1 obj=Intent { cmp=com.samsung.android.MtpApplication/.MtpService } target=com.samsung.android.MtpApplication.MtpService$ServiceHandler }
08-03 14:43:39.228 9080-9080/? E/MTPJNIInterface: noti = 2

                                                  [ 08-03 14:43:39.228  9080: 9080 D/         ]
                                                  deleting sockets before message queue initialization


                                                  [ 08-03 14:43:39.228  9080: 9080 D/         ]
                                                  event handler thread is created, so set the flag
08-03 14:43:39.248 9080-9116/? E/MtpService: handleMessage. msg= { when=-4ms what=0 arg1=2 obj=Intent { cmp=com.samsung.android.MtpApplication/.MtpService } target=com.samsung.android.MtpApplication.MtpService$ServiceHandler }
08-03 14:43:42.198 9080-9080/? E/MTPRx: Open session has come  remove the  Message false
08-03 14:43:42.208 9080-9080/? E/MTPRx: Open session has come  remove the  Message false
08-03 14:46:22.068 816-1069/? D/PackageManager: remove MCS_UNBIND message and Posting MCS_UNBIND 10 secs later
08-03 14:46:22.108 816-816/? D/PackageManager: [VERIFY] sendMessageDelayed(CHECK_PENDING_VERIFICATION, 11, 10000)
08-03 14:46:24.278 816-816/? D/PackageManager: [VERIFY] sendMessageDelayed(CHECK_PENDING_VERIFICATION, 11, 10000)
08-03 14:46:27.058 4316-4316/? W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1525)
08-03 14:46:27.058 4316-4316/? W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
08-03 14:46:28.698 816-4077/? W/ActivityManager: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.apple.qs/.Activity.Activity.ActivityMain_txt } from null (pid=10272, uid=2000) requires android.permission.SEND_RESPOND_VIA_MESSAGE
08-03 14:46:29.378 10341-10341/? W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1509)
08-03 14:46:29.378 10341-10341/? W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
08-03 14:46:30.098 10374-10374/? D/Mms/MmsConfig: setFreeMessageEnabled, getSupportedFeatures = -1 isAuth = false

我将应用设置为默认应用的代码:

 protected void onResume() {


        super.onResume();

        if (sharedPreferences.getBoolean("pref_", true)) {
            //You can perform anything over here. This will call only first time
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {

                if (!Telephony.Sms.getDefaultSmsPackage(this).equals(myPackageName)) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(ActivityMain_txt.this);
                    builder.setMessage("This app is not set as your default messaging app. Do you want to set it as default?")
                            .setCancelable(false)
                            .setTitle("Alert!")
                            .setNegativeButton("No", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            })

                            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                @TargetApi(19)
                                public void onClick(DialogInterface dialog, int id) {
                                    Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
                                    intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getPackageName());

                                    startActivity(intent);
                                    dialog.dismiss();
                                    // ActivityMain_txt.this.finish();


                                }

                            });
                    builder.show();

                }


            }


            editor = sharedPreferences.edit();
            editor.putBoolean("pref_", false);
            editor.commit();

        }


    }

清单:

  <activity android:name=".Activity.ActivityMain_txt" android:enabled="@bool/is_kitkat"  android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE">
            <intent-filter>
                <data android:mimeType="vnd.android-dir/mms-sms" />
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
                    <category android:name="android.intent.category.LAUNCHER" />
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SENDTO" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="sms" />
                <data android:scheme="smsto" />
                <data android:scheme="mms" />
                <data android:scheme="mmsto" />
            </intent-filter>
        </activity>

        <service android:name=".receiver.HeadlessSmsSendService"
            android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
            android:exported="true" >
            <intent-filter>
                <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="sms" />
                <data android:scheme="smsto" />
                <data android:scheme="mms" />
                <data android:scheme="mmsto" />
            </intent-filter>
        </service>

        <activity
            android:name=".Activity.ActivityMessageDetails_txt"
            android:label="List" >
        </activity>
        <activity
            android:name=".Activity.ActivityNewMessage_txt"
            android:label="New Message" >
        </activity>

        <receiver android:name=".receiver.MessageReceiver" android:permission="android.permission.BROADCAST_SMS">
            <intent-filter android:priority="1000" >
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
                <action android:name="android.provider.Telephony.SMS_DELIVER" />
            </intent-filter>
        </receiver>

        <receiver android:name="receiver.MmsReceiver"
            android:permission="android.permission.BROADCAST_WAP_PUSH">
            <intent-filter>
                <action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" />
                <data android:mimeType="application/vnd.wap.mms-message" />
            </intent-filter>
        </receiver>

共享偏好:

public static boolean getBooleanPref(String key_val, boolean def_val, Context context) {
        SharedPreferences pref = context.getSharedPreferences("pref_"+key_val,context.MODE_PRIVATE);
        return pref.getBoolean(key_val, def_val);
    }

    public static void setBooleanPref(String key_val, boolean val, Context context) {
        SharedPreferences pref = context.getSharedPreferences("pref_"+key_val,context.MODE_PRIVATE);
        SharedPreferences.Editor prefEditor = pref.edit();
        prefEditor.clear();
        prefEditor.putBoolean(key_val, val);
        prefEditor.commit();
    }

0 个答案:

没有答案