当用户点击通知时,Titanium Android Notification 执行操作 [英] Titanium Android Notification perform action when user clicks notification

查看:22
本文介绍了当用户点击通知时,Titanium Android Notification 执行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有成功响应钛合金的通知.所有工作示例都是经典示例.虽然我在 tiampl.xml 中定义了以下活动

I haven't succeed in responding notification in Titanium Alloy. All working examples are classic ones. Although I have defined following activity in tiampl.xml

如您所见,即使 tiapp.xml 包含 notification.js 活动,AndroidManifest.xml 也不包含此活动.应该加上这个!

As you see even though tiapp.xml contains notification.js activity AndroidManifest.xml does not contain this activity. It should add this!

<id>alloyandroidnotification.example.com</id>
<name>alloyandroidnotification</name>
<activity url="notification.js"> 
<intent-filter> 
<action android:name="android.intent.action.VIEW"/> 
<category android:name="android.intent.category.DEFAULT"/> 
</intent-filter> 
</activity>

我在 lib 文件夹中定义了 notification.js,我的 index.js 文件是:

I have defined notification.js in lib folder and my index.js file is:

function doClick(e) {
        var intent = Ti.Android.createIntent({
            action: Ti.Android.ACTION_VIEW,
            packageName:"alloyandroidnotification.example.com",
            className:"alloyandroidnotification.example.com.NotificationActivity"
        });
        intent.addCategory(Ti.Android.CATEGORY_LAUNCHER);


        Titanium.Android.NotificationManager.notify(1, Titanium.Android.createNotification({
            contentTitle: "notification",
            contentText : "notification",
            contentIntent: Ti.Android.createPendingIntent({
                intent:intent,
                type : Ti.Android.PENDING_INTENT_FOR_ACTIVITY
            }),
            flags : Titanium.Android.FLAG_AUTO_CANCEL | Titanium.Android.FLAG_SHOW_LIGHTS
        }));
}

$.index.open();

AndroidManifest.xml

AndroidManifest.xml

<application android:icon="@drawable/appicon" android:label="alloyandroidnotification" android:name="AlloyandroidnotificationApplication" android:debuggable="false" android:theme="@style/Theme.AppCompat">
    <activity android:name=".AlloyandroidnotificationActivity" android:label="@string/app_name" android:theme="@style/Theme.Titanium" android:configChanges="keyboardHidden|orientation|screenSize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <activity android:name="org.appcelerator.titanium.TiActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
    <activity android:name="org.appcelerator.titanium.TiTranslucentActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:theme="@style/Theme.AppCompat.Translucent"/>
    <activity android:name="ti.modules.titanium.ui.android.TiPreferencesActivity" android:configChanges="screenSize"/>
    <service android:name="com.appcelerator.analytics.APSAnalyticsService" android:exported="false"/>
</application>

我应该在缺少预期活动后在 AndroidManifest.xml 中看到

I should see in AndroidManifest.xml following missing expected activity

  <android 
    xmlns:android="http://schemas.android.com/apk/res/android">

      <activity url="notificationClick.js">
        <intent-filter>
          <action android:name="android.intent.action.VIEW"/>
          <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
      </activity>


  </android>

当我点击通知时没有任何反应.但是以下经典示例有效.有效的经典示例代码

Nothing happens when I click notification. But following classic example works. classic example code that works

推荐答案

我发现你在 之外使用了 和 url 否则如果您想使用 使用自定义 AndroidManifest.xml

I figured out you have use <activities> outside of <activity> with url otherwise it does not work also if use <application> if you want to use <application> use custom AndroidManifest.xml

<android xmlns:android="http://schemas.android.com/apk/res/android">
 <activities>
   <activity url="notificationClick.js">
     <intent-filter>
      <action android:name="android.intent.action.VIEW"/>
      <category android:name="android.intent.category.DEFAULT"/>
     </intent-filter>
   </activity>
</activities>
</android>

这篇关于当用户点击通知时,Titanium Android Notification 执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆