android studio 一个月新手
我现在想要在 NotificationListenerServic 抓到app通知的标题跟内容
抓到后回传到其他activity,这个string另作其他用途
但目前试过intent回传,程式点进去会闪退
目前onCreate如果加了char flag就会闪退,不加不会
想请问各位大大是什么问题
Code 如下连结
https://ideone.com/fork/mnqVCs
activity的onCreate底下如下:
...
        Bundle bundleNotify = this.getIntent().getExtras();
        char flag = bundleNotify.getChar("nene"); //flag = 1 执行
        String ChineseString = bundleNotify.getString("Title"+"Text");
         //这行得到监听的string,flag是有得到通知才会变成1,才送图
        if(flag==1) {
            Bitmap Water = createChinese2(25, ChineseString);
            Deliver(Water);
            }
NotificationListenerService的副程式如下
public class NotificationService extends NotificationListenerService {
    //收到通知时开始触发
    @Override
    public void onNotificationPosted (StatusBarNotification sbn){
        Notification mNotification = sbn.getNotification();//获取通知包
        Bundle bundle = new Bundle();
        char flag =0;//flag
        if(mNotification != null){
            String packageName = sbn.getPackageName();//发送通知的包名
            String notificationTitle = bundle.getString(mNotification.EXTRA_TITLE);//通知标题
            String notificationText = bundle.getString(mNotification.EXTRA_TEXT);//通知内容
            bundle.putString("Title",notificationTitle);
            bundle.putString("Text",notificationText);
            Intent intent = new Intent(this,StringAndPic.class);
            intent.putExtras(bundle);
            startActivity(intent);  //
        }
        bundle.putChar("nene",flag);//当f=1执行
        Intent intent = new Intent(this,StringAndPic.class);
        intent.putExtras(bundle);
        startActivity(intent);
    }
作者: mewme (阿喵)   2018-11-03 00:19:00
onCreate闪退的原因会不会是因为第34行这时bundle里还没有加putChar,所以get不到