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

查看:101
本文介绍了当用户单击通知时,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

推荐答案

我发现您已经在<activity>之外使用url了<activities>,否则,如果要使用<application>,则也无法使用<application>使用自定义 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天全站免登陆