我想通过Facebook上的分享意图与我的应用程序预先填充的标题分享照片.
示例代码
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_TEXT, "eample");
intent.putExtra(Intent.EXTRA_TITLE, "example");
intent.putExtra(Intent.EXTRA_SUBJECT, "example");
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
Intent openInChooser = new Intent(intent);
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
startActivity(openInChooser);
Run Code Online (Sandbox Code Playgroud)
这是我得到的屏幕截图

如果设置类型为图像/*,则上传照片时不会预填充文本.如果设置为文本/普通照片不显示.....
从帖子是否可以通过adb shell启动活动?,我们可以通过adb启动Android应用程序
adb shell am start -n yourpackagename/.activityname
Run Code Online (Sandbox Code Playgroud)
但是,如果不知道活动名称,是否可以通过adb启动Android应用程序?例如,通过将android.intent.action.MAIN意图发送到包?也许有些命令是这样的:
adb shell am start -a android.intent.action.MAIN -n packageName
Run Code Online (Sandbox Code Playgroud)
谢谢!!
-Cosmo
我想结合两个意图标志,就像我们在android中所做的那样
Intent intent = new Intent(this, MapsActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
Run Code Online (Sandbox Code Playgroud)
我尝试过这样的事情,但它对我不起作用
val intent = Intent(context, MapActivity::class.java)
intent.flags = (Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
Run Code Online (Sandbox Code Playgroud) 我非常喜欢开源贡献广场已经对Android社区做了什么,并正在调查他们的最新贡献Otto(事件总线)
深入挖掘我看到Otto使用反射并且没有有序广播(一种模式,其中未消息的消息从一个接收器传递到下一个接收器,听取相同类型的事件)Otto相信更多的火灾和忘记模型.
现在android LocalBroadcastManager在其v4支持库中有(LBM)用于相同的目的,尽管它更笨重并且对传递的对象有更多限制.但在更明亮的一面,它确实支持有序广播,它更像是正常的广播.
Otto和LBM都处于相同的处理空间内,因此就速度而言,我猜两者都是相同的.我能看到的唯一真正的区别是Otto允许您定义自定义事件,而您不必序列化/包裹对象.
因此,我真正的问题是,如果LBM做同样的事情,你何时会使用Otto.
参考文献:
http://nick.perfectedz.com/otto-event-system/
https://plus.google.com/107049228697365395345/posts/6j4ANWngCUY
我在Android文档中读到,通过将我的Activity的launchMode属性设置为singleTop或者通过向FLAG_ACTIVITY_SINGLE_TOP我的Intent 添加标志,该调用startActivity(intent)将重用单个Activity实例并在onNewIntent回调中给我Intent .我做了这两件事,每次都onNewIntent不会发射和onCreate射击.文档还说,它this.getIntent()返回首次创建时首次传递给Activity的意图.在onCreate我打电话getIntent,每一次(我创建另一个动作的意图对象,并增加一个额外的给它我得到一个新的...这额外的应该是相同的,每次如果它回到我同样的意图对象).所有这些让我相信我的活动并不像"单一顶级",我不明白为什么.
为了添加一些背景,以防我只是错过了一个必需的步骤,这里是清单中的Activity声明和我用来启动活动的代码.活动本身没有做任何值得一提的事情:
在AndroidManifest.xml中:
<activity
android:name=".ArtistActivity"
android:label="Artist"
android:launchMode="singleTop">
</activity>
Run Code Online (Sandbox Code Playgroud)
在我的通话活动中:
Intent i = new Intent();
i.putExtra(EXTRA_KEY_ARTIST, id);
i.setClass(this, ArtistActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(i);
Run Code Online (Sandbox Code Playgroud) java android android-manifest android-intent android-activity
这似乎是一个常见的问题,我经历了我已经找到的所有相关问题: 活动没有获得新意图,为什么在android通知意图中没有发送额外数据(整数)?,Notification传递旧的Intent Extras,不能为通知中的意图,android挂起意图通知问题添加额外内容 ; 但仍然无法弄清楚这一点.
问题是一样的.我设置了一个带有PendingIntent的通知,其中包含一些额外的信息,而我却没有在另一方面得到它.
以下是生成通知的代码:
Notification notification = new Notification(R.drawable.icon, getResources().getString(R.string.notification_ticker), System.currentTimeMillis());
notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE;
Intent start_test = new Intent(this, MyActivity.class);
start_test.putExtra("start_test", true);
start_test.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pi = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), start_test, PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(this, getResources().getString(R.string.notification_title), getResources().getString(R.string.notification_content, expired), pi);
nm.notify(NOTIFICATION_ID, notification);
Run Code Online (Sandbox Code Playgroud)
另一方面:
boolean start_test=getIntent().getBooleanExtra("start_test", false);
Run Code Online (Sandbox Code Playgroud)
捆绑实际上不存在(getExtras()返回null).
我尝试了不同的标志为PendingIntent.getActivity(FLAG_UPDATE_CURRENT,FLAG_CANCEL_CURRENT,FLAG_ONE_SHOT),没有这些帮助的.
如代码所示,我使用getCurrentMillis来确保requestID发生变化....
还发现在MyActivity中,onCreate并onNewIntent没有被调用.只是onResume.即使FLAG_ACTIVITY_NEW_TASK设定......?
我错过了一些非常简单的事吗?
我开发了一个具有共享文本功能的应用程序.除WhatsApp外,这个工作正常.我该怎么办?是否有任何特定的API?
下面是我的测试代码,用于创建列表视图,列表视图显示成功,但是,点击事件中存在错误.我想创建一个向新活动发送硬编码消息的意图.但是,它显示该行的错误
Intent intent = new Intent(context, SendMessage.class);
Run Code Online (Sandbox Code Playgroud)
所以问题是,我应该为这门课提供什么?
另外,输出消息代替硬编码,如何捕获列表视图行中的数据并传递给新活动?例如BBB,AAA,R.drawable.tab1_hdpi,对于第一行.
谢谢.
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.ListViewTest.MESSAGE";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<ListEntry> members = new ArrayList<ListEntry>();
members.add(new ListEntry("BBB","AAA",R.drawable.tab1_hdpi));
members.add(new ListEntry("ccc","ddd",R.drawable.tab2_hdpi));
members.add(new ListEntry("assa","cxv",R.drawable.tab3_hdpi));
members.add(new ListEntry("BcxsadvBB","AcxdxvAA"));
members.add(new ListEntry("BcxvadsBB","AcxzvAA"));
members.add(new ListEntry("BcxvBB","AcxvAA"));
members.add(new ListEntry("BvBB","AcxsvAA"));
members.add(new ListEntry("BcxvBB","AcxsvzAA"));
members.add(new ListEntry("Bcxadv","AcsxvAA"));
members.add(new ListEntry("BcxcxB","AcxsvAA"));
ListView lv = (ListView)findViewById(R.id.listView1);
Log.i("testTag","before start adapter");
StringArrayAdapter ad = new StringArrayAdapter (members,this);
Log.i("testTag","after start adapter");
Log.i("testTag","set adapter");
lv.setAdapter(ad);
lv.setOnItemClickListener(new OnItemClickListener() { …Run Code Online (Sandbox Code Playgroud) android listview android-intent onitemclicklistener onitemclick
我有BroadcastReceiver类:
public class IntentReceiver extends BroadcastReceiver {
final String tag = "Intent Intercepter";
@Override
public void onReceive(Context context, Intent intent) {
try {
String data = intent.getStringExtra("sms_body");
Log.i(tag, data);
Toast.makeText(context, data.subSequence(0, data.length()), Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(context, "Intercepted", Toast.LENGTH_LONG).show();
}
}
}
Run Code Online (Sandbox Code Playgroud)
而且在清单中:
<receiver android:name="com.whereismywifeserver.IntentReceiver" android:enabled="true">
<intent-filter android:priority="999">
<action android:name="com.whereismywifeserver.intent.TEST"/>
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
但是当我尝试从adb发送意图时,我收到错误:
C:\Users\i.yesilevsky>adb shell am start -a com.whereismywifeserver.intent.TEST
--es sms_body "test from adb" -c android.intent.category.HOME -n com.whereismywifeserver/.IntentReceiver
Starting: Intent { act=com.whereismywifeserver.intent.TEST t=[android.intent.category.HOME] cmp=com.whereismywifeserver/.IntentReceiver (has extras) }
Error …Run Code Online (Sandbox Code Playgroud) android ×10
android-intent ×10
adb ×2
java ×2
facebook ×1
google-play ×1
hyperlink ×1
kotlin ×1
listview ×1
onitemclick ×1
otto ×1
share ×1
whatsapp ×1