import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
/**
* 获取Netflix ESN方法:
* 发送广播给Netflix,Netflix回发广播
*/
public class MainActivity extends AppCompatActivity {
private BroadcastReceiver receiver;
private TextView tv_esn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(this, String.valueOf(hasNetflix()), Toast.LENGTH_SHORT).show();
tv_esn = findViewById(R.id.tv_esn);
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String esn = intent.getStringExtra("ESNValue");
tv_esn.setText(esn);
}
};
IntentFilter filter = new IntentFilter("com.netflix.ninja.intent.action.ESN_RESPONSE");
registerReceiver(receiver, filter, "com.netflix.ninja.permission.ESN", null);
Intent esnQueryIntent = new Intent("com.netflix.ninja.intent.action.ESN");
esnQueryIntent.setPackage("com.netflix.ninja");
esnQueryIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
sendBroadcast(esnQueryIntent);
}
@Override
protected void onDestroy() {
super.onDestroy();
if (receiver != null) {
unregisterReceiver(receiver);
}
}
public boolean hasNetflix(){
String product = Build.PRODUCT;
if (product.contains("WON")){
return false;
}else {
return true;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.smartdevice.dtv.skyhome.testesn">
<uses-permission android:name="com.netflix.ninja.permission.ESN"/>
<uses-permission android:name="com.netflix.ninja.permission.ESN_RESPONSE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
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>
</application>
</manifest>
注意:需要在系统编译环境下,进行签名才可以(mm)