Java Code Examples for android.content.Intent.setComponent()

The following are Jave code examples for showing how to use setComponent() of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: KomaMusic   File: ArtistsAdapter.java   View Source Code Vote up 7 votes
@Override
public void onClick(View view) {
    int position = (int) view.getTag();

    long artistId = mData.get(position).mArtistId;

    String artistName = mData.get(position).mArtistName;

    Intent intent = new Intent();
    intent.putExtra(Constants.ARTIST_ID, artistId);
    intent.putExtra(Constants.ARTIST_NAME, artistName);
    intent.putExtra(Constants.WHICH_DETAIL_PAGE, Constants.ARTIST_DETAIL);

    ComponentName componentName = new ComponentName(Constants.MUSIC_PACKAGE_NAME,
            Constants.DETAIL_PACKAGE_NAME);

    intent.setComponent(componentName);

    mContext.startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(
            ((AppCompatActivity) mContext), new Pair<View, String>(mAlbum,
                    mAlbumTransitionName)).toBundle());
}
 
Example 2
Project: springreplugin   File: PluginServiceServer.java   View Source Code Vote up 7 votes
private void startPitService() {
    // TODO 其实,有一种更好的办法……敬请期待
    String pname = IPC.getCurrentProcessName();
    int process = PluginClientHelper.getProcessInt(pname);

    ComponentName cn = PluginPitService.makeComponentName(mContext, process);
    if (LOG) {
        LogDebug.d(TAG, "startPitService: Start " + cn);
    }

    Intent intent = new Intent();
    intent.setComponent(cn);

    try {
        mContext.startService(intent);
    } catch (Exception e) {
        // 就算AMS出了问题(如system_server挂了,概率极低,和低配ROM有关),最多也就是服务容易被系统回收,但不能让它“不干活”
        e.printStackTrace();
    }
}
 
Example 3
Project: DroidPlugin   File: ServcesManager.java   View Source Code Vote up 7 votes
public boolean stopServiceToken(ComponentName cn, IBinder token, int startId) throws Exception {
    Service service = mTokenServices.get(token);
    if (service != null) {
        Integer lastId = mServiceTaskIds.get(token);
        if (lastId == null) {
            return false;
        }
        if (startId != lastId) {
            return false;
        }
        Intent intent = new Intent();
        intent.setComponent(cn);
        ServiceInfo info = PluginManager.getInstance().resolveServiceInfo(intent, 0);
        if (info != null) {
            handleOnUnbindOne(intent);
            handleOnDestroyOne(info);
            return true;
        }
    }
    return false;
}
 
Example 4
Project: Phoenix-for-VK   File: Utils.java   View Source Code Vote up 7 votes
/***
 * Android L (lollipop, API 21) introduced a new problem when trying to invoke implicit intent,
 * "java.lang.IllegalArgumentException: Service Intent must be explicit"
 * <p>
 * If you are using an implicit intent, and know only 1 target would answer this intent,
 * This method will help you turn the implicit intent into the explicit form.
 * <p>
 * Inspired from SO answer: http://stackoverflow.com/a/26318757/1446466
 *
 * @param context
 * @param implicitIntent - The original implicit intent
 * @return Explicit Intent created from the implicit original intent
 */
public static Intent createExplicitFromImplicitIntent(Context context, Intent implicitIntent) {
    // Retrieve all services that can match the given intent
    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resolveInfo = pm.queryIntentServices(implicitIntent, 0);

    // Make sure only one match was found
    if (resolveInfo == null || resolveInfo.size() != 1) {
        return null;
    }

    // Get component info and create ComponentName
    ResolveInfo serviceInfo = resolveInfo.get(0);
    String packageName = serviceInfo.serviceInfo.packageName;
    String className = serviceInfo.serviceInfo.name;
    ComponentName component = new ComponentName(packageName, className);

    // Create a new intent. Use the old one for extras and such reuse
    Intent explicitIntent = new Intent(implicitIntent);

    // Set the component to be explicit
    explicitIntent.setComponent(component);

    return explicitIntent;
}
 
Example 5
Project: boohee_v5.6   File: NetworkStatusReceiver.java   View Source Code Vote up 7 votes
private void a(Context context) {
    if (!(g.a(context).b() || !a.a(context).i() || a.a(context).n())) {
        try {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(context, "com.xiaomi.push.service" +
                    ".XMPushService"));
            intent.setAction("com.xiaomi.push.network_status_changed");
            context.startService(intent);
        } catch (Throwable e) {
            b.a(e);
        }
    }
    if (d.d(context) && g.a(context).f()) {
        g.a(context).c();
    }
}
 
Example 6
Project: TPlayer   File: ResolverActivity.java   View Source Code Vote up 6 votes
public Intent intentForPosition(int position) {
    DisplayResolveInfo dri = mList.get(position);

    Intent intent = new Intent(dri.origIntent != null
            ? dri.origIntent : mIntent);
    intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT
            | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
    ActivityInfo ai = dri.ri.activityInfo;
    intent.setComponent(new ComponentName(
            ai.applicationInfo.packageName, ai.name));
    return intent;
}
 
Example 7
Project: OSchina_resources_android   File: TDevice.java   View Source Code Vote up 6 votes
public static boolean openAppActivity(Context context,
                                      String packageName,
                                      String activityName) {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ComponentName cn = new ComponentName(packageName, activityName);
    intent.setComponent(cn);
    try {
        context.startActivity(intent);
        return true;
    } catch (ActivityNotFoundException e) {
        return false;
    }
}
 
Example 8
Project: FlickLauncher   File: LauncherAppsCompatV16.java   View Source Code Vote up 6 votes
public void startActivityForProfile(ComponentName component, UserHandleCompat user,
        Rect sourceBounds, Bundle opts) {
    Intent launchIntent = new Intent(Intent.ACTION_MAIN);
    launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    launchIntent.setComponent(component);
    launchIntent.setSourceBounds(sourceBounds);
    launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mContext.startActivity(launchIntent, opts);
}
 
Example 9
Project: ProgressManager   File: a.java   View Source Code Vote up 6 votes
/**
 * Request the Keyboard Shortcuts screen to show up. This will trigger
 * {@link #onProvideKeyboardShortcuts} to retrieve the shortcuts for the foreground activity.
 */
public final void requestShowKeyboardShortcuts() {
    Intent intent = new Intent(Intent.ACTION_SHOW_KEYBOARD_SHORTCUTS);
    intent.setComponent(new ComponentName(KEYBOARD_SHORTCUTS_RECEIVER_PKG_NAME,
            KEYBOARD_SHORTCUTS_RECEIVER_CLASS_NAME));
    sendBroadcast(intent);
}
 
Example 10
Project: AndroidBasicLibs   File: SystemUtils.java   View Source Code Vote up 6 votes
public static void openSettings(Activity context, String action) {
    Intent intent = new Intent();
    ComponentName comp = new ComponentName("com.android.settings", action);
    intent.setComponent(comp);
    intent.setAction("android.intent.action.VIEW");
    context.startActivityForResult(intent, 0);
}
 
Example 11
Project: Virtualview-Android   File: ScrollerListActivity.java   View Source Code Vote up 6 votes
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    Map<String, String> item = (Map<String, String>)l.getItemAtPosition(position);
    String className = item.get("class");
    Intent intent = new Intent();
    intent.setComponent(new ComponentName(this, className));
    intent.putExtra("name", item.get("name"));
    intent.putExtra("data", item.get("data"));
    startActivity(intent);
}
 
Example 12
Project: Utils   File: IntentUtil.java   View Source Code Vote up 6 votes
/**
 * 获取其他应用的Intent
 *
 * @param packageName 包名
 * @param className   全类名
 * @return 意图
 */
public static Intent getComponentNameIntent(String packageName, String className, Bundle bundle) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    if (bundle != null)
        intent.putExtras(bundle);
    ComponentName cn = new ComponentName(packageName, className);
    intent.setComponent(cn);
    return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
 
Example 13
Project: ReadMark   File: NetworkUtils.java   View Source Code Vote up 6 votes
/**
 * 打开网络设置界面
 */
public static void openSetting(Activity activity) {
    Intent intent = new Intent("/");
    ComponentName cm = new ComponentName("com.android.settings",
            "com.android.settings.WirelessSettings");
    intent.setComponent(cm);
    intent.setAction("android.intent.action.VIEW");
    activity.startActivityForResult(intent, 0);
}
 
Example 14
Project: MVPArms_Fragment-fragment   File: DeviceUtils.java   View Source Code Vote up 6 votes
public static boolean openAppActivity(Context context, String packageName,
                                      String activityName) {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    ComponentName cn = new ComponentName(packageName, activityName);
    intent.setComponent(cn);
    try {
        context.startActivity(intent);
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example 15
Project: financisto1-holo   File: PreferencesActivity.java   View Source Code Vote up 6 votes
private Intent createShortcutIntent(String activity, String shortcutName, ShortcutIconResource shortcutIcon, String action) {
	Intent shortcutIntent = new Intent();
	shortcutIntent.setComponent(new ComponentName(this.getPackageName(), activity));
	shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	Intent intent = new Intent();
	intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
	intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName);
	intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcon);
	intent.setAction(action);
	return intent;
}
 
Example 16
Project: Virtualview-Android   File: ScriptListActivity.java   View Source Code Vote up 6 votes
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    Map<String, String> item = (Map<String, String>)l.getItemAtPosition(position);
    String className = item.get("class");
    if (className != null) {
        Intent intent = new Intent();
        intent.setComponent(new ComponentName(this, className));
        intent.putExtra("name", item.get("name"));
        intent.putExtra("data", item.get("data"));
        startActivity(intent);
    } else {
        String result = VSEngine.test();
        Toast.makeText(getApplicationContext(), "executing result: " + result, Toast.LENGTH_LONG).show();
    }
}
 
Example 17
Project: Orin   File: PlayingNotificationImpl.java   View Source Code Vote up 5 votes
private PendingIntent buildPendingIntent(Context context, final String action, final ComponentName serviceName) {
    Intent intent = new Intent(action);
    intent.setComponent(serviceName);
    return PendingIntent.getService(context, 0, intent, 0);
}
 
Example 18
Project: ScanLinks   File: ScanActivity.java   View Source Code Vote up 5 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    urlToCheck = getIntent().getDataString();
    browserIntent = new Intent();

    new Prefs.Builder()
            .setContext(this)
            .setMode(ContextWrapper.MODE_PRIVATE)
            .setPrefsName(getPackageName())
            .setUseDefaultSharedPreference(true)
            .build();

    PackageManager packageManager = this.getPackageManager();
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("http://www.google.com"));
    List<ResolveInfo> list;

    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        list = packageManager.queryIntentActivities(intent,
                PackageManager.GET_META_DATA);
    } else {
        list = packageManager.queryIntentActivities(intent,
                PackageManager.MATCH_ALL);
    }

    whitelistArray = Prefs.getOrderedStringSet("whitelistArray", Collections.<String>emptySet());

    for (ResolveInfo info : list) {
        if (info.activityInfo.applicationInfo.loadLabel(packageManager).toString().equals(Prefs.getString("browserName", "Chrome"))) {
            browserCompName = new ComponentName(info.activityInfo.packageName, info.activityInfo.name);
            browserIntent.setComponent(browserCompName);
        }
    }

    for (String url : whitelistArray) {
        if (urlToCheck.contains(url)) {
            launchURLInBrowser();
        }
    }

    if (Prefs.getBoolean("suppressWarnings", false)) {
        launchURLInBrowser();
    }

    if (Prefs.getBoolean("blockWithoutDialog", false)) {
        blockWithoutDiag = true;
    }

    if (Prefs.getBoolean("blockWithDialog", false)) {
        blockWithoutDiag = false;
    }

    if (Prefs.getBoolean("ignoreNotInDbWarn", false)) {
        ignoreNotInDbWarning = true;
    }

    showProgressDialog();
    getScanIDAndExecuteScan();

}
 
Example 19
Project: PretendSharing   File: QQActivity.java   View Source Code Vote up 5 votes
public void onButtonClick(View mView) {
    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    final Intent iGet = getIntent();
    final Uri uGet = iGet.getData();//获取Uri
    /*test*/ //if(this.getCallingActivity()!=null)
        //Toast.makeText(this,getCallingActivity().getClassName(),Toast.LENGTH_LONG).show();
    if(null!=uGet)
    {
        //Toast.makeText(this, uGet.getHost(), Toast.LENGTH_SHORT).show();
        if(!(string_share.equals(uGet.getHost()))) {
            Toast.makeText(this, R.string.msg_not_qq_share_action, Toast.LENGTH_SHORT).show();
        }
            //this.returnintent();
            //假装我是qq,而且假装分享成功了
            //相关qq sdk内代码:com.tencent.connect.common.UIListenerManager:onActivityResultData
            //  com.tencent.connect.common.AssistActivity:onActivityResult 和 setResultData
            //Intent i = getIntent();
            //Intent i = new Intent(this,this.getClass());
            //i.putExtra("key_response","action_share");
            //i.putExtra("key_action","action_share");
            //i.putExtra("result","complete");
            //i.putExtra("action","shareToQQ");
            //i.putExtra("key_response","");
            //qq json
            //i.putExtra("key_response","{\"openid\":\"666\",\"access_token\":\"233\"}");
            //i.putExtra("key_error_code",0);
            //i.putExtra("key_error_msg","");
            //i.putExtra("key_error_detail","");
            //i.putExtra("key_response","");
            //this.setResult(RESULT_OK,i);
            this.setResult(RESULT_OK,null);
            //if(this.getParent()!=null)
            //    getParent().setResult(RESULT_OK,i);
            //else
            //    setResult(RESULT_OK,i);
            Intent launchBackIntent = new Intent();
            String pkgName = iGet.getStringExtra("pkg_name");
            launchBackIntent.setData(Uri.parse("tencent222222://tauth.qq.com/?#action=shareToQQ&result=complete&response={\"ret\":0}"));
            launchBackIntent.setFlags(272629760);
            launchBackIntent.putExtra("fling_action_key",2);
            launchBackIntent.putExtra("preAct","LiteActivity");
            launchBackIntent.putExtra("leftViewText","分享成功");
            launchBackIntent.putExtra("fling_code_key",32253408);
            launchBackIntent.putExtra("preAct_time",1493381615748L);
            try{
                launchBackIntent.setComponent(new ComponentName(pkgName,"com.tencent.tauth.AuthActivity"));
                startActivity(launchBackIntent);
            }catch (Exception e){
                Toast.makeText(this,String.format(getString(R.string.msg_error_no_callback),pkgName),Toast.LENGTH_SHORT).show();
                irregularCallback();
                super.onBackPressed();
            }
            if(!sharedPreferences.getBoolean("disable_toast",false))
                Toast.makeText(this, R.string.msg_qq_share_success, Toast.LENGTH_SHORT).show();
            super.onBackPressed();
    }else {
        Toast.makeText(this, R.string.msg_not_action, Toast.LENGTH_SHORT).show();
        super.onBackPressed();
    }

}
 
Example 20
Project: RetroMusicPlayer   File: PlayingNotificationImpl24.java   View Source Code Vote up 5 votes
private PendingIntent retrievePlaybackAction(final String action) {
    final ComponentName serviceName = new ComponentName(service, MusicService.class);
    Intent intent = new Intent(action);
    intent.setComponent(serviceName);
    return PendingIntent.getService(service, 0, intent, 0);
}