2016-08-23 5 views
0

この質問は別のユーザーから聞かれるかもしれませんが、私は自分の問題を解決できません 受信SMS用のブロードキャストを1つ作成していますが、 ...私はそれは私のコードHuawei社の装置ではクリアラムの後にSMSを受信

public class ReceiveSms extends BroadcastReceiver { 
    @Override 
    public void onReceive(Context context, Intent intent) { 

     Log.i("log","sms received"); 
    // Toast.makeText(App.context,"you have sms",Toast.LENGTH_SHORT).show(); 
     Object[] pdus= (Object[]) intent.getExtras().get("pdus"); 


     SmsMessage sms=SmsMessage.createFromPdu((byte[]) pdus[0]); 
     String body=sms.getMessageBody(); 
     String sender=sms.getDisplayOriginatingAddress(); 
     Log.i("log","sms body"+body); 
     Toast.makeText(App.context,"message from :"+sender,Toast.LENGTH_SHORT).show(); 

     Intent startProgram=new Intent(App.context,MainActivity.class); 
     startProgram.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

     App.context.startActivity(startProgram); 


    } 


} 

とmainfast

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.masiha68.sms"> 
    <uses-permission android:name="android.permission.SEND_SMS"/> 
    <uses-permission android:name="android.permission.RECEIVE_SMS"/> 
    <uses-permission android:name="android.permission.WAKE_LOCK"/> 
    <uses-permission android:name="android.permission.NFC" /> 
    <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 

    <application 
     android:name=".App" 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity android:name=".MainActivity"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <service android:name=".RC" 
      android:process=":remote" 
      android:enabled="true" 
      > 

     </service> 

<receiver android:name=".ReceiveSms" 
    android:process=":remote" 
    > 
    <intent-filter> 
     <action android:name="android.provider.Telephony.SMS_RECEIVED"> 

     </action> 
    </intent-filter> 

</receiver> 

    </application> 

</manifest> 

答えて

0

であっても、ユーザ明らかラム 仕事の放送を作成することができ、あなたが「保護された中でのアプリあなたを有効にする必要がありますどのように アプリを走り続ける画面が消えた後、またはバックグラウンドからアプリを終了した後>パワーセービング - - >保護されたアプリケーション - >あなたのアプリを見つけ、それを '有効にする' という後藤、

電話Managerの場合