简体   繁体   中英

how to fire my own activity when user clicks on the new sms notification

hi guys i am looking for solution to fire my own activity to be lauched to handle incoming sms notification. i am not talking about receving broadcast of incoming sms but i want to launch my own activity when user clicks the new sms notification.Is it possible?

The notification is generated by the default sms application, so it is linked to it, you can't change that.
The only thing you can do is create by yourself a notification through a receiver/intent-filter and link it to the Activity you want to launch.

To elaborate further on what @Lyrkan said, add the following to your manifest,

<receiver class=".SMSReceiver">
   <intent-filter>
      <action android:value="android.provider.Telephony.SMS_RECEIVED" />
  </intent-filter>
</receiver>

and make sure you have the appropriate permission, ie

<uses-permission android:name="android.permission.RECEIVE_SMS"/>

and the class you need to implement is something like

public class SMSReceiver extends BroadcastReceiver{

    @Override 
    public void onReceive(Context context,Intent intent){
    //your code here
    }
}//end of class

Now from the onReceive you can do whatever it is that you want to do with the SMS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM