点击来自可穿戴设备的推送通知打开应用程序,但点击来自手机的通知不会做任何事情。

时间:2017-04-24 20:38:19

标签: android notifications

这是我第一次实施推送通知,根据我的理解,如果我使用NotificationCompat,那么它应该只适用于手机和可穿戴设备。那么为什么点击我的手机通知不会打开我的应用程序,但它适用于可穿戴设备。

BTW我的推送通知代码全部在OnCreate中。

MainActivity

public class MainActivity extends AppCompatActivity {

    private WebView myWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        myWebView = (WebView)findViewById(R.id.webView_ID);
        WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        myWebView.loadUrl("http://www.mommy-info.com");
        myWebView.setWebViewClient(new WebViewClient());

        //notification code

        Intent intent = new Intent(this, MainActivity.class);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Action action = new NotificationCompat.Action.Builder(
                R.mipmap.baby, getString(R.string.app_name), pendingIntent).build();


        Notification notification = new NotificationCompat.Builder(this)
                .setContentText("Come check out some of our new posts.")
                .setContentTitle("It's been awhile")
                .setSmallIcon(R.mipmap.baby)
                .extend(new NotificationCompat.WearableExtender().addAction(action))
                .build();

        NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
        notificationManagerCompat.notify(001, notification);
    }

    @Override
    public void onBackPressed() {
        if(myWebView.canGoBack()){
            myWebView.goBack();
        }
        else{
            super.onBackPressed();
        }
    }
}

0 个答案:

没有答案