0

일부 알림을 표시하는 데 사용하는 브로드 캐스트 수신기가 있습니다. 나는 그것을 호출 할 수 있으며 ADB를 사용하여 올바르게 트리거되도록 할 수 있습니다. 하지만 다른 앱 내에서 호출하면 아무 것도하지 않습니다.Broadcastreceiver는 ADP에서 호출 할 수 있지만 다른 앱에서는 호출 할 수 없습니다.

리시버는 Android Wear 앱/기기에 살고 있습니다. 앱

Intent i = new Intent(); 
i.setAction("site.com.app.SHOW_NOTIFICATION"); 
i.putExtra("contentText", "Some Text"); 
sendBroadcast(i); 

에서 ADB

에서

수신기

<receiver android:name=".NotificationReceiver" android:exported="true"> <intent-filter> <action android:name="site.com.app.SHOW_NOTIFICATION" /> </intent-filter> </receiver>

전화

./adb -s SERIAL shell am broadcast -a site.com.app.SHOW_NOTIFICATION 

전화가 다른 응용 프로그램에서 ADB에서 작동하지만 이유를 잘 모르겠어요 , 어떤 아이디어?

+0

OS 버전을 테스트하는 기기에는 어떤 것이 있습니까? 예를 들어, 화웨이 : 시스템에서 자동 시작 기능을 사용 가능하게 설정할 때까지는 방송 수신자가 절전 모드로 들어오지 않습니다. 나는 다른 공급 업체가 이런 짓을할지 모르지만 앱이 중지되었을 가능성이 있습니다. IDE에 연결된 상태로 유지하면 멈추지 않으므로 방송을 수신합니다. – Opiatefuchs

답변

1

정확한 코드는 모르지만 아래 코드를 시도해 볼 수 있습니다.

**Second Application** 

    package com.example.jiteshmohite.callingbroadcast; 

    import android.content.Intent; 
    import android.support.v7.app.AppCompatActivity; 
    import android.os.Bundle; 
    import android.view.View; 
    import android.widget.Button; 

     public class MainActivity extends AppCompatActivity { 

     private Button button; 
     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_main); 
      button = (Button) findViewById(R.id.button); 
      button.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        lunchExportedBroadcast(); 
       } 
      }); 
     } 
      private void lunchExportedBroadcast() { 
       Intent intent = new Intent(); 
       intent.setAction("com.example.exportedreceiver"); 
       sendBroadcast(intent); 
      } 
    } 

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.jiteshmohite.callingbroadcast.MainActivity"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello World!" 
     android:id="@+id/textView" /> 

    <Button 
     android:text="Call Broadcast" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/textView" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_marginLeft="13dp" 
     android:layout_marginStart="13dp" 
     android:layout_marginTop="18dp" 
     android:id="@+id/button" /> 
</RelativeLayout> 

**First Application who register broadcast** 

    public class ExportedReceiver extends BroadcastReceiver { 

     public ExportedReceiver() {`enter code here` 
      // empty constr 
     } 
     @Override 
     public void onReceive(Context context, Intent intent) { 
      // showing toast whenever any external application call these receiver. 
      Toast.makeText(context.getApplicationContext(), "ExportedReceiver", Toast.LENGTH_SHORT).show(); 
     } 
    } 

**Register receiver in First Application** 

    <receiver android:name=".receiver.ExportedReceiver"> 
       <intent-filter > 
        <action android:name="com.example.exportedreceiver"></action> 
       </intent-filter> 

      </receiver> 
관련 문제